about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-06 00:58:05 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-06 00:58:05 -0800
commited3cdddc3c5a03993b872baff70c5956885a6a37 (patch)
treef390860502f53ed5ae89cf2c9f827a3173066ebd
parentc47511798d8018902147593b44e76c17f6e86744 (diff)
downloadmu-ed3cdddc3c5a03993b872baff70c5956885a6a37.tar.gz
2629 - starting work on hash tables
-rw-r--r--077hash.mu28
1 files changed, 28 insertions, 0 deletions
diff --git a/077hash.mu b/077hash.mu
new file mode 100644
index 00000000..77e564d9
--- /dev/null
+++ b/077hash.mu
@@ -0,0 +1,28 @@
+# From http://burtleburtle.net/bob/hash/hashfaq.html#example
+# Though this one doesn't behave the same because mu uses doubles under the
+# hood, which wrap around at a different limit.
+recipe hash x:address:shared:array:character -> n:number [
+  local-scope
+  load-ingredients
+  n <- copy 0
+  len:number <- length *x
+  i:number <- copy 0
+  {
+    done?:boolean <- greater-or-equal i, len
+    break-if done?
+    c:character <- index *x, i
+    n <- add n, c
+    tmp1:number <- shift-left n, 10
+    n <- add n, tmp1
+    tmp2:number <- shift-right n, 6
+    n <- xor-bits n, tmp2
+    tmp3:number <- shift-left n, 3
+    n <- add n, tmp3
+    tmp4:number <- shift-right n, 11
+    n <- xor-bits n, tmp4
+    tmp5:number <- shift-left n, 15
+    n <- add n, tmp5
+    i <- add i, 1
+    loop
+  }
+]