Skip to content

Commit

Permalink
new LinkedHashMap/LinkedHashSet implementation
Browse files Browse the repository at this point in the history
The mutable HashMap/HashSet has been rewroten and the
performance is better. So rewrote the LinkedHashMap and
LinkedHashSet also to improve performance. The detailed
data can be seen in the PR.
Most codes are same with HashMap/HashSet but some are
different:
1. the stepper is not overridden since order may be broken.
2. specific method to handle the order when adding/removing
the nodes.
3. other minor changes.

Signed-off-by: Liang Yan <ckgppl_yan@sina.cn>
  • Loading branch information
liang3zy22 committed Nov 17, 2022
1 parent bfedc2b commit 41ada93
Show file tree
Hide file tree
Showing 7 changed files with 961 additions and 218 deletions.
4 changes: 2 additions & 2 deletions src/library/scala/collection/immutable/ListMap.scala
Expand Up @@ -246,7 +246,7 @@ object ListMap extends MapFactory[ListMap] {
// by directly iterating through LinkedHashMap entries, we save creating intermediate tuples for each
// key-value pair
var current: ListMap[K, V] = empty[K, V]
var firstEntry = lhm._firstEntry
var firstEntry = lhm._firstNode
while (firstEntry ne null) {
current = new Node(firstEntry.key, firstEntry.value, current)
firstEntry = firstEntry.later
Expand Down Expand Up @@ -349,7 +349,7 @@ private[immutable] final class ListMapBuilder[K, V] extends mutable.ReusableBuil
} else xs match {
case lhm: collection.mutable.LinkedHashMap[K, V] =>
// special-casing LinkedHashMap avoids creating of Iterator and tuples for each key-value
var firstEntry = lhm._firstEntry
var firstEntry = lhm._firstNode
while (firstEntry ne null) {
underlying = new ListMap.Node(firstEntry.key, firstEntry.value, underlying)
firstEntry = firstEntry.later
Expand Down

0 comments on commit 41ada93

Please sign in to comment.