immut

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

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

Go to latest
Published: May 10, 2016 License: MIT Imports: 6 Imported by: 0

README

immut

A collection of immutable/persistent data structures for use in go programs

Documentation

Index

Constants

View Source
const (
	Int = iota

	UInt
	Float
	String
)

Variables

View Source
var (
	IndexOutOfRange = errors.New("index out of range")
)

Functions

This section is empty.

Types

type Byteser

type Byteser interface {
	Bytes() []byte
}

Byteser returns the []bytes representation of the type. Note this does not need to be able to be decoded, just needs to be a unique identifier for the value.

type Entry

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

A TNodeKey stores both the hashed value and the key that created the value

type HashMap

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

HashMap maps anything to anything using the immutible trie type

func NewHashMap

func NewHashMap() *HashMap

NewHashMap

func (*HashMap) Del

func (h *HashMap) Del(k interface{}) (*HashMap, interface{})

Del deletes the value stored at the given key

func (*HashMap) Each

func (h *HashMap) Each(f func(k, v interface{}))

Each funs a function on each k,v pair

func (*HashMap) Get

func (h *HashMap) Get(k interface{}) (interface{}, bool)

Get returns the value stored at the given key if it exists else nil, false

func (*HashMap) Keys

func (h *HashMap) Keys() []interface{}

Keys returns the keys stored in the hash map

func (*HashMap) Put

func (h *HashMap) Put(k, v interface{}) *HashMap

Put will map anything to anything in the internal trie

func (*HashMap) Values

func (h *HashMap) Values() []interface{}

Values returns the values stored in the has map

type IntHashMap

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

IntHashMap maps an int to anything using an immutable trie

func (*IntHashMap) Get

func (i *IntHashMap) Get(k int) (interface{}, bool)

Get the value stored at the given key

func (*IntHashMap) Put

func (i *IntHashMap) Put(k int64, v interface{}) *IntHashMap

Put a kv pair into the map

type List

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

A List is an immutable singly linked list that is safe for concurrent use

func NewList

func NewList(val interface{}) *List

NewList creates and returns an new list with the given value at the first node

func (*List) Append

func (l *List) Append(val interface{}) *List

Append the given value to the end of the list. This will reallocate the whole list

func (*List) Each

func (l *List) Each(f func(i interface{}))

func (*List) End

func (l *List) End() bool

End returns true if this is the end of the list

func (*List) Filter

func (l *List) Filter(f func(*List) bool) *List

func (*List) Index

func (l *List) Index(i int) (interface{}, error)

Index returns the value stored at the given index if it exists

func (*List) Len

func (l *List) Len() int

Len returns the length of the list

func (*List) Next

func (l *List) Next() *List

Next returns the next node in the list

func (*List) Prepend

func (l *List) Prepend(val interface{}) *List

Prepend the given value onto a new list

func (*List) String

func (l *List) String() string

String returns a string representation of the list

func (*List) Val

func (l *List) Val() interface{}

Val returns the value stored at the current node in the list

type TNode

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

func NewTNode

func NewTNode(parent *TNode, vals []Entry) *TNode

NewTNode creates and returns a new *TNode

func (*TNode) Del

func (t *TNode) Del(key []byte) (*TNode, interface{}, bool)

Del remove the value stored at the given key, returns the value if it existed

func (*TNode) Each

func (t *TNode) Each(f func([]byte, interface{}))

Each runs a function over all k,v pairs in the node and it's children

func (*TNode) Get

func (t *TNode) Get(key []byte) (interface{}, bool)

Get a value from the TNode if it exists and (nil, false) if it doesn't

func (*TNode) Put

func (t *TNode) Put(key []byte, val interface{}) *TNode

Put inserts a key, val pair into the TNode

func (*TNode) String

func (t *TNode) String() string

String returns the string representation of the TNode

type Trie

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

A Trie is an immutible implementation of of trie Inspired by Rich Hickey's implementation in clojure. Read about it at http://hypirion.com/musings/understanding-persistent-vector-pt-2

func NewTrie

func NewTrie() *Trie

NewTrie creates an empty Trie and returns it

func (*Trie) Del

func (t *Trie) Del(key []byte) (*Trie, interface{})

Del remove the value stored at the given key and return the value that was stored there

func (*Trie) Each

func (t *Trie) Each(f func([]byte, interface{}))

Each runs the given function on every k,v pair

func (*Trie) Get

func (t *Trie) Get(key []byte) (interface{}, bool)

Get returns the value stored at the given key

func (*Trie) Keys

func (t *Trie) Keys() [][]byte

Keys returns all of the keys stored in the trie

func (*Trie) Put

func (t *Trie) Put(key []byte, val interface{}) *Trie

Put inserts the given value at the given key

func (*Trie) Size

func (t *Trie) Size() int

Size returns the number of keys/vals in the trie

func (*Trie) Values

func (t *Trie) Values() []interface{}

Values returns all fo the values stored in the trie

type UintHashMap

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

UintHashMap maps an int to anything using an immutable trie

func NewUintHashMap

func NewUintHashMap() *UintHashMap

func (*UintHashMap) Get

func (i *UintHashMap) Get(k uint64) (interface{}, bool)

Get the value stored at the given key

func (*UintHashMap) Put

func (i *UintHashMap) Put(k uint64, v interface{}) *UintHashMap

Put a kv pair into the map

type Vector

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

Vector is a constant time lookup with constand time appending and linier prepending

func NewVector

func NewVector() *Vector

NewVector returns a new empty vector

func (*Vector) Get

func (v *Vector) Get(index int) (interface{}, bool)

Get the value at the givne index

func (*Vector) Put

func (v *Vector) Put(index int, val interface{}) *Vector

Put the given value at the given index

func (*Vector) Size

func (v *Vector) Size() int

Size returns the number of elements in the vector

func (*Vector) Slice

func (v *Vector) Slice(start, end int) *Vector

Slice returns a subslice of the vector. same as the built in slice operations mySlice[1:10]

Jump to

Keyboard shortcuts

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