1 ! Based on Clojure's PersistentHashMap by Rich Hickey.
3 USING: accessors kernel math math.bitwise
4 persistent.hashtables.config persistent.hashtables.nodes
5 persistent.sequences sequences sequences.private ;
6 IN: persistent.hashtables.nodes.bitmap
8 : index ( bit bitmap -- n ) [ 1 - ] dip bitand bit-count ; inline
10 M:: bitmap-node (entry-at) ( key hashcode bitmap-node -- entry )
11 bitmap-node shift>> :> shift
12 hashcode shift bitpos :> bit
13 bitmap-node bitmap>> :> bitmap
14 bitmap-node nodes>> :> nodes
15 bitmap bit bitand 0 eq? [ f ] [
17 bit bitmap index nodes nth-unsafe
21 M:: bitmap-node (new-at) ( shift value key hashcode bitmap-node -- node' added-leaf )
22 bitmap-node shift>> :> shift
23 hashcode shift bitpos :> bit
24 bitmap-node bitmap>> :> bitmap
25 bit bitmap index :> idx
26 bitmap-node nodes>> :> nodes
28 bitmap bit bitand 0 eq? [
29 value key hashcode <leaf-node> :> new-leaf
31 new-leaf idx nodes insert-nth
37 shift radix-bits + value key hashcode n (new-at) :> ( n' new-leaf )
49 M:: bitmap-node (pluck-at) ( key hashcode bitmap-node -- node' )
50 hashcode bitmap-node shift>> bitpos :> bit
51 bitmap-node bitmap>> :> bitmap
52 bitmap-node nodes>> :> nodes
53 bitmap-node shift>> :> shift
54 bit bitmap bitand 0 eq? [ bitmap-node ] [
55 bit bitmap index :> idx
56 idx nodes nth-unsafe :> n
57 key hashcode n (pluck-at) :> n'
67 bitmap bit eq? [ f ] [
68 bitmap bit bitnot bitand
77 M: bitmap-node >alist% nodes>> >alist-each% ;