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) :> new-leaf :> n'
52 M:: bitmap-node (pluck-at) ( key hashcode bitmap-node -- node' )
53 hashcode bitmap-node shift>> bitpos :> bit
54 bitmap-node bitmap>> :> bitmap
55 bitmap-node nodes>> :> nodes
56 bitmap-node shift>> :> shift
57 bit bitmap bitand 0 eq? [ bitmap-node ] [
58 bit bitmap index :> idx
59 idx nodes nth-unsafe :> n
60 key hashcode n (pluck-at) :> n'
70 bitmap bit eq? [ f ] [
71 bitmap bit bitnot bitand
80 M: bitmap-node >alist% ( node -- ) nodes>> >alist-each% ;