Improve sequence hash algorithm
parent
52c3db354b
commit
48026c7d8d
|
@ -38,9 +38,7 @@ TUPLE: no-case ;
|
|||
pick 0 <= [ 3drop 0 ] [ rot 1- -rot call ] if ; inline
|
||||
|
||||
M: sequence hashcode*
|
||||
[
|
||||
0 -rot [ hashcode* bitxor ] curry* each
|
||||
] recursive-hashcode ;
|
||||
[ sequence-hashcode ] recursive-hashcode ;
|
||||
|
||||
: alist>quot ( default assoc -- quot )
|
||||
[ rot \ if 3array append [ ] like ] assoc-each ;
|
||||
|
|
|
@ -44,7 +44,7 @@ M: sequence lengthen 2dup length > [ set-length ] [ 2drop ] if ;
|
|||
TUPLE: bounds-error index seq ;
|
||||
|
||||
: bounds-error ( n seq -- * )
|
||||
\ bounds-error construct-boa throw ;
|
||||
die \ bounds-error construct-boa throw ;
|
||||
|
||||
: bounds-check ( n seq -- n seq )
|
||||
2dup bounds-check? [ bounds-error ] unless ; inline
|
||||
|
@ -666,3 +666,8 @@ PRIVATE>
|
|||
|
||||
: infimum ( seq -- n ) dup first [ min ] reduce ;
|
||||
: supremum ( seq -- n ) dup first [ max ] reduce ;
|
||||
|
||||
: sequence-hashcode ( n seq -- x )
|
||||
0 -rot [
|
||||
hashcode* >fixnum swap 31 fixnum*fast fixnum+fast
|
||||
] curry* each ; inline
|
||||
|
|
|
@ -13,8 +13,7 @@ IN: strings
|
|||
: reset-string-hashcode f swap set-string-hashcode ; inline
|
||||
|
||||
: rehash-string ( str -- )
|
||||
dup 0 [ swap 31 fixnum*fast fixnum+fast ] reduce
|
||||
swap set-string-hashcode ; inline
|
||||
1 over sequence-hashcode swap set-string-hashcode ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
|
Loading…
Reference in New Issue