Split out codes

This commit is contained in:
Ian Gulliver
2023-12-29 12:52:34 -08:00
parent 77fc700dc9
commit cb38c7581c
3 changed files with 272 additions and 267 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/icza/bitio"
"github.com/samber/lo"
"github.com/securemesh/coding/codes"
"github.com/securemesh/coding/heap"
)
@@ -14,8 +15,8 @@ func Encode(h *heap.Heap, msg []byte) []byte {
for _, b := range msg {
index := h.IncrementSymbol(b)
code := codes[index]
lo.Must0(w.WriteBits(uint64(code.value), uint8(code.bits)))
code := codes.CodeForIndex(index)
lo.Must0(w.WriteBits(uint64(code.Value), uint8(code.Bits)))
}
lo.Must0(w.Close())