From 88b8d6124e199a61c302e4f7b826fbc991410076 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 31 Oct 2016 21:59:05 -0700 Subject: 3615 --- 070table.mu | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to '070table.mu') 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 -- cgit 1.4.1-2-gfad0