diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-31 21:59:05 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-31 21:59:05 -0700 |
commit | 88b8d6124e199a61c302e4f7b826fbc991410076 (patch) | |
tree | 81e437126d755e2433f709f4b5be57b44324b697 | |
parent | 7c3bbb775b92577a147676c2901c449abfe4e8ca (diff) | |
download | mu-88b8d6124e199a61c302e4f7b826fbc991410076.tar.gz |
3615
-rw-r--r-- | 070table.mu | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/070table.mu b/070table.mu index 111e56b5..1b3d5fd3 100644 --- a/070table.mu +++ b/070table.mu @@ -51,15 +51,15 @@ def put-index table:&:table:_key:_value, key:_key, value:_value -> table:&:table hash:num <- hash key hash <- abs hash capacity:num <- get *table, capacity:offset - _, hash <- divide-with-remainder hash, capacity - hash <- abs hash # in case hash overflows into a negative integer + _, hash-key:num <- divide-with-remainder hash, capacity + hash-key <- abs hash-key # in case hash-key overflows into a negative integer table-data:&:@:table-row:_key:_value <- get *table, data:offset - x:table-row:_key:_value <- index *table-data, hash + x:table-row:_key:_value <- index *table-data, hash-key occupied?:bool <- get x, occupied?:offset not-occupied?:bool <- not occupied?:bool assert not-occupied?, [can't handle collisions yet] new-row:table-row:_key:_value <- merge 1/true, key, value - *table-data <- put-index *table-data, hash, new-row + *table-data <- put-index *table-data, hash-key, new-row ] def abs n:num -> result:num [ @@ -76,10 +76,10 @@ def index table:&:table:_key:_value, key:_key -> result:_value [ hash:num <- hash key hash <- abs hash capacity:num <- get *table, capacity:offset - _, hash <- divide-with-remainder hash, capacity - hash <- abs hash # in case hash overflows into a negative integer + _, hash-key:num <- divide-with-remainder hash, capacity + hash-key <- abs hash-key # in case hash-key overflows into a negative integer table-data:&:@:table-row:_key:_value <- get *table, data:offset - x:table-row:_key:_value <- index *table-data, hash + x:table-row:_key:_value <- index *table-data, hash-key occupied?:bool <- get x, occupied?:offset assert occupied?, [can't handle missing elements yet] result <- get x, value:offset |