adt

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: Apache-2.0, MIT Imports: 18 Imported by: 79

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntKey

func IntKey(k int64) intKey

noinspection GoExportedFuncWithUnexportedType

func ParseIntKey

func ParseIntKey(k string) (int64, error)

noinspection GoUnusedExportedFunction

func ParseUIntKey

func ParseUIntKey(k string) (uint64, error)

func UIntKey

func UIntKey(k uint64) uintKey

noinspection GoExportedFuncWithUnexportedType

Types

type AddrKey

type AddrKey addr.Address

Adapts an address as a mapping key.

func (AddrKey) Key

func (k AddrKey) Key() string

type Array

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

Array stores a sparse sequence of values in an AMT.

func AsArray

func AsArray(s Store, r cid.Cid) (*Array, error)

AsArray interprets a store as an AMT-based array with root `r`.

func MakeEmptyArray

func MakeEmptyArray(s Store) *Array

Creates a new map backed by an empty HAMT and flushes it to the store.

func (*Array) AppendContinuous

func (a *Array) AppendContinuous(value runtime.CBORMarshaler) error

Appends a value to the end of the array. Assumes continuous array. If the array isn't continuous use Set and a separate counter

func (*Array) BatchDelete

func (a *Array) BatchDelete(ix []uint64) error

func (*Array) Delete

func (a *Array) Delete(i uint64) error

func (*Array) ForEach

func (a *Array) ForEach(out runtime.CBORUnmarshaler, fn func(i int64) error) error

Iterates all entries in the array, deserializing each value in turn into `out` and then calling a function. Iteration halts if the function returns an error. If the output parameter is nil, deserialization is skipped.

func (*Array) Get

func (a *Array) Get(k uint64, out runtime.CBORUnmarshaler) (bool, error)

Get retrieves array element into the 'out' unmarshaler, returning a boolean

indicating whether the element was found in the array

func (*Array) Length

func (a *Array) Length() uint64

func (*Array) Root

func (a *Array) Root() (cid.Cid, error)

Returns the root CID of the underlying AMT.

func (*Array) Set

func (a *Array) Set(i uint64, value runtime.CBORMarshaler) error

type BalanceTable

type BalanceTable Map

A specialization of a map of addresses to token amounts.

func AsBalanceTable

func AsBalanceTable(s Store, r cid.Cid) (*BalanceTable, error)

Interprets a store as balance table with root `r`.

func (*BalanceTable) Add

func (t *BalanceTable) Add(key addr.Address, value abi.TokenAmount) error

Adds an amount to a balance. The entry must have been previously initialized.

func (*BalanceTable) AddCreate

func (t *BalanceTable) AddCreate(key addr.Address, value abi.TokenAmount) error

Adds an amount to a balance. Create entry if not exists

func (*BalanceTable) Get

func (t *BalanceTable) Get(key addr.Address) (abi.TokenAmount, error)

Gets the balance for a key. The entry must have been previously initialized.

func (*BalanceTable) Has

func (t *BalanceTable) Has(key addr.Address) (bool, error)

Has checks if the balance for a key exists

func (*BalanceTable) MustSubtract

func (t *BalanceTable) MustSubtract(key addr.Address, req abi.TokenAmount) error

func (*BalanceTable) Remove

func (t *BalanceTable) Remove(key addr.Address) (abi.TokenAmount, error)

Removes an entry from the table, returning the prior value. The entry must have been previously initialized.

func (*BalanceTable) Root

func (t *BalanceTable) Root() (cid.Cid, error)

Returns the root cid of underlying HAMT.

func (*BalanceTable) Set

func (t *BalanceTable) Set(key addr.Address, value abi.TokenAmount) error

Sets the balance for an address, overwriting any previous balance.

func (*BalanceTable) SubtractWithMinimum

func (t *BalanceTable) SubtractWithMinimum(key addr.Address, req abi.TokenAmount, floor abi.TokenAmount) (abi.TokenAmount, error)

Subtracts up to the specified amount from a balance, without reducing the balance below some minimum. Returns the amount subtracted (always positive or zero).

func (*BalanceTable) Total

func (t *BalanceTable) Total() (abi.TokenAmount, error)

Returns the total balance held by this BalanceTable

type EmptyValue

type EmptyValue struct{}

The empty value represents absence of a value. It is used for parameter and return types for actor methods that don't take/return any data. This saves a byte in serialization of messages and receipts: the serialized form is an empty byte slice, rather than a byte slice containing a single byte CBOR encoding of nil/empty/etc.

The only expected use of this is as the type of a nil reference. Don't instantiate this type.

This is primarily necessary due to Go's lack of a void type and our interface-based serialization scheme.

var Empty *EmptyValue = nil

A typed nil pointer to EmptyValue.

func (*EmptyValue) MarshalCBOR

func (v *EmptyValue) MarshalCBOR(_ io.Writer) error

func (*EmptyValue) UnmarshalCBOR

func (v *EmptyValue) UnmarshalCBOR(_ io.Reader) error

type ErrNotFound

type ErrNotFound struct {
	Root cid.Cid
	Key  interface{}
}

Error type returned when an expected key is absent.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Keyer

type Keyer interface {
	Key() string
}

Keyer defines an interface required to put values in mapping.

type Map

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

Map stores key-value pairs in a HAMT.

func AsMap

func AsMap(s Store, r cid.Cid) (*Map, error)

AsMap interprets a store as a HAMT-based map with root `r`.

func MakeEmptyMap

func MakeEmptyMap(s Store) *Map

Creates a new map backed by an empty HAMT and flushes it to the store.

func (*Map) CollectKeys

func (m *Map) CollectKeys() (out []string, err error)

Collects all the keys from the map into a slice of strings.

func (*Map) Delete

func (m *Map) Delete(k Keyer) error

Delete removes the value at `k` from the hamt store.

func (*Map) ForEach

func (m *Map) ForEach(out runtime.CBORUnmarshaler, fn func(key string) error) error

Iterates all entries in the map, deserializing each value in turn into `out` and then calling a function with the corresponding key. Iteration halts if the function returns an error. If the output parameter is nil, deserialization is skipped.

func (*Map) Get

func (m *Map) Get(k Keyer, out runtime.CBORUnmarshaler) (bool, error)

Get puts the value at `k` into `out`.

func (*Map) Put

func (m *Map) Put(k Keyer, v runtime.CBORMarshaler) error

Put adds value `v` with key `k` to the hamt store.

func (*Map) Root

func (m *Map) Root() (cid.Cid, error)

Returns the root cid of underlying HAMT.

type Multimap

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

Multimap stores multiple values per key in a HAMT of AMTs. The order of insertion of values for each key is retained.

func AsMultimap

func AsMultimap(s Store, r cid.Cid) (*Multimap, error)

Interprets a store as a HAMT-based map of AMTs with root `r`.

func MakeEmptyMultimap

func MakeEmptyMultimap(s Store) *Multimap

Creates a new map backed by an empty HAMT and flushes it to the store.

func (*Multimap) Add

func (mm *Multimap) Add(key Keyer, value runtime.CBORMarshaler) error

Adds a value for a key.

func (*Multimap) ForEach

func (mm *Multimap) ForEach(key Keyer, out runtime.CBORUnmarshaler, fn func(i int64) error) error

Iterates all entries for a key in the order they were inserted, deserializing each value in turn into `out` and then calling a function. Iteration halts if the function returns an error. If the output parameter is nil, deserialization is skipped.

func (*Multimap) Get

func (mm *Multimap) Get(key Keyer) (*Array, bool, error)

func (*Multimap) RemoveAll

func (mm *Multimap) RemoveAll(key Keyer) error

Removes all values for a key.

func (*Multimap) Root

func (mm *Multimap) Root() (cid.Cid, error)

Returns the root cid of the underlying HAMT.

type Set

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

Set interprets a Map as a set, storing keys (with empty values) in a HAMT.

func AsSet

func AsSet(s Store, r cid.Cid) (*Set, error)

AsSet interprets a store as a HAMT-based set with root `r`.

func MakeEmptySet

func MakeEmptySet(s Store) *Set

NewSet creates a new HAMT with root `r` and store `s`.

func (*Set) CollectKeys

func (h *Set) CollectKeys() (out []string, err error)

Collects all the keys from the set into a slice of strings.

func (*Set) Delete

func (h *Set) Delete(k Keyer) error

Delete removes `k` from the set.

func (*Set) ForEach

func (h *Set) ForEach(cb func(k string) error) error

ForEach iterates over all values in the set, calling the callback for each value. Returning error from the callback stops the iteration.

func (*Set) Has

func (h *Set) Has(k Keyer) (bool, error)

Has returns true iff `k` is in the set.

func (*Set) Put

func (h *Set) Put(k Keyer) error

Put adds `k` to the set.

func (*Set) Root

func (h *Set) Root() (cid.Cid, error)

Root return the root cid of HAMT.

type Store

type Store interface {
	Context() context.Context
	cbor.IpldStore
}

Store defines an interface required to back the ADTs in this package.

func AsStore

func AsStore(rt vmr.Runtime) Store

Adapts a Runtime as an ADT store.

func WrapStore

func WrapStore(ctx context.Context, store cbor.IpldStore) Store

Adapts a vanilla IPLD store as an ADT store.

Jump to

Keyboard shortcuts

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