Split out heap

This commit is contained in:
Ian Gulliver
2023-12-24 18:03:29 -05:00
parent e8117edf01
commit 0d95420bdf
3 changed files with 11 additions and 5 deletions

View File

@@ -2,11 +2,13 @@ package coding
import ( import (
"bytes" "bytes"
"github.com/icza/bitio" "github.com/icza/bitio"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/securemesh/coding/heap"
) )
func Encode(h *Heap, msg []byte) []byte { func Encode(h *heap.Heap, msg []byte) []byte {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
w := bitio.NewWriter(buf) w := bitio.NewWriter(buf)

View File

@@ -1,4 +1,4 @@
package coding package heap
import ( import (
"maps" "maps"

View File

@@ -1,5 +1,9 @@
package coding package coding
import (
"github.com/securemesh/coding/heap"
)
var chatHeap = newHeapFromSeed([][]byte{ var chatHeap = newHeapFromSeed([][]byte{
[]byte(`]\_}`), []byte(`]\_}`),
[]byte(`[ê%=Z`), []byte(`[ê%=Z`),
@@ -18,12 +22,12 @@ var chatHeap = newHeapFromSeed([][]byte{
[]byte(` `), []byte(` `),
}) })
func ChatHeap() *Heap { func ChatHeap() *heap.Heap {
return chatHeap.Clone() return chatHeap.Clone()
} }
func newHeapFromSeed(seed [][]byte) *Heap { func newHeapFromSeed(seed [][]byte) *heap.Heap {
h := NewHeap() h := heap.NewHeap()
for i := range seed { for i := range seed {
for _, s := range seed[i:] { for _, s := range seed[i:] {