Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b48876c832
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (26 sloc) 1.154 kb
###########
# hashmaps!
###########
addHash k v hashmap = cons (cons k v) (removeHash k hashmap)
hashFromList l = if (null? l) nil
addHash (head l) (head (tail l)) (hashFromList (tail (tail l)))
key cons = head cons
value cons = tail cons
getPair k hashmap = findIf (\x . eq (head x) k) hashmap
# getPairOpt returns a 2Valued option
getPairOpt k l = l (\h t D . h (\kk vv . (eq k kk) (some2 kk vv) (getPairOpt k t))) none
getHashValue k hashmap = (\pair. if (eq pair nil) nil (value pair)) (getPair k hashmap)
getHashValueDefault k default hashmap = do
val = getHashValue k hashmap
if (neq val nil) val default
getKeys hashmap = map (\cell . (key cell)) hashmap
numKeys hashmap = length (getKeys hashmap)
firstPair hashmap = head hashmap
restPairs hashmap = tail hashmap
mergeHashKeys hm1 hm2 keys = if (null? keys) hm1
if (null? (getPair (head keys) hm1) )
cons (getPair (head keys) hm2) (mergeHashKeys hm1 hm2 (tail keys))
mergeHashKeys hm1 hm2 (tail keys)
# keys in hm2 take precedence over keys in hm1
mergeHash hm1 hm2 = mergeHashKeys hm1 hm2 (getKeys hm2)
removeHash k hashmap = removeIf (\x . eq (key x) k) hashmap
Jump to Line
Something went wrong with that request. Please try again.