You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
749 B

7 years ago
  1. package compress
  2. import (
  3. "github.com/dataence/encoding/cursor"
  4. "github.com/dataence/encoding/delta/bp32"
  5. )
  6. // Compress compresses in[]int32 to out[]int32
  7. func Compress32(in []int32) (out []int32, err error) {
  8. out = make([]int32, len(in)*2)
  9. inpos := cursor.New()
  10. outpos := cursor.New()
  11. if err = bp32.New().Compress(in, inpos, len(in), out, outpos); err != nil {
  12. return nil, err
  13. }
  14. return out[:outpos.Get()], nil
  15. }
  16. // Uncompress uncompresses in[]int32 to out[]int32
  17. func Uncompress32(in []int32, buffer []int32) (out []int32, err error) {
  18. out = buffer
  19. inpos := cursor.New()
  20. outpos := cursor.New()
  21. if err = bp32.New().Uncompress(in, inpos, len(in), out, outpos); err != nil {
  22. return nil, err
  23. }
  24. return out[:outpos.Get()], nil
  25. }