blade

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

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Go Blade

Build Status

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NIL = "00000000-0000-0000-0000-000000000000"

NIL UUID

Functions

func Addr

func Addr() *net.TCPAddr

Addr returns an available addr.

func CauseBy

func CauseBy(err error) error

CauseBy ...

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf ...

func Eth0

func Eth0() *net.Interface

Eth0 returns eth0 network

func Fail

func Fail(t T, args ...interface{})

Fail reports a failure through

func FailNow

func FailNow(t T, args ...interface{})

FailNow fails test

func IPv4

func IPv4() net.IP

IPv4 returns a valid ip

func Interface

func Interface() *net.Interface

Interface returns a valid interface.

func Interfaces

func Interfaces() []net.Interface

Interfaces returns all net interfaces.

func Join

func Join(slice Slice, sep string) string

Join joins the slice with the sep.

func MurmurHash

func MurmurHash(b []byte) uint32

MurmurHash implements a hashing algorithm similar to the Murmur hash.

func Parse

func Parse(v url.Values, obj interface{}) error

Parse parses the given object into url.Values.

func Port

func Port() int

Port returns an available port.

Types

type Assertion

type Assertion interface {
	IsNil()
	IsEmpty()
	IsNotNil()
	IsNotEmpty()
	IsTrue()
	IsFalse()
	IsEqualTo(expect interface{})
	IsNotEqualTo(expect interface{})
	IsDeepEqualTo(expect interface{})
	IsNotDeepEqualTo(expect interface{})
}

Assertion is the interface for all comparisons.

func AssertThat

func AssertThat(t T, actual interface{}) Assertion

AssertThat returns an assertion.

type Bloom

type Bloom []byte

Bloom is the thin wrapper around a byte slice.

func NewBloom

func NewBloom(numberOfKeys, bitsPerKey int) Bloom

NewBloom creates a new Bloom filter with the given number of the keys and the number of bits per key, approximately.

The number of the keys and the number of bits per key are used to predict the number of the bits in the array and hash functions needed.

func (Bloom) Append

func (b Bloom) Append(key []byte)

Append appends a key into the filter.

func (Bloom) Maybe

func (b Bloom) Maybe(key []byte) bool

Maybe returns whether the filter may contains the given key. It returns false if the filter does not contain the given key.

type Element

type Element struct {
	V interface{}
	// contains filtered or unexported fields
}

Element is one holder in the list.

func (*Element) After

func (e *Element) After(mark *Element)

After moves the e after the mark element of the list.

func (*Element) Before

func (e *Element) Before(mark *Element)

Before moves the e before the mark element of the list.

func (*Element) ToBack

func (e *Element) ToBack()

ToBack moves the e to the back of the list.

func (*Element) ToFront

func (e *Element) ToFront()

ToFront moves the e to the front of list.

type Helper

type Helper interface {
	Helper()
}

Helper marks the calling function as a test helper function.

type Iterator

type Iterator interface {
	Next() bool
	Value() interface{}
	Reverse()
}

Iterator is used to traversing the elements of the list.

type LRU

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

LRU implements a non-thread safe fixed size LRU cache

func NewLRU

func NewLRU(size int, onEvict func(k, v interface{})) *LRU

NewLRU returns a new lru cache.

func (*LRU) Add

func (l *LRU) Add(k, v interface{}) (old interface{}, evict bool)

Add adds the k/v pair and returns the old value associated with the given key. It also returns true if the eviction occured.

func (*LRU) Exist

func (l *LRU) Exist(k interface{}) (ok bool)

Exist checks whether the given is not exist in the cache.

func (*LRU) Get

func (l *LRU) Get(k interface{}) (v interface{}, exist bool)

Get returns the value associated with the given key. Returns false if the given is not exist.

func (*LRU) GetOldest

func (l *LRU) GetOldest() (k, v interface{}, exist bool)

GetOldest returns oldest k/v pair.

func (*LRU) Len

func (l *LRU) Len() int

Len returns the length.

func (*LRU) Peek

func (l *LRU) Peek(k interface{}) (v interface{}, exist bool)

Peek returns the value associated with the given key. Returns false if the given is not exist. But the Peek didn't update the visit(recently used).

func (*LRU) Remove

func (l *LRU) Remove(k interface{}) (v interface{}, exist bool)

Remove removes the k/v pair from the cache.

func (*LRU) RemoveOldest

func (l *LRU) RemoveOldest() (k, v interface{}, exist bool)

RemoveOldest removes oldest k/v pair.

func (*LRU) Walk

func (l *LRU) Walk(f func(k, v interface{}))

Walk scans all k/v pair.

type List

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

List is a circular doubly-linked list.

This is a figure of 2-elements list:

Front Back

+------+ next +-----+ next +-----+ next +-----+ | dummy| <----> |node1| <----> |node2| <----> |dummy| +------+ prev +-----+ prev +-----+ prev +-----+

 ^                                    ^
 |                                    |
push                                 insert

func NewList

func NewList() *List

NewList returns an initialized list.

func (*List) Back

func (l *List) Back() *Element

Back returns the last element of list l or nil if the list is empty.

func (*List) Front

func (l *List) Front() *Element

Front returns the first element of list l or nil if the list is empty.

func (*List) Insert

func (l *List) Insert(v interface{}) (e *Element)

Insert inserts the v before the dummy element.

func (*List) Iterator

func (l *List) Iterator() Iterator

Iterator returns a Iterator for traversing the elements of the list from front to back.

func (*List) Len

func (l *List) Len() int

Len returns the number of the elements in the list.

func (*List) Push

func (l *List) Push(v interface{}) (e *Element)

Push inserts the v after the dummy element.

func (*List) Remove

func (l *List) Remove(e *Element)

Remove removes e from the list. e must be the element of the list.

type RadixNode

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

RadixNode is the note in radix tree.

func (*RadixNode) Clone

func (n *RadixNode) Clone() *RadixNode

Clone returns a deep copy of the current node.

func (*RadixNode) Get

func (n *RadixNode) Get(k []byte) (v interface{}, ok bool)

Get returns the value associated with the given key if the key is exist, otherwise false.

func (*RadixNode) IsLeaf

func (n *RadixNode) IsLeaf() bool

IsLeaf returns true if the node is leaf.

func (*RadixNode) Walk

func (n *RadixNode) Walk(fn func(k []byte, v interface{}) bool)

Walk is used to walk the tree. Stopped when the fn returns true.

func (*RadixNode) WalkPath

func (n *RadixNode) WalkPath(path []byte, fn func(k []byte, v interface{}) bool)

WalkPath is used to walk the tree, but only visiting nodes from the root down to a given leaf. Stopped when the fn returns true.

func (*RadixNode) WalkPrefix

func (n *RadixNode) WalkPrefix(prefix []byte, fn func(k []byte, v interface{}) bool)

WalkPrefix is used to walk the tree underlying the prefix. Stopped when the fn returns true.

type RadixTXN

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

RadixTXN is a transaction of the RadixDB.

func (*RadixTXN) Commit

func (t *RadixTXN) Commit() *RadixTree

Commit finalizes the transaction and returns a new tree.

func (*RadixTXN) Delete

func (t *RadixTXN) Delete(k []byte) (old interface{})

Delete deletes the k/v pair from the tree.

func (*RadixTXN) DeletePrefix

func (t *RadixTXN) DeletePrefix(prefix []byte) int

DeletePrefix deletes the k/v pair whose key is started with the given prefix.

func (*RadixTXN) Get

func (t *RadixTXN) Get(k []byte) (interface{}, bool)

Get returns the value associated with the given key if the key is exist, otherwise false.

func (*RadixTXN) Insert

func (t *RadixTXN) Insert(k []byte, v interface{}) (old interface{})

Insert inserts the k/v pair into the tree and returns the old value associated with the given key if it exists.

func (*RadixTXN) MemOptimized

func (t *RadixTXN) MemOptimized()

MemOptimized will create a cache for reusing the node's clone.

func (*RadixTXN) Rollback

func (t *RadixTXN) Rollback() *RadixTree

Rollback finalizes the transaction and returns the old tree.

type RadixTree

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

RadixTree implements an immutable radix tree and is immutable.

func NewRadixTree

func NewRadixTree() *RadixTree

NewRadixTree creates a new RadixTree.

func (*RadixTree) Get

func (t *RadixTree) Get(k []byte) (interface{}, bool)

Get returns the value associated with the given key if the key is exist, otherwise false.

func (*RadixTree) OpenTXN

func (t *RadixTree) OpenTXN() *RadixTXN

OpenTXN returns a new transaction for inserting or deleting the tree node.

func (*RadixTree) Root

func (t *RadixTree) Root() *RadixNode

Root returns the root of this radix tree.

func (*RadixTree) Size

func (t *RadixTree) Size() int

Size returns the size of the tree.

func (*RadixTree) Walk

func (t *RadixTree) Walk(fn func(k []byte, v interface{}) bool)

Walk calls node.Walk.

func (*RadixTree) WalkPath

func (t *RadixTree) WalkPath(path []byte, fn func(k []byte, v interface{}) bool)

WalkPath calls node.WalkPath.

func (*RadixTree) WalkPrefix

func (t *RadixTree) WalkPrefix(prefix []byte, fn func(k []byte, v interface{}) bool)

WalkPrefix calls node.WalkPrefix.

type SkipList

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

SkipList is a Skip List.

This is a picture of the 2 level skip list(height is 3):

Head Tail +-+ +-+ +-+ | |---------------->|D|--------------------->|I|------------>nil h3/ level2 +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | |----------->|C|->|D|------>|F|----------->|I|------>|K|-->nil h2/level 1 +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | |->|A|->|B|->|C|->|D|->|E|->|F|->|G|->|H|->|I|->|J|->|K|-->nil h1/level 0 +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+

func NewSkipList

func NewSkipList(compare func(v1, v2 interface{}) int) *SkipList

NewSkipList return an initialized Skip Skiplist.

func (*SkipList) Add

func (l *SkipList) Add(v interface{})

Add inserts the v into the Skiplist.

func (*SkipList) Clear

func (l *SkipList) Clear()

Clear clears the SKip.

func (*SkipList) Exist

func (l *SkipList) Exist(v interface{}) (ok bool)

Exist returns true if the v is in the skiplist, it means there is a v1 in the skiplist is equal to the v (0 == compare(v, v1)).

func (*SkipList) Find

func (l *SkipList) Find(v interface{}) Iterator

Find returns an iterator positioned before the first v which is 'greater than or equal to the given v. There may be no such value, in which case the iterator will return false on Next.

func (*SkipList) Len

func (l *SkipList) Len() int

Len returns the number of the nodes in the Skiplist.

func (*SkipList) Remove

func (l *SkipList) Remove(v interface{})

Remove removes the node of which the v is equal to the specified v.

type Slice

type Slice interface {
	// StringAt returns the value at given position.
	StringAt(i int) string

	// Len returns the length of slice.
	Len() int
}

Slice indicates the object is a slice or array.

type Stack

type Stack []*StackRecord

Stack is error traced info.

func NewStack

func NewStack(skip int, depth int) Stack

NewStack returns Stack instance.

func (Stack) PrintGracefully

func (s Stack) PrintGracefully(indent int, numno bool) string

PrintGracefully returns string with indent.

func (Stack) String

func (s Stack) String() string

String returns the formatted string for the stack.

type StackRecord

type StackRecord struct {
	Name string
	File string
	Line int
}

StackRecord records the context where error comes from.

func Caller

func Caller(skip int) (r StackRecord, ok bool)

Caller returns the context where this function was called.

type T

type T interface {
	Fail()
	FailNow()
	Log(v ...interface{})
}

T is a interface of the testing.T.

type UUID

type UUID [16]byte

UUID - unique identifier type representing a 128 bit number

func UUID1

func UUID1() UUID

UUID1 generates a new time based UUID (version 1) as described in RFC 4122. This UUID contains the MAC address of the node that generated the UUID, the given timestamp and a sequence number.

func (UUID) String

func (u UUID) String() string

String returns the UUID in it's canonical form, a 32 digit hexadecimal number in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Jump to

Keyboard shortcuts

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