def HMap.split

bend-kit-collections@0.1.4.1 · hmap.bend:68

import bend-kit-collections@0.1.4.1/hmap.bend as Hmap
import Base

68def HMap.split(
69  ~K: Data, ~V: Data, ~eq: K -> K -> Bool,
70  +n: Nat, +mask: U32, +oldhash: U32, +entries: List<&2, Entry<K, V>>,
71  +hash: U32, +k: K, +v: V
72) -> HMap<K, V>:
73  match n:
74    case 0n:
75      HLeaf{oldhash, HMap.entries.put(~K, ~V, ~eq, entries, k, v)}
76    case 1n+p:
77      HMap.bool(HMap<K, V>, U32.is_eq((oldhash .&. mask : U32), (hash .&. mask : U32)),
78        u => HMap.bool(HMap<K, V>, U32.is_eq((oldhash .&. mask : U32), 0),
79          x => HBranch{HMap.split(~K, ~V, ~eq, p, (mask << 1n : U32), oldhash, entries, hash, k, v), HNil{}},
80          x => HBranch{HNil{}, HMap.split(~K, ~V, ~eq, p, (mask << 1n : U32), oldhash, entries, hash, k, v)}),
81        u => HMap.split.side(K, V, U32.is_eq((oldhash .&. mask : U32), 0),
82          HLeaf{oldhash, entries}, HLeaf{hash, [Entry{k, v}]}))

Uses (12)

Used by (4)