2005-03-28 23:45:13 -05:00
|
|
|
IN: temporary
|
2004-07-16 02:26:21 -04:00
|
|
|
USE: hashtables
|
|
|
|
USE: kernel
|
|
|
|
USE: lists
|
2004-08-26 22:21:17 -04:00
|
|
|
USE: math
|
2004-07-16 02:26:21 -04:00
|
|
|
USE: namespaces
|
|
|
|
USE: test
|
2004-08-04 03:12:55 -04:00
|
|
|
USE: vectors
|
2005-07-16 22:16:18 -04:00
|
|
|
USE: sequences
|
2005-09-11 20:46:55 -04:00
|
|
|
USE: sequences-internals
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
16 <hashtable> "testhash" set
|
|
|
|
|
2004-08-04 03:12:55 -04:00
|
|
|
: silly-key/value dup dup * swap ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-07-31 23:38:33 -04:00
|
|
|
1000 [ silly-key/value "testhash" get set-hash ] each
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
[ f ]
|
2005-07-25 17:13:35 -04:00
|
|
|
[ 1000 >list [ silly-key/value "testhash" get hash = not ] subset ]
|
2004-08-04 03:12:55 -04:00
|
|
|
unit-test
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
[ t ]
|
2004-08-04 03:12:55 -04:00
|
|
|
[ "testhash" get hashtable? ]
|
|
|
|
unit-test
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
[ f ]
|
2005-01-13 19:49:47 -05:00
|
|
|
[ [[ 1 [[ 2 3 ]] ]] hashtable? ]
|
2004-08-04 03:12:55 -04:00
|
|
|
unit-test
|
2004-08-07 18:45:48 -04:00
|
|
|
|
|
|
|
! Test some hashcodes.
|
|
|
|
|
|
|
|
[ t ] [ [ 1 2 3 ] hashcode [ 1 2 3 ] hashcode = ] unit-test
|
2005-01-13 19:49:47 -05:00
|
|
|
[ t ] [ [[ f t ]] hashcode [[ f t ]] hashcode = ] unit-test
|
2004-08-07 18:45:48 -04:00
|
|
|
[ t ] [ [ 1 [ 2 3 ] 4 ] hashcode [ 1 [ 2 3 ] 4 ] hashcode = ] unit-test
|
|
|
|
|
2004-11-20 16:57:01 -05:00
|
|
|
[ t ] [ 12 hashcode 12 hashcode = ] unit-test
|
|
|
|
[ t ] [ 12 >bignum hashcode 12 hashcode = ] unit-test
|
|
|
|
[ t ] [ 12.0 hashcode 12 >bignum hashcode = ] unit-test
|
2004-12-16 18:36:26 -05:00
|
|
|
|
|
|
|
! Test various odd keys to see if they work.
|
|
|
|
|
|
|
|
16 <hashtable> "testhash" set
|
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
t C{ 2 3 } "testhash" get set-hash
|
2005-01-23 16:47:28 -05:00
|
|
|
f 100000000000000000000000000 "testhash" get set-hash
|
2004-12-16 18:36:26 -05:00
|
|
|
{ } { [ { } ] } "testhash" get set-hash
|
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
[ t ] [ C{ 2 3 } "testhash" get hash ] unit-test
|
2005-01-23 16:47:28 -05:00
|
|
|
[ f ] [ 100000000000000000000000000 "testhash" get hash* cdr ] unit-test
|
2005-01-28 23:55:22 -05:00
|
|
|
[ { } ] [ { [ { } ] } clone "testhash" get hash* cdr ] unit-test
|
2004-12-17 21:46:19 -05:00
|
|
|
|
|
|
|
[
|
2005-01-13 19:49:47 -05:00
|
|
|
[[ "salmon" "fish" ]]
|
|
|
|
[[ "crocodile" "reptile" ]]
|
|
|
|
[[ "cow" "mammal" ]]
|
|
|
|
[[ "visual basic" "language" ]]
|
2004-12-17 21:46:19 -05:00
|
|
|
] alist>hash "testhash" set
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
"visual basic" "testhash" get remove-hash
|
|
|
|
"visual basic" "testhash" get hash*
|
|
|
|
] unit-test
|
2005-01-27 20:06:10 -05:00
|
|
|
|
|
|
|
[ 4 ] [
|
|
|
|
"hey"
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "hey" 4 ]] [[ "whey" 5 ]] } 2dup (hashcode)
|
2005-09-11 20:46:55 -04:00
|
|
|
swap underlying nth assoc
|
2005-01-27 20:06:10 -05:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! Testing the hash element counting
|
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ } clone "counting" set
|
2005-01-28 23:55:22 -05:00
|
|
|
"value" "key" "counting" get set-hash
|
2005-01-27 20:06:10 -05:00
|
|
|
[ 1 ] [ "counting" get hash-size ] unit-test
|
2005-01-28 23:55:22 -05:00
|
|
|
"value" "key" "counting" get set-hash
|
2005-01-27 20:06:10 -05:00
|
|
|
[ 1 ] [ "counting" get hash-size ] unit-test
|
2005-01-28 23:55:22 -05:00
|
|
|
"key" "counting" get remove-hash
|
|
|
|
[ 0 ] [ "counting" get hash-size ] unit-test
|
|
|
|
"key" "counting" get remove-hash
|
|
|
|
[ 0 ] [ "counting" get hash-size ] unit-test
|
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
[ t ] [ H{ } dup hash-contained? ] unit-test
|
|
|
|
[ f ] [ H{ [[ 1 3 ]] } H{ } hash-contained? ] unit-test
|
|
|
|
[ t ] [ H{ } H{ [[ 1 3 ]] } hash-contained? ] unit-test
|
|
|
|
[ t ] [ H{ [[ 1 3 ]] } H{ [[ 1 3 ]] } hash-contained? ] unit-test
|
|
|
|
[ f ] [ H{ [[ 1 3 ]] } H{ [[ 1 "hey" ]] } hash-contained? ] unit-test
|
|
|
|
[ f ] [ H{ [[ 1 f ]] } H{ } hash-contained? ] unit-test
|
|
|
|
[ t ] [ H{ [[ 1 f ]] } H{ [[ 1 f ]] } hash-contained? ] unit-test
|
|
|
|
|
|
|
|
[ t ] [ H{ } dup = ] unit-test
|
|
|
|
[ f ] [ "xyz" H{ } = ] unit-test
|
|
|
|
[ t ] [ H{ } H{ } = ] unit-test
|
|
|
|
[ f ] [ H{ [[ 1 3 ]] } H{ } = ] unit-test
|
|
|
|
[ f ] [ H{ } H{ [[ 1 3 ]] } = ] unit-test
|
|
|
|
[ t ] [ H{ [[ 1 3 ]] } H{ [[ 1 3 ]] } = ] unit-test
|
|
|
|
[ f ] [ H{ [[ 1 3 ]] } H{ [[ 1 "hey" ]] } = ] unit-test
|
2005-03-05 16:33:40 -05:00
|
|
|
|
|
|
|
! Test rehashing
|
|
|
|
|
|
|
|
2 <hashtable> "rehash" set
|
|
|
|
|
|
|
|
1 1 "rehash" get set-hash
|
|
|
|
2 2 "rehash" get set-hash
|
|
|
|
3 3 "rehash" get set-hash
|
|
|
|
4 4 "rehash" get set-hash
|
|
|
|
5 5 "rehash" get set-hash
|
|
|
|
6 6 "rehash" get set-hash
|
|
|
|
|
|
|
|
[ 6 ] [ "rehash" get hash-size ] unit-test
|
|
|
|
|
|
|
|
[ 6 ] [ "rehash" get clone hash-size ] unit-test
|
|
|
|
|
|
|
|
"rehash" get hash-clear
|
|
|
|
|
|
|
|
[ 0 ] [ "rehash" get hash-size ] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
3
|
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
2 H{
|
2005-03-05 16:33:40 -05:00
|
|
|
[[ 1 2 ]]
|
|
|
|
[[ 2 3 ]]
|
2005-10-29 23:25:38 -04:00
|
|
|
} clone hash
|
2005-03-05 16:33:40 -05:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! There was an assoc in place of assoc* somewhere
|
|
|
|
3 <hashtable> "f-hash-test" set
|
|
|
|
|
|
|
|
10 [ f f "f-hash-test" get set-hash ] times
|
|
|
|
|
|
|
|
[ 1 ] [ "f-hash-test" get hash-size ] unit-test
|
2005-06-12 22:06:03 -04:00
|
|
|
|
|
|
|
[ 21 ] [
|
2005-10-29 23:25:38 -04:00
|
|
|
0 H{
|
2005-06-12 22:06:03 -04:00
|
|
|
[[ 1 2 ]]
|
|
|
|
[[ 3 4 ]]
|
|
|
|
[[ 5 6 ]]
|
2005-10-29 23:25:38 -04:00
|
|
|
} [
|
2005-06-12 22:06:03 -04:00
|
|
|
uncons + +
|
|
|
|
] hash-each
|
|
|
|
] unit-test
|
2005-06-27 03:47:22 -04:00
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ } clone "cache-test" set
|
2005-06-27 03:47:22 -04:00
|
|
|
|
|
|
|
[ 4 ] [ 1 "cache-test" get [ 3 + ] cache ] unit-test
|
|
|
|
[ 5 ] [ 2 "cache-test" get [ 3 + ] cache ] unit-test
|
|
|
|
[ 4 ] [ 1 "cache-test" get [ 3 + ] cache ] unit-test
|
|
|
|
[ 5 ] [ 2 "cache-test" get [ 3 + ] cache ] unit-test
|
2005-09-16 02:39:33 -04:00
|
|
|
|
|
|
|
[
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "factor" "rocks" ]] [[ 3 4 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "factor" "rocks" ]] [[ "dup" "sq" ]] [[ 3 4 ]] }
|
|
|
|
H{ [[ "factor" "rocks" ]] [[ 1 2 ]] [[ 2 3 ]] [[ 3 4 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
hash-intersect
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ 1 2 ]] [[ 2 3 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "factor" "rocks" ]] [[ "dup" "sq" ]] [[ 3 4 ]] }
|
|
|
|
H{ [[ "factor" "rocks" ]] [[ 1 2 ]] [[ 2 3 ]] [[ 3 4 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
hash-diff
|
|
|
|
] unit-test
|
|
|
|
|
2005-09-16 20:49:24 -04:00
|
|
|
[
|
|
|
|
2
|
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "factor" "rocks" ]] [[ "dup" "sq" ]] [[ 3 4 ]] }
|
|
|
|
H{ [[ "factor" "rocks" ]] [[ 1 2 ]] [[ 2 3 ]] [[ 3 4 ]] }
|
2005-09-16 20:49:24 -04:00
|
|
|
hash-diff hash-size
|
|
|
|
] unit-test
|
|
|
|
|
2005-09-16 02:39:33 -04:00
|
|
|
[
|
|
|
|
t
|
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "hello" "world" ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
clone
|
2005-09-18 01:37:28 -04:00
|
|
|
100 [ 1+ over set-bucket-count hashcode ] map-with all-equal?
|
2005-09-16 02:39:33 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ 1 2 ]] [[ 2 3 ]] [[ 6 5 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
] [
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ 2 4 ]] [[ 6 5 ]] } H{ [[ 1 2 ]] [[ 2 3 ]] }
|
2005-09-16 02:39:33 -04:00
|
|
|
hash-union
|
|
|
|
] unit-test
|
2005-09-17 04:15:05 -04:00
|
|
|
|
2005-10-29 23:25:38 -04:00
|
|
|
[ [ 1 3 ] ] [ H{ [[ 2 2 ]] } [ 1 2 3 ] remove-all ] unit-test
|