diff options
-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 |