pair

package module
v0.0.0-...-1140497 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2017 License: MIT Imports: 3 Imported by: 5

README

Pair

GoDoc

Pair is a Go package that provides a low memory key/value object that takes up one allocation. It's useful for in-memory key/value stores and data structures where memory space is a concern.

Data structure

The allocation is a single packed block of bytes with the following format:

ValueSize uint32 KeySize uint32 Value []byte Key []byte

Using

To start using Pair, install Go and run go get:

$ go get -u github.com/tidwall/pair

Create a new Pair:

item := pair.New([]byte("user:2054:name"), []byte("Alice Tripplehorn"))

Access the Pair data:

item.Key() []byte    // returns the key portion of the pair.
item.Value() []byte  // returns the value portion of the pair.
item.Size() int      // returns the exact in-memory size of the item.
item.Zero() bool     // returns true if the pair is unallocated.

Unsafe pointer access:

item.Pointer() unsafe.Pointer             // returns the base pointer
pair.FromPointer(ptr unsafe.Pointer) Pair // returns a Pair with provided base pointer

Contact

Josh Baker @tidwall

License

Pair source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

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

Pair is a tightly packed key/value pair

func FromPointer

func FromPointer(ptr unsafe.Pointer) Pair

FromPointer returns a pair that uses the memory at the pointer.

func New

func New(key, value []byte) Pair

New returns a Pair

func (Pair) Key

func (pair Pair) Key() []byte

Key returns the key portion of the key

func (Pair) Pointer

func (pair Pair) Pointer() unsafe.Pointer

Pointer returns the underlying pointer

func (Pair) Size

func (pair Pair) Size() int

Size returns the size of the allocation

func (Pair) Value

func (pair Pair) Value() []byte

Value returns the value

func (Pair) Zero

func (pair Pair) Zero() bool

Zero return true if the pair is unallocated

Jump to

Keyboard shortcuts

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