]> gitweb.factorcode.org Git - factor.git/commitdiff
hash-sets,hashtables: improved key@ word
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 25 Sep 2016 18:07:08 +0000 (20:07 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 25 Sep 2016 18:07:08 +0000 (20:07 +0200)
Don't need to check the length of the backing array because it can be
assumed to be > 0. That should make hash lookups a little faster.

core/hash-sets/hash-sets-tests.factor
core/hash-sets/hash-sets.factor
core/hashtables/hashtables.factor

index 46dc06849fb1dfc5d6f3fa965df50333566e06a1..3bf7f8a45435945ef48ccc53ccde4132dffd31f4 100644 (file)
@@ -1,7 +1,17 @@
 ! Copyright (C) 2010 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors fry hash-sets kernel math prettyprint sequences
-sets sorting tools.test ;
+USING: accessors arrays fry hash-sets hash-sets.private kernel math
+prettyprint sequences sets sorting tools.test ;
+FROM: hashtables.private => tombstone ;
+
+! key@
+{
+    { { T{ tombstone } T{ tombstone } } f f }
+    { { T{ tombstone } 123 } 1 t }
+} [
+    "hi" 0 <hash-set> key@ 3array
+    123 HS{ 123 } key@ 3array
+] unit-test
 
 { { 1 2 3 } } [ HS{ 1 2 3 } members natural-sort ] unit-test
 
index 9e99dc6a1a99c041624d6fe27d57719acfa54dac..03577db12a7180066509d67fd3b877fa57a74746 100644 (file)
@@ -32,8 +32,7 @@ TUPLE: hash-set
     ] if ; inline recursive
 
 : key@ ( key hash -- array n ? )
-    array>> dup length>> 0 eq?
-    [ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
+    array>> 2dup hash@ 0 (key@) ; inline
 
 : <hash-array> ( n -- array )
     3 * 1 + 2/ next-power-of-2 +empty+ <array> ; inline
index d7763428d7c8db2a9eb8bdd31e56879e0dc79680..ee14103cb835952af7b5d5b4cc7aaaac3596c287 100644 (file)
@@ -32,8 +32,7 @@ TUPLE: hashtable
     ] if ; inline recursive
 
 : key@ ( key hash -- array n ? )
-    array>> dup length>> 0 eq?
-    [ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
+    array>> 2dup hash@ 0 (key@) ; inline
 
 : <hash-array> ( n -- array )
     3 * 1 + 2/ next-power-of-2 2 * +empty+ <array> ; inline