From 1167f8779c2de268a074fc8656f022721df56c3f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 31 Oct 2016 22:00:07 -0700 Subject: 3617 --- html/070table.mu.html | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'html') diff --git a/html/070table.mu.html b/html/070table.mu.html index 61e1466b..7d46ec53 100644 --- a/html/070table.mu.html +++ b/html/070table.mu.html @@ -62,10 +62,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color container table:_key:_value [ length:num capacity:num - data:&:@:table_row:_key:_value + data:&:@:table-row:_key:_value ] -container table_row:_key:_value [ +container table-row:_key:_value [ occupied?:bool key:_key value:_value @@ -75,7 +75,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients result <- new {(table _key _value): type} - data:&:@:table_row:_key:_value <- new {(table_row _key _value): type}, capacity + data:&:@:table-row:_key:_value <- new {(table-row _key _value): type}, capacity *result <- merge 0/length, capacity, data ] @@ -85,23 +85,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 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 - table-data:&:@:table_row:_key:_value <- get *table, data:offset - x:table_row:_key:_value <- index *table-data, hash + _, 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-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 -] - -def abs n:num -> result:num [ - local-scope - load-ingredients - positive?:bool <- greater-or-equal n, 0 - return-if positive?, n - result <- multiply n, -1 + new-row:table-row:_key:_value <- merge 1/true, key, value + *table-data <- put-index *table-data, hash-key, new-row ] def index table:&:table:_key:_value, key:_key -> result:_value [ @@ -110,14 +102,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 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 - table-data:&:@:table_row:_key:_value <- get *table, data:offset - x:table_row:_key:_value <- index *table-data, hash + _, 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-key occupied?:bool <- get x, occupied?:offset assert occupied?, [can't handle missing elements yet] result <- get x, value:offset ] + +def abs n:num -> result:num [ + local-scope + load-ingredients + positive?:bool <- greater-or-equal n, 0 + return-if positive?, n + result <- multiply n, -1 +] -- cgit 1.4.1-2-gfad0