aboutsummaryrefslogtreecommitdiffstats
path: root/csc/hash-map-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-13 15:47:30 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-13 15:47:30 -0800
commitd65318dd916a3529f009e8c431b8da2df6446c0e (patch)
tree42120edd43b518bbb9d40127b5b02e4ab75938ef /csc/hash-map-test.csc
parentAdd a README. (diff)
downloadchromatopelma-d65318dd916a3529f009e8c431b8da2df6446c0e.tar.zst
Generalize the hash map.
Before we were assuming keys could be compared with eqv?. But it seems like that assumption isn't true when we want to hold identifiers in the hash map.
Diffstat (limited to 'csc/hash-map-test.csc')
-rw-r--r--csc/hash-map-test.csc13
1 files changed, 10 insertions, 3 deletions
diff --git a/csc/hash-map-test.csc b/csc/hash-map-test.csc
index 353e6b4..3e26570 100644
--- a/csc/hash-map-test.csc
+++ b/csc/hash-map-test.csc
@@ -15,8 +15,15 @@
(string<? (symbol->string s1) (symbol->string s2)))
+(define (cmp-symbols s1 s2)
+ (cond
+ ((symbol<? s1 s2) -1)
+ ((symbol=? s1 s2) 0)
+ (else 1)))
+
+
(define (alist->map->alist l)
- (map->alist (alist->map hash-symbol symbol<? l)))
+ (map->alist (alist->map hash-symbol cmp-symbols l)))
(define (sort-alist l)
@@ -70,9 +77,9 @@
(test lookup
(assert-equal
2
- (lookup (alist->map hash-symbol symbol<? '((a . 1) (b . 2) (c . 3))) 'b)))
+ (lookup (alist->map hash-symbol cmp-symbols '((a . 1) (b . 2) (c . 3))) 'b)))
(test lookup-notfound
(assert-raises key-not-found-error?
- (lookup (alist->map hash-symbol symbol<? '((a . 1) (b . 2) (c . 3))) 'd)))
+ (lookup (alist->map hash-symbol cmp-symbols '((a . 1) (b . 2) (c . 3))) 'd)))