Working data structure, optimal seed
This commit is contained in:
@@ -6,15 +6,15 @@ import (
|
||||
"github.com/icza/bitio"
|
||||
"github.com/samber/lo"
|
||||
"github.com/securemesh/coding/codes"
|
||||
"github.com/securemesh/coding/heap"
|
||||
"github.com/securemesh/coding/state"
|
||||
)
|
||||
|
||||
func Encode(h *heap.Heap, msg []byte) []byte {
|
||||
func Encode(st *state.State, msg []byte) []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
w := bitio.NewWriter(buf)
|
||||
|
||||
for _, b := range msg {
|
||||
index := h.IncrementSymbol(b)
|
||||
index := st.IncrementSymbol(b)
|
||||
code := codes.CodeForIndex(index)
|
||||
lo.Must0(w.WriteBits(uint64(code.Value), uint8(code.Bits)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user