diff options
author | Eduardo Julian | 2016-12-22 02:10:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-12-22 02:10:30 -0400 |
commit | 02e6cd7687a0acba65b47f12db45bea0db604fdb (patch) | |
tree | a00f46b68a3ba0631e05278f96bee55fd04ede65 /stdlib/source | |
parent | 168c783c2aa203316846e4f86de30f0735e51917 (diff) |
- Fixed a bug in the way hierarchy->base demotion worked for Dict nodes.
- Fixed a bug in a test for lux/data/struct/list.
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/data/struct/dict.lux | 26 | ||||
-rw-r--r-- | stdlib/source/lux/data/struct/set.lux | 18 |
2 files changed, 23 insertions, 21 deletions
diff --git a/stdlib/source/lux/data/struct/dict.lux b/stdlib/source/lux/data/struct/dict.lux index 38cfe7efa..56ab6ca64 100644 --- a/stdlib/source/lux/data/struct/dict.lux +++ b/stdlib/source/lux/data/struct/dict.lux @@ -228,18 +228,20 @@ ## nodes to save space. (def: (demote-hierarchy except-idx [h-size h-array]) (All [k v] (-> Index (Hierarchy k v) [BitMap (Base k v)])) - (List/fold (lambda [idx (^@ node [bitmap base])] - (case (array;get idx h-array) - #;None node - (#;Some sub-node) (if (n.= except-idx idx) - node - [(set-bit-position (->bit-position idx) bitmap) - (array;put idx (#;Left sub-node) base)]) - )) - [clean-bitmap - (: (Base ($ +0) ($ +1)) - (array;new (n.dec h-size)))] - (list;indices (array;size h-array)))) + (product;right (List/fold (lambda [idx [insertion-idx node]] + (let [[bitmap base] node] + (case (array;get idx h-array) + #;None [insertion-idx node] + (#;Some sub-node) (if (n.= except-idx idx) + [insertion-idx node] + [(n.inc insertion-idx) + [(set-bit-position (->bit-position idx) bitmap) + (array;put insertion-idx (#;Left sub-node) base)]]) + ))) + [+0 [clean-bitmap + (: (Base ($ +0) ($ +1)) + (array;new (n.dec h-size)))]] + (list;indices (array;size h-array))))) ## When #Base nodes grow too large, they're promoted to #Hierarchy to ## add some depth to the tree and help keep it's balance. diff --git a/stdlib/source/lux/data/struct/set.lux b/stdlib/source/lux/data/struct/set.lux index 44a383e7c..5f828ba43 100644 --- a/stdlib/source/lux/data/struct/set.lux +++ b/stdlib/source/lux/data/struct/set.lux @@ -35,13 +35,21 @@ (All [a] (-> (Set a) a Bool)) (dict;contains? elem set)) +(def: #export to-list + (All [a] (-> (Set a) (List a))) + dict;keys) + +(def: #export (from-list Hash<a> xs) + (All [a] (-> (Hash a) (List a) (Set a))) + (List/fold add (new Hash<a>) xs)) + (def: #export (union xs yx) (All [a] (-> (Set a) (Set a) (Set a))) (dict;merge xs yx)) (def: #export (difference subs base) (All [a] (-> (Set a) (Set a) (Set a))) - (List/fold remove base (dict;keys subs))) + (List/fold remove base (to-list subs))) (def: #export (intersection filter base) (All [a] (-> (Set a) (Set a) (Set a))) @@ -55,14 +63,6 @@ (All [a] (-> (Set a) Bool)) (n.= +0 (dict;size set))) -(def: #export to-list - (All [a] (-> (Set a) (List a))) - dict;keys) - -(def: #export (from-list Hash<a> xs) - (All [a] (-> (Hash a) (List a) (Set a))) - (List/fold add (new Hash<a>) xs)) - (def: #export (sub? super sub) (All [a] (-> (Set a) (Set a) Bool)) (list;every? (member? super) (to-list sub))) |