good morning!!!!

Skip to content
Snippets Groups Projects
Commit 34d62c38 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke
Browse files

Encoding helpers for trie

parent 276fa6c7
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"strings" "strings"
_"fmt"
) )
func CompactEncode(hexSlice []int) string { func CompactEncode(hexSlice []int) string {
...@@ -32,6 +33,21 @@ func CompactEncode(hexSlice []int) string { ...@@ -32,6 +33,21 @@ func CompactEncode(hexSlice []int) string {
return buff.String() return buff.String()
} }
func CompactDecode(str string) []int {
base := CompactHexDecode(str)
base = base[:len(base)-1]
if base[0] >= 2 {// && base[len(base)-1] != 16 {
base = append(base, 16)
}
if base[0] % 2 == 1 {
base = base[1:]
} else {
base = base[2:]
}
return base
}
func CompactHexDecode(str string) []int { func CompactHexDecode(str string) []int {
base := "0123456789abcdef" base := "0123456789abcdef"
hexSlice := make([]int, 0) hexSlice := make([]int, 0)
......
...@@ -27,18 +27,6 @@ func TestCompactEncode(t *testing.T) { ...@@ -27,18 +27,6 @@ func TestCompactEncode(t *testing.T) {
} }
} }
// Helper function for comparing slices
func CompareIntSlice(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func TestCompactHexDecode(t *testing.T) { func TestCompactHexDecode(t *testing.T) {
exp := []int{7, 6, 6, 5, 7, 2, 6, 2, 16} exp := []int{7, 6, 6, 5, 7, 2, 6, 2, 16}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment