aboutsummaryrefslogtreecommitdiffstats
path: root/sw/cal/table.go
diff options
context:
space:
mode:
Diffstat (limited to 'sw/cal/table.go')
-rw-r--r--sw/cal/table.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/sw/cal/table.go b/sw/cal/table.go
new file mode 100644
index 0000000..20d21d0
--- /dev/null
+++ b/sw/cal/table.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ "slices"
+)
+
+const tabRows = 32
+
+type Table struct {
+ keys []int32
+ vals []uint16
+}
+
+func (t *Table) Insert(key int32, val uint16) error {
+ if len(t.keys) >= tabRows {
+ return fmt.Errorf("too many rows")
+ }
+
+ i, ok := slices.BinarySearch(t.keys, key)
+ if ok {
+ return ErrDupKey{key}
+ }
+ t.keys = slices.Insert(t.keys, i, key)
+ t.vals = slices.Insert(t.vals, i, val)
+
+ return nil
+}