-
Notifications
You must be signed in to change notification settings - Fork 126
Refactor immut/{set, map, sparse_array} #2205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pull Request Test Coverage Report for Build 7139Details
💛 - Coveralls |
Although we could use test {
let rs = @quickcheck/splitmix.new()
fn f(size) {
let a : T[Int] = Arbitrary::arbitrary(size, rs)
let d = [0, 0, 0, 0, 0, 0, 0]
a.each(fn(x) { d[a.depth_of(x)] += 1 })
(a.size(), d)
}
inspect(f(100), content="(44, [0, 9, 33, 2, 0, 0, 0])")
inspect(f(1000), content="(31, [0, 17, 14, 0, 0, 0, 0])")
inspect(f(10000), content="(4023, [0, 0, 71, 3474, 464, 14, 0])")
inspect(f(100000), content="(28305, [0, 0, 0, 11785, 15720, 776, 24])")
inspect(f(1000000), content="(322608, [0, 0, 0, 13, 237231, 82405, 2959])")
inspect(f(2000000), content="(1149207, [0, 0, 0, 0, 383947, 727437, 37823])")
inspect(f(4000000), content="(1513468, [0, 0, 0, 0, 357127, 1089929, 66412])")
} |
The new implementation could better document the hash collision handling behaviorCategory union/intersection/difference operations could be optimized with early exitsCategory Potential missing error handling in Path operationsCategory |
I've completed porting immut/hashset from my temp repo. Before proceeding with immut/hashmap, I'd like to get review feedback to avoid duplicate fixes. |
Could you please split this PR into smaller patches so that we can review more easily? Thank you. |
Overview
I'm planning to refactor the immut/{set, map, sparse_array} modules. Due to the extensive changes, I've temporarily placed the new implementation in a separate repository: https://github.com/FlyCloudC/HAMT
Bug Fixes
Leaf
creation insingleton
, which previously forced subsequent add operations to degenerate intoCollision
nodes (causing O(n) performance).difference
(originally reported in Add set operations to@immut/hash{map, set}
and@internal/sparse_array
Summary #2145).Improvement
Flat[K, Path]
to eliminate redundant single-leaf Branch nesting, reducing depth and improving lookup/insertion.@list
to deduplicate method implementations.Leaf[K]
). Now usingLeaf(K, List[K])
to represent non-empty lists. This adds an extra@list.Empty
for each bottom-level node (depth=5), but since most leaves will be represented asFlat
(without hash collisions), the overhead is acceptableinplace
add_inplace
to reduce memory usage duringfrom_array
andfrom_iter
Comapre
brfore:
after:
Pending Work
bench