Documentation
¶
Overview ¶
package compints provides useful wrapper for nelz9999's StreamVByte algorithm.
Input is just slice of uint32. Slice size is flexible.
There are two pairs of functions grouped by output data:
- Compress/Decompress: returns compressed data, control bytes, element count
- CompressToBytes/DecompressFromBytes: returns just []byte
If just serialize the result, CompressToBytes/DecompressFromBytes are useful.
If you stores the value into block devices and keeps flexibility to modify, Compress/Decompress allow you to implement more efficient code.
Both functions has mode "diff". If diff==true, my code assumes input data is sorted ascendant order.
Index ¶
- func Compress(input []uint32, diff bool) (output, cbytes []byte, elementCount int)
- func CompressToBytes(input []uint32, diff bool) []byte
- func Decompress(input, cbytes []byte, elementCount int, diff bool) (output []uint32, err error)
- func DecompressFromBytes(input []byte, diff bool) ([]uint32, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
Compress receives []uint32 slice and compress into compress data, control bytes, element count.
These three output are required by Decompress.
If you needs more simple method, use CompressToBytes.
Example ¶
package main
import (
"fmt"
"github.com/shibukawa/compints"
"reflect"
)
var input = []uint32{1, 2, 3, 4, 5, 6, 6, 8, 10}
func main() {
compressed, cbytes, length := compints.Compress(input, true)
output, err := compints.Decompress(compressed, cbytes, length, true)
fmt.Printf("equal: %v\n", reflect.DeepEqual(input, output))
fmt.Printf("error: %v\n", err)
}
Output: equal: true error: <nil>
func CompressToBytes ¶
CompressToBytes receives []uint32 slice and compress into []byte.
Example ¶
package main
import (
"fmt"
"github.com/shibukawa/compints"
"reflect"
)
var input = []uint32{1, 2, 3, 4, 5, 6, 6, 8, 10}
func main() {
compressed := compints.CompressToBytes(input, false)
output, err := compints.DecompressFromBytes(compressed, false)
fmt.Printf("equal: %v\n", reflect.DeepEqual(input, output))
fmt.Printf("error: %v\n", err)
}
Output: equal: true error: <nil>
func Decompress ¶
Decompress consumes the result of Compress and returns original []uint32 slice.
Types ¶
This section is empty.