]> gitweb.factorcode.org Git - factor.git/commitdiff
persistent.hashtables: cleanup.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 29 Jan 2020 00:22:33 +0000 (16:22 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 29 Jan 2020 00:22:33 +0000 (16:22 -0800)
basis/persistent/hashtables/hashtables.factor

index 64577f8ff01411f1f5487aa902bcb2f12708e691..4d474caa79faa49730079e2d86cb8ede1389d374 100644 (file)
@@ -1,19 +1,14 @@
 ! Based on Clojure's PersistentHashMap by Rich Hickey.
 
-USING: kernel math accessors assocs fry combinators parser
-prettyprint.custom locals make sequences
-persistent.assocs
-persistent.hashtables.nodes
-persistent.hashtables.nodes.empty
-persistent.hashtables.nodes.leaf
-persistent.hashtables.nodes.full
-persistent.hashtables.nodes.bitmap
-persistent.hashtables.nodes.collision ;
+USING: accessors assocs combinators kernel make math
+parser persistent.assocs persistent.hashtables.nodes
+prettyprint.custom ;
+
 IN: persistent.hashtables
 
 TUPLE: persistent-hash
-{ root read-only initial: empty-node }
-{ count fixnum read-only } ;
+    { root read-only initial: empty-node }
+    { count fixnum read-only } ;
 
 M: persistent-hash assoc-size count>> ;
 
@@ -21,13 +16,11 @@ M: persistent-hash at*
      [ dup hashcode >fixnum ] [ root>> ] bi* (entry-at)
      dup [ value>> t ] [ f ] if ;
 
-M: persistent-hash new-at ( value key assoc -- assoc' )
+M: persistent-hash new-at
     [
         [ 0 ] 3dip
-        [ dup hashcode >fixnum ] [ root>> ] bi*
-        (new-at) 1 0 ?
-    ] [ count>> ] bi +
-    persistent-hash boa ;
+        [ dup hashcode >fixnum ] [ root>> ] bi* (new-at) 1 0 ?
+    ] [ count>> ] bi + persistent-hash boa ;
 
 M: persistent-hash pluck-at
     [ [ dup hashcode >fixnum ] [ root>> ] bi* (pluck-at) ] keep
@@ -39,12 +32,12 @@ M: persistent-hash pluck-at
 
 M: persistent-hash >alist [ root>> >alist% ] { } make ;
 
-M: persistent-hash keys >alist [ first ] map ;
+M: persistent-hash keys >alist keys ;
 
-M: persistent-hash values >alist [ second ] map ;
+M: persistent-hash values >alist values ;
 
-:: >persistent-hash ( assoc -- phash )
-    T{ persistent-hash } assoc [| ph k v | v k ph new-at ] assoc-each ;
+: >persistent-hash ( assoc -- phash )
+    T{ persistent-hash } swap [ swap rot new-at ] assoc-each ;
 
 M: persistent-hash equal?
     over persistent-hash? [ assoc= ] [ 2drop f ] if ;