2020-01-31 04:11:20 +00:00
|
|
|
package trie
|
|
|
|
|
|
|
|
// CompressNibbles - supports only even number of nibbles
|
2020-03-11 10:31:49 +00:00
|
|
|
// This method supports only arrays of even nibbles
|
2020-01-31 04:11:20 +00:00
|
|
|
//
|
|
|
|
// HI_NIBBLE(b) = (b >> 4) & 0x0F
|
|
|
|
// LO_NIBBLE(b) = b & 0x0F
|
2020-02-12 13:52:59 +00:00
|
|
|
func CompressNibbles(nibbles []byte, out *[]byte) {
|
2020-01-31 04:11:20 +00:00
|
|
|
tmp := (*out)[:0]
|
|
|
|
for i := 0; i < len(nibbles); i += 2 {
|
|
|
|
tmp = append(tmp, nibbles[i]<<4|nibbles[i+1])
|
|
|
|
}
|
|
|
|
*out = tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecompressNibbles - supports only even number of nibbles
|
|
|
|
//
|
|
|
|
// HI_NIBBLE(b) = (b >> 4) & 0x0F
|
|
|
|
// LO_NIBBLE(b) = b & 0x0F
|
2020-02-12 13:52:59 +00:00
|
|
|
func DecompressNibbles(in []byte, out *[]byte) {
|
2020-01-31 04:11:20 +00:00
|
|
|
tmp := (*out)[:0]
|
|
|
|
for i := 0; i < len(in); i++ {
|
2020-02-12 13:52:59 +00:00
|
|
|
tmp = append(tmp, (in[i]>>4)&0x0F, in[i]&0x0F)
|
2020-01-31 04:11:20 +00:00
|
|
|
}
|
|
|
|
*out = tmp
|
|
|
|
}
|