dac

package module
v0.0.0-...-0dcc8a7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Dictionary with Directly Addressable Codes

Build Status Go Reference Go Report Card codecov

Directly Addressable Codes (DACs) consist of a variable-length encoding scheme for integers that enables direct access to any element of the encoded sequence and obtains compact spaces.

References

https://lbd.udc.es/research/DACS/

Documentation

Overview

Package dac implements a compressed dictionary for booleans, integers, dates, and floats of all sizes. Compression is obtained by application of variable byte codes. Direct access to any value is obtained through the utilization of Directly Addressable Codes (DACs). The integer data can be searched efficiently when sorted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Len

func Len(d *Dict) int

Len returns the actual number of entries in the dictionary.

Types

type Dict

type Dict struct {
	// contains filtered or unexported fields
}

Dict is a dictionary type that stores values in a "Directly Addressable Codes" structure. Data is compressed but still provides direct access to any value. Moreover, data can be searched efficiently when stored in sorted order.

func From

func From(values []uint64) *Dict

From constructs a dictionary from the given values. From automatically closes the dictionary for writing.

func New

func New(n ...int) (*Dict, error)

New constructs a dictionary with an initial capacity of n values. Setting the capacity is optional but recommended for performance reasons. The capacity gets automatically updated when needed.

func (*Dict) Close

func (d *Dict) Close()

Close builds support structures that improve the performance of direct reads. You should not do any direct reads before calling Close, as the read will crash. You can still write to the dictionary after a call to Close, but you will have to close the dictionary again before doing any direct reads.

func (*Dict) InsertU64At

func (d *Dict) InsertU64At(k int, v uint64) error

InsertU64At inserts a uint64 value at index k of the dictionary.

func (*Dict) Iter

func (d *Dict) Iter() Iterator

Iter creates an iterator for the dictionary.

func (*Dict) ReadBool

func (d *Dict) ReadBool(i int) (bool, error)

ReadBool reads a boolean value at a given index in the dictionary.

func (*Dict) ReadBoolList

func (d *Dict) ReadBoolList(values []bool) []bool

ReadBoolList returns all values in the dictionary when they are of boolean type. One can avoid the allocation of the return slice in ReadBoolList by supplying a slice of a size sufficient to store all values. Supplying a slice is optional.

func (*Dict) ReadDateTime

func (d *Dict) ReadDateTime(i int) (time.Time, error)

ReadDateTime reads a time.Time value at a given index in the dictionary. No timezone is read.

func (*Dict) ReadDateTimeList

func (d *Dict) ReadDateTimeList(dateTimes []time.Time) []time.Time

ReadDateTimeList returns all values in the dictionary when they are of time.Time type. One can avoid the allocation of the return slice in ReadDateTimeList by supplying a slice of a size sufficient to store all values. However, this is optional.

func (*Dict) ReadFloat32

func (d *Dict) ReadFloat32(i int) (float32, error)

ReadFloat32 reads a float32 value at a given index in the dictionary.

func (*Dict) ReadFloat32List

func (d *Dict) ReadFloat32List(values []float32) []float32

ReadFloat32List returns all values in the dictionary when they are of float32 type. One can avoid the allocation of the return slice in ReadFloat32List by supplying a slice of a size sufficient to store all values. However, this is optional.

func (*Dict) ReadFloat64

func (d *Dict) ReadFloat64(i int) (float64, error)

ReadFloat64 reads a float64 value at a given index in the dictionary.

func (*Dict) ReadFloat64List

func (d *Dict) ReadFloat64List(values []float64) []float64

ReadFloat64List returns all values in the dictionary when they are of float64 type. One can avoid the allocation of the return slice in ReadFloat64List by supplying a slice of a size sufficient to store all values. However, this is optional.

func (*Dict) ReadI16

func (d *Dict) ReadI16(i int) (int16, error)

ReadI16 reads an int16 value at a given index in the dictionary.

func (*Dict) ReadI16List

func (d *Dict) ReadI16List(values []int16) []int16

ReadI16List returns all values in the dictionary when they are of int16 type. One can avoid the allocation of the return slice in ReadI16List by supplying a slice of a size sufficient to store all values. Still, this is optional.

func (*Dict) ReadI32

func (d *Dict) ReadI32(i int) (int32, error)

ReadI32 reads an int32 value at a given index in the dictionary.

func (*Dict) ReadI32List

func (d *Dict) ReadI32List(values []int32) []int32

ReadI32List returns all values in the dictionary when they are of int32 type. One can avoid the allocation of the return slice in ReadI32List by supplying a slice of a size sufficient to store all values. Still, this is optional.

func (*Dict) ReadI64

func (d *Dict) ReadI64(i int) (int64, error)

ReadI64 reads an int64 value at a given index in the dictionary.

func (*Dict) ReadI64List

func (d *Dict) ReadI64List(values []int64) []int64

ReadI64List returns all values in the dictionary when they are of int64 type. One can avoid the allocation of the return slice in ReadI64List by supplying a slice of a size sufficient to store all values. Still, this is optional.

func (*Dict) ReadI8

func (d *Dict) ReadI8(i int) (int8, error)

ReadI8 reads an int8 value at a given index in the dictionary.

func (*Dict) ReadI8List

func (d *Dict) ReadI8List(values []int8) []int8

ReadI8List returns all values in the dictionary when they are of int8 type. One can avoid the allocation of the return slice in ReadI8List by supplying a slice of a size sufficient to store all values. Still, this is optional.

func (*Dict) ReadU16

func (d *Dict) ReadU16(k int) (v uint16, err error)

ReadU16 reads an uint16 value at a given index in the dictionary.

func (*Dict) ReadU16List

func (d *Dict) ReadU16List(values []uint16) []uint16

ReadU16List returns all values in the dictionary when they are of uint16 type. One can avoid the allocation of the return slice in ReadU16List by supplying a slice of a size sufficient to store all values. Supplying a slice is optional.

func (*Dict) ReadU32

func (d *Dict) ReadU32(k int) (v uint32, err error)

ReadU32 reads an uint32 value at a given index in the dictionary.

func (*Dict) ReadU32List

func (d *Dict) ReadU32List(values []uint32) []uint32

ReadU32List returns all values in the dictionary when they are of uint32 type. One can avoid the allocation of the return slice in ReadU32List by supplying a slice of a size sufficient to store all values. Supplying a slice is optional.

func (*Dict) ReadU64

func (d *Dict) ReadU64(k int) (v uint64, err error)

ReadU64 reads an uint64 value at a given index in the dictionary.

func (*Dict) ReadU64List

func (d *Dict) ReadU64List(values []uint64) []uint64

ReadU64List returns all values in the dictionary when they are of uint64 type. One can avoid the allocation of the return slice in ReadU64List by supplying a slice of a size sufficient to store all values. Supplying a slice is optional.

func (*Dict) ReadU8

func (d *Dict) ReadU8(i int) (uint8, error)

ReadU8 reads an uint8 value at a given index in the dictionary.

func (*Dict) ReadU8List

func (d *Dict) ReadU8List(values []uint8) []uint8

ReadU8List returns all values in the dictionary when they are of uint8 type. One can avoid the allocation of the return slice in ReadU8List by supplying a slice of a size sufficient to store all values. Supplying a slice is optional.

func (*Dict) RemoveAt

func (d *Dict) RemoveAt(k int) error

RemoveAt removes the k-th entry from the dictionary.

func (*Dict) Reset

func (d *Dict) Reset()

Reset resets the dictionary without releasing its resources. It allows to re-use an existing dictionary.

func (*Dict) Scan

func (d *Dict) Scan(value uint64) (idx int)

Scan returns the index of the first instance of the search value in the dictionary. If the value is not found, -1 is returned. When the values are sorted, Search is going to be faster than Scan.

func (*Dict) Search

func (d *Dict) Search(value uint64) (idx, l int)

Search returns the indexes in the dictionary of the searched value. If value is not found, an empty slice is returned. Search should only be used when the dictionary is sorted.

func (*Dict) UpdateU64At

func (d *Dict) UpdateU64At(k int, v uint64) error

UpdateU64At updates a uint64 value at index k of the dictionary.

func (*Dict) WriteBool

func (d *Dict) WriteBool(v bool) int

WriteBool writes a boolean value to the dictionary.

func (*Dict) WriteBoolList

func (d *Dict) WriteBoolList(values []bool)

WriteBoolList writes a slice of boolean values to the dictionary.

func (*Dict) WriteDateTime

func (d *Dict) WriteDateTime(t time.Time) int

WriteDateTime writes a time.Time value with nanosecond precision to the dictionary. Timezones are not written.

func (*Dict) WriteDateTimeList

func (d *Dict) WriteDateTimeList(dateTimes []time.Time)

WriteDateTimeList writes a slice of time.Time values to the dictionary.

func (*Dict) WriteFloat32

func (d *Dict) WriteFloat32(v float32) int

WriteFloat32 writes a float32 value to the dictionary.

func (*Dict) WriteFloat32List

func (d *Dict) WriteFloat32List(values []float32)

WriteFloat32List writes a slice of float values to the dictionary.

func (*Dict) WriteFloat64

func (d *Dict) WriteFloat64(v float64) int

WriteFloat64 writes a float64 value to the dictionary.

func (*Dict) WriteFloat64List

func (d *Dict) WriteFloat64List(values []float64)

WriteFloat64List writes a slice of float64 values to the dictionary.

func (*Dict) WriteI16

func (d *Dict) WriteI16(v int16) int

WriteI16 writes an int16 value to the dictionary.

func (*Dict) WriteI16List

func (d *Dict) WriteI16List(values []int16)

WriteI16List writes a slice of int16 values to the dictionary.

func (*Dict) WriteI32

func (d *Dict) WriteI32(v int32) int

WriteI32 writes an int32 value to the dictionary.

func (*Dict) WriteI32List

func (d *Dict) WriteI32List(values []int32)

WriteI32List writes a slice of int32 values to the dictionary.

func (*Dict) WriteI64

func (d *Dict) WriteI64(v int64) int

WriteI64 writes an int64 value to the dictionary.

func (*Dict) WriteI64List

func (d *Dict) WriteI64List(values []int64)

WriteI64List writes a slice of int64 values to the dictionary.

func (*Dict) WriteI8

func (d *Dict) WriteI8(v int8) int

WriteI8 writes an int8 value to the dictionary.

func (*Dict) WriteI8List

func (d *Dict) WriteI8List(values []int8)

WriteI8List writes a slice of int8 values to the dictionary.

func (*Dict) WriteU16

func (d *Dict) WriteU16(v uint16) int

WriteU16 writes a uint16 value to the dictionary.

func (*Dict) WriteU16List

func (d *Dict) WriteU16List(values []uint16)

WriteU16List writes a slice of uint16 values to the dictionary.

func (*Dict) WriteU32

func (d *Dict) WriteU32(v uint32) int

WriteU32 writes a uint32 value to the dictionary.

func (*Dict) WriteU32List

func (d *Dict) WriteU32List(values []uint32)

WriteU32List writes a slice of uint32 values to the dictionary.

func (*Dict) WriteU64

func (d *Dict) WriteU64(v uint64) int

WriteU64 writes a uint64 value at the end of the dictionary. A write index is returned.

func (*Dict) WriteU64List

func (d *Dict) WriteU64List(values []uint64)

WriteU64List writes a slice of uint64 values to the dictionary.

func (*Dict) WriteU8

func (d *Dict) WriteU8(v uint8) int

WriteU8 writes a uint8 value to the dictionary.

func (*Dict) WriteU8List

func (d *Dict) WriteU8List(values []uint8)

WriteU8List writes a slice of uint8 values to the dictionary.

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator enables iteration over the dictionary. Concurrent iteration is allowed once the dictionary is closed (no more writing).

func (*Iterator) Next

func (it *Iterator) Next() (k int, v uint64, ok bool)

Next returns the next index and value from the dictionary. If there is not a next value, the ok return value will be false.

func (*Iterator) Reset

func (it *Iterator) Reset()

Reset resets the iterator, without releasing its resources. After Reset, the iterator points again to the first element of the dictionary.

func (*Iterator) Value

func (it *Iterator) Value(k int) (v uint64, err error)

Value returns the k-th value from the dictionary. It also sets the iterator state, so that subsequent calls to Next will return the k+1, k+2, ... value.

Jump to

Keyboard shortcuts

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