From 48835572a7c6922927a443c27985434fddaeacf5 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 31 Oct 2016 23:13:20 -0700 Subject: 3619 --- html/070table.mu.html | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'html/070table.mu.html') diff --git a/html/070table.mu.html b/html/070table.mu.html index b843f50f..85df5029 100644 --- a/html/070table.mu.html +++ b/html/070table.mu.html @@ -40,10 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color tab:&:table:num:num <- new-table 30 run [ put-index tab, 12, 34 - 1:num/raw <- index tab, 12 + 60:num/raw, 61:bool/raw <- index tab, 12 ] memory-should-contain [ - 1 <- 34 + 60 <- 34 + 61 <- 1 # found ] ] @@ -52,10 +53,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color tab:&:table:text:num <- new-table 30 run [ put-index tab, [abc def], 34 - 1:num/raw <- index tab, [abc def] + 1:num/raw, 2:bool/raw <- index tab, [abc def] ] memory-should-contain [ 1 <- 34 + 2 <- 1 # found + ] +] + +scenario table-read-not-found [ + local-scope + tab:&:table:text:num <- new-table 30 + run [ + 1:num/raw, 2:bool/raw <- index tab, [abc def] + ] + memory-should-contain [ + 1 <- 0 + 2 <- 0 # not found ] ] @@ -96,7 +110,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color *table-data <- put-index *table-data, hash-key, new-row ] -def index table:&:table:_key:_value, key:_key -> result:_value [ +def index table:&:table:_key:_value, key:_key -> result:_value, found?:bool [ local-scope load-ingredients hash:num <- hash key @@ -106,8 +120,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color hash-key <- abs hash-key # in case hash overflows from a double into a negative integer inside 'divide-with-remainder' above 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] + empty:&:_value <- new _value:type + result <- copy *empty + found?:bool <- get x, occupied?:offset + return-unless found? + key2:_key <- get x, key:offset + found?:bool <- equal key, key2 + return-unless found? result <- get x, value:offset ] -- cgit 1.4.1-2-gfad0