indexcompression

package
v4.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Example (DecodeIndexList)
fmt.Println(DecodeIndexList([]int32{5}, 4))
fmt.Println(DecodeIndexList([]int32{5}, 5))
fmt.Println(DecodeIndexList([]int32{5}, 6))
fmt.Println(DecodeIndexList([]int32{}, 1))
fmt.Println(DecodeIndexList([]int32{1, 5, 7, 12, 4, 10, 14}, 50))
fmt.Println(DecodeIndexList([]int32{1, 5, -1, 8, 12, 4, 10, 14}, 50))
fmt.Println(DecodeIndexList([]int32{1, 5, -4, 8, 12, 4, 10, 14}, 50))
fmt.Println(DecodeIndexList([]int32{-1, 5, -1, 8, 12, 4, 10, 14}, 50))
fmt.Println(DecodeIndexList([]int32{1, 5, -1, 8, 12, 4, 10, 14, -1}, 50))
fmt.Println(DecodeIndexList([]int32{1, -1, 4, -1, 8}, 50))
fmt.Println(DecodeIndexList([]int32{1, -1, 4, 6, -1, 5}, 50))
fmt.Println(DecodeIndexList([]int32{1, -1, 4, 6, -1, 6}, 50))
fmt.Println(DecodeIndexList([]int32{1, -1, 4, 6, -1, 7}, 50))
fmt.Println(DecodeIndexList([]int32{1, -1, 4, 6, -1, 8}, 50))
// We don't ensure there are no repeats or they're in order...
fmt.Println(DecodeIndexList([]int32{1, -1, 4, 2, -1, 8, 11, 13, -1, 16}, 50))
// Check that expansion going past array size is found
fmt.Println(DecodeIndexList([]int32{1, -1, 12}, 10))
// And specified value going past
fmt.Println(DecodeIndexList([]int32{1, 3, 5, 12, 2}, 10))
// Verify arraySizeOptional is optional!
fmt.Println(DecodeIndexList([]int32{1, 3, 5, 12, 2}, -1))
Output:

[] index 5 out of bounds: 4
[] index 5 out of bounds: 5
[5] <nil>
[] <nil>
[1 5 7 12 4 10 14] <nil>
[1 5 6 7 8 12 4 10 14] <nil>
[] invalid index: -4
[] indexes start with -1
[] indexes end with -1
[1 2 3 4 5 6 7 8] <nil>
[] invalid range: 6->5
[] invalid range: 6->6
[] invalid range: 6->7
[1 2 3 4 6 7 8] <nil>
[1 2 3 4 2 3 4 5 6 7 8 11 13 14 15 16] <nil>
[] index 12 out of bounds: 10
[] index 12 out of bounds: 10
[1 3 5 12 2] <nil>
Example (EncodeIndexList)
fmt.Println(EncodeIndexList([]uint32{9, 22, 8}))
fmt.Println(EncodeIndexList([]uint32{9, 7, 9, 8}))
fmt.Println(EncodeIndexList([]uint32{9, 7, 8, 7}))
fmt.Println(EncodeIndexList([]uint32{9, 7, 8, 8}))
fmt.Println(EncodeIndexList([]uint32{1002, 14, 1005, 15, 1003, 1004, 13, 16}))
fmt.Println(EncodeIndexList([]uint32{7, 8}))
fmt.Println(EncodeIndexList([]uint32{9, 7, 8}))
fmt.Println(EncodeIndexList([]uint32{1, 3, 5, 12, 2}))
fmt.Println(EncodeIndexList([]uint32{}))
fmt.Println(EncodeIndexList([]uint32{7}))
fmt.Println(EncodeIndexList([]uint32{7, 8, 2, 9, 10, 11, 12, 14, 13, 16}))
fmt.Println(EncodeIndexList([]uint32{1002, 14, 1005, 15, 1003, 1004, 13, 1100, 16}))
fmt.Println(EncodeIndexList([]int32{1002, 14, 1005, 15, 1003, 1004, 13, 1100, 16}))
fmt.Println(EncodeIndexList([]uint32{9, math.MaxInt32, 8}))
fmt.Println(EncodeIndexList([]uint32{9, math.MaxInt32 + 1, 8}))
Output:

[8 9 22] <nil>
[7 -1 9] <nil>
[7 -1 9] <nil>
[7 -1 9] <nil>
[13 -1 16 1002 -1 1005] <nil>
[7 8] <nil>
[7 -1 9] <nil>
[1 -1 3 5 12] <nil>
[] <nil>
[7] <nil>
[2 7 -1 14 16] <nil>
[13 -1 16 1002 -1 1005 1100] <nil>
[13 -1 16 1002 -1 1005 1100] <nil>
[8 9 2147483647] <nil>
[] index list had value > maxint

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeIndexList

func DecodeIndexList(encodedIndexes []int32, arraySizeOptional int) ([]uint32, error)

Returns a list of unsigned indexes, and an error if: - A negative value is seen that is not -1 - <start idx>, -1, <end idx which is <= start idx>

func EncodeIndexList

func EncodeIndexList[T uint32 | int32](indexes []T) ([]int32, error)

Given a list of unsigned indexes, this SORTS them and encodes them such that runs of consecutive numbers like 4, 5, 6, 7 are replaced with the sequence 4, -1, 7 - thereby reducing storage size NOTE: even though it takes unsigned int32s, it cannot support values over maxint, it just takes unsigned to signify that an array index can't be negative

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL