1 ! Based on Clojure's PersistentHashMap by Rich Hickey.
3 USING: math math.bitwise arrays kernel accessors locals sequences
6 persistent.hashtables.config
7 persistent.hashtables.nodes ;
8 IN: persistent.hashtables.nodes.bitmap
10 : index ( bit bitmap -- n ) [ 1 - ] dip bitand bit-count ; inline
12 M:: bitmap-node (entry-at) ( key hashcode bitmap-node -- entry )
13 bitmap-node shift>> :> shift
14 hashcode shift bitpos :> bit
15 bitmap-node bitmap>> :> bitmap
16 bitmap-node nodes>> :> nodes
17 bitmap bit bitand 0 eq? [ f ] [
19 bit bitmap index nodes nth-unsafe
23 M:: bitmap-node (new-at) ( shift value key hashcode bitmap-node -- node' added-leaf )
24 bitmap-node shift>> :> shift
25 hashcode shift bitpos :> bit
26 bitmap-node bitmap>> :> bitmap
27 bit bitmap index :> idx
28 bitmap-node nodes>> :> nodes
30 bitmap bit bitand 0 eq? [
31 value key hashcode <leaf-node> :> new-leaf
33 new-leaf idx nodes insert-nth
39 shift radix-bits + value key hashcode n (new-at) :> ( n' new-leaf )
51 M:: bitmap-node (pluck-at) ( key hashcode bitmap-node -- node' )
52 hashcode bitmap-node shift>> bitpos :> bit
53 bitmap-node bitmap>> :> bitmap
54 bitmap-node nodes>> :> nodes
55 bitmap-node shift>> :> shift
56 bit bitmap bitand 0 eq? [ bitmap-node ] [
57 bit bitmap index :> idx
58 idx nodes nth-unsafe :> n
59 key hashcode n (pluck-at) :> n'
69 bitmap bit eq? [ f ] [
70 bitmap bit bitnot bitand
79 M: bitmap-node >alist% nodes>> >alist-each% ;