diff options
Diffstat (limited to 'stdlib/source/library/lux/data/collection/dictionary.lux')
-rw-r--r-- | stdlib/source/library/lux/data/collection/dictionary.lux | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/stdlib/source/library/lux/data/collection/dictionary.lux b/stdlib/source/library/lux/data/collection/dictionary.lux index 0b9690eb3..bdfc2638a 100644 --- a/stdlib/source/library/lux/data/collection/dictionary.lux +++ b/stdlib/source/library/lux/data/collection/dictionary.lux @@ -240,12 +240,12 @@ (product.right (list\mix (function (_ idx [insertion_idx node]) (let [[bitmap base] node] (case (array.read! idx h_array) - #.None [insertion_idx node] - {#.Some sub_node} (if (n.= except_idx idx) + {.#None} [insertion_idx node] + {.#Some sub_node} (if (n.= except_idx idx) [insertion_idx node] [(++ insertion_idx) [(with_bit_position (to_bit_position idx) bitmap) - (array.write! insertion_idx {#.Left sub_node} base)]]) + (array.write! insertion_idx {.#Left sub_node} base)]]) ))) [0 [clean_bitmap (array.empty (-- h_size))]] @@ -268,15 +268,15 @@ bitmap) [(++ base_idx) (case (array.read! base_idx base) - {#.Some {#.Left sub_node}} + {.#Some {.#Left sub_node}} (array.write! hierarchy_idx sub_node h_array) - {#.Some {#.Right [key' val']}} + {.#Some {.#Right [key' val']}} (array.write! hierarchy_idx (node\has (level_up level) (\ key_hash hash key') key' val' key_hash empty_node) h_array) - #.None + {.#None} (undefined))] default)) [0 @@ -303,7 +303,7 @@ {#Hierarchy _size hierarchy} (let [idx (level_index level hash) [_size' sub_node] (case (array.read! idx hierarchy) - {#.Some sub_node} + {.#Some sub_node} [_size sub_node] _ @@ -321,18 +321,18 @@ (let [idx (base_index bit bitmap)] (case (array.read! idx base) ... If it's being used by a node, add the KV to it. - {#.Some {#.Left sub_node}} + {.#Some {.#Left sub_node}} (let [sub_node' (node\has (level_up level) hash key val key_hash sub_node)] - {#Base bitmap (array\revised idx {#.Left sub_node'} base)}) + {#Base bitmap (array\revised idx {.#Left sub_node'} base)}) ... Otherwise, if it's being used by a KV, compare the keys. - {#.Some {#.Right key' val'}} + {.#Some {.#Right key' val'}} (if (\ key_hash = key key') ... If the same key is found, replace the value. - {#Base bitmap (array\revised idx {#.Right key val} base)} + {#Base bitmap (array\revised idx {.#Right key val} base)} ... Otherwise, compare the hashes of the keys. {#Base bitmap (array\revised idx - {#.Left (let [hash' (\ key_hash hash key')] + {.#Left (let [hash' (\ key_hash hash key')] (if (n.= hash hash') ... If the hashes are ... the same, a new @@ -352,7 +352,7 @@ (node\has next_level hash key val key_hash)))))} base)}) - #.None + {.#None} (undefined))) ... However, if the Bit_Position has not been used yet, check ... whether this #Base node is ready for a promotion. @@ -361,7 +361,7 @@ ... If so, resize the #Base node to accommodate the ... new KV-pair. {#Base (with_bit_position bit bitmap) - (array\has (base_index bit bitmap) {#.Right [key val]} base)} + (array\has (base_index bit bitmap) {.#Right [key val]} base)} ... Otherwise, promote it to a #Hierarchy node, and add the new ... KV-pair as a singleton node to it. {#Hierarchy (++ base_count) @@ -378,17 +378,17 @@ (case (collision_index key_hash key _colls) ... If the key was already present in the collisions-list, its ... value gets updated. - {#.Some coll_idx} + {.#Some coll_idx} {#Collisions _hash (array\revised coll_idx [key val] _colls)} ... Otherwise, the KV-pair is added to the collisions-list. - #.None + {.#None} {#Collisions _hash (array\has (array.size _colls) [key val] _colls)}) ... If the hashes are not equal, create a new #Base node that ... contains the old #Collisions node, plus the new KV-pair. (|> {#Base (level_bit_position level _hash) (|> (array.empty 1) - (array.write! 0 {#.Left node}))} + (array.write! 0 {.#Left node}))} (node\has level hash key val key_hash))) )) @@ -401,11 +401,11 @@ (let [idx (level_index level hash)] (case (array.read! idx h_array) ... If not, there's nothing to remove. - #.None + {.#None} node ... But if there is, try to remove the key from the sub-node. - {#.Some sub_node} + {.#Some sub_node} (let [sub_node' (node\lacks (level_up level) hash key key_hash sub_node)] ... Then check if a removal was actually done. (if (same? sub_node sub_node') @@ -431,7 +431,7 @@ (case (array.read! idx base) ... If set, check if it's a sub_node, and remove the KV ... from it. - {#.Some {#.Left sub_node}} + {.#Some {.#Left sub_node}} (let [sub_node' (node\lacks (level_up level) hash key key_hash sub_node)] ... Verify that it was removed. (if (same? sub_node sub_node') @@ -450,10 +450,10 @@ ... But, if it did not come out empty, then the ... position is kept, and the node gets updated. {#Base bitmap - (array\revised idx {#.Left sub_node'} base)}))) + (array\revised idx {.#Left sub_node'} base)}))) ... If, however, there was a KV-pair instead of a sub-node. - {#.Some {#.Right [key' val']}} + {.#Some {.#Right [key' val']}} ... Check if the keys match. (if (\ key_hash = key key') ... If so, remove the KV-pair and unset the Bit_Position. @@ -462,7 +462,7 @@ ... Otherwise, there's nothing to remove. node) - #.None + {.#None} (undefined))) ... If the Bit_Position is not set, there's nothing to remove. node)) @@ -471,11 +471,11 @@ {#Collisions _hash _colls} (case (collision_index key_hash key _colls) ... If not, then there's nothing to remove. - #.None + {.#None} node ... But if so, then check the size of the collisions list. - {#.Some idx} + {.#Some idx} (if (n.= 1 (array.size _colls)) ... If there's only one left, then removing it leaves us with ... an empty node. @@ -490,25 +490,25 @@ ... For #Hierarchy nodes, just look-up the key on its children. {#Hierarchy _size hierarchy} (case (array.read! (level_index level hash) hierarchy) - #.None #.None - {#.Some sub_node} (node\value (level_up level) hash key key_hash sub_node)) + {.#None} {.#None} + {.#Some sub_node} (node\value (level_up level) hash key key_hash sub_node)) ... For #Base nodes, check the leaves, and recursively check the branches. {#Base bitmap base} (let [bit (level_bit_position level hash)] (if (with_bit_position? bit bitmap) (case (array.read! (base_index bit bitmap) base) - {#.Some {#.Left sub_node}} + {.#Some {.#Left sub_node}} (node\value (level_up level) hash key key_hash sub_node) - {#.Some {#.Right [key' val']}} + {.#Some {.#Right [key' val']}} (if (\ key_hash = key key') - {#.Some val'} - #.None) + {.#Some val'} + {.#None}) - #.None + {.#None} (undefined)) - #.None)) + {.#None})) ... For #Collisions nodes, do a linear scan of all the known KV-pairs. {#Collisions _hash _colls} @@ -526,8 +526,8 @@ {#Base _ base} (array\mix n.+ 0 (array\each (function (_ sub_node') (case sub_node' - {#.Left sub_node} (node\size sub_node) - {#.Right _} 1)) + {.#Left sub_node} (node\size sub_node) + {.#Right _} 1)) base)) {#Collisions hash colls} @@ -539,23 +539,23 @@ (case node {#Hierarchy _size hierarchy} (array\mix (function (_ sub_node tail) (list\composite (node\entries sub_node) tail)) - #.End + {.#End} hierarchy) {#Base bitmap base} (array\mix (function (_ branch tail) (case branch - {#.Left sub_node} + {.#Left sub_node} (list\composite (node\entries sub_node) tail) - {#.Right [key' val']} - {#.Item [key' val'] tail})) - #.End + {.#Right [key' val']} + {.#Item [key' val'] tail})) + {.#End} base) {#Collisions hash colls} - (array\mix (function (_ [key' val'] tail) {#.Item [key' val'] tail}) - #.End + (array\mix (function (_ [key' val'] tail) {.#Item [key' val'] tail}) + {.#End} colls))) (type: .public (Dictionary k v) @@ -565,7 +565,7 @@ (def: .public key_hash (All (_ k v) (-> (Dictionary k v) (Hash k))) - (value@ #..hash)) + (value@ ..#hash)) (def: .public (empty key_hash) (All (_ k v) (-> (Hash k) (Dictionary k v))) @@ -590,24 +590,24 @@ (def: .public (key? dict key) (All (_ k v) (-> (Dictionary k v) k Bit)) (case (value key dict) - #.None #0 - {#.Some _} #1)) + {.#None} #0 + {.#Some _} #1)) (exception: .public key_already_exists) (def: .public (has' key val dict) (All (_ k v) (-> k v (Dictionary k v) (Try (Dictionary k v)))) (case (value key dict) - #.None {#try.Success (has key val dict)} - {#.Some _} (exception.except ..key_already_exists []))) + {.#None} {try.#Success (has key val dict)} + {.#Some _} (exception.except ..key_already_exists []))) (def: .public (revised key f dict) (All (_ k v) (-> k (-> v v) (Dictionary k v) (Dictionary k v))) (case (value key dict) - #.None + {.#None} dict - {#.Some val} + {.#Some val} (has key (f val) dict))) (def: .public (revised' key default f dict) @@ -641,8 +641,8 @@ (All (_ k v) (-> (Dictionary k v) (List <side>))) (|>> ..entries (list\mix (function (_ [k v] bundle) - {#.Item <side> bundle}) - #.End)))] + {.#Item <side> bundle}) + {.#End})))] [k keys] [v values] @@ -658,10 +658,10 @@ (All (_ k v) (-> (-> v v v) (Dictionary k v) (Dictionary k v) (Dictionary k v))) (list\mix (function (_ [key val2] dict) (case (value key dict) - #.None + {.#None} (has key val2 dict) - {#.Some val1} + {.#Some val1} (has key (f val2 val1) dict))) dict1 (entries dict2))) @@ -669,10 +669,10 @@ (def: .public (re_bound from_key to_key dict) (All (_ k v) (-> k k (Dictionary k v) (Dictionary k v))) (case (value from_key dict) - #.None + {.#None} dict - {#.Some val} + {.#Some val} (|> dict (lacks from_key) (has to_key val)))) @@ -682,8 +682,8 @@ (let [[key_hash _] dict] (list\mix (function (_ key new_dict) (case (value key dict) - #.None new_dict - {#.Some val} (has key val new_dict))) + {.#None} new_dict + {.#Some val} (has key val new_dict))) (empty key_hash) keys))) @@ -695,7 +695,7 @@ (..size subject)) (list.every? (function (_ [k rv]) (case (..value k subject) - {#.Some sv} + {.#Some sv} (,\= rv sv) _ @@ -713,11 +713,11 @@ {#Base bitmap base} {#Base bitmap (array\each (function (_ either) (case either - {#.Left fa'} - {#.Left (each f fa')} + {.#Left fa'} + {.#Left (each f fa')} - {#.Right [k v]} - {#.Right [k (f v)]})) + {.#Right [k v]} + {.#Right [k (f v)]})) base)} {#Collisions hash collisions} |