about summary refs log tree commit diff stats
path: root/512array.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-19 15:39:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-19 15:39:36 -0700
commit542773df2f2055fb06efedd353cbce1474653607 (patch)
treefcc26ef08b632f3416438f773736cae4b9cc2405 /512array.mu
parentb22e6ebfe2b4bd3533495a71b39a14c5ed8eb831 (diff)
downloadmu-542773df2f2055fb06efedd353cbce1474653607.tar.gz
render functions in MRU order
Diffstat (limited to '512array.mu')
-rw-r--r--512array.mu21
1 files changed, 21 insertions, 0 deletions
diff --git a/512array.mu b/512array.mu
index 19d5485c..b2a0ceb0 100644
--- a/512array.mu
+++ b/512array.mu
@@ -80,6 +80,27 @@ fn test-slide-down {
   check-slide-down "0 1 2 3 0", 1/start 4/end, 2/target, "0 1 1 2 3", "F - test-slide-down/overlapping"
 }
 
+# Return the index that val is at.
+# If not found, return len-1.
+# That way the result is always a valid index to pass into slide-down.
+fn find-slide-down-slot-in-array _a: (addr array int), _val: int -> _/ecx: int {
+  var a/esi: (addr array int) <- copy _a
+  var val/ebx: int <- copy _val
+  var max/edx: int <- length a
+  max <- decrement
+  var i/ecx: int <- copy 0
+  {
+    compare i, max
+    break-if->=
+    var curr/eax: (addr int) <- index a, i
+    compare *curr, val
+    break-if-=
+    i <- increment
+    loop
+  }
+  return i
+}
+
 # helpers for tests
 fn check-slide-up before: (addr array byte), start: int, end: int, target: int, after: (addr array byte), msg: (addr array byte) {
   var arr-h: (handle array int)