repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
Workiva/go-datastructures
slice/skip/node.go
newNode
func newNode(cmp common.Comparator, maxLevels uint8) *node { return &node{ entry: cmp, forward: make(nodes, maxLevels), widths: make(widths, maxLevels), } }
go
func newNode(cmp common.Comparator, maxLevels uint8) *node { return &node{ entry: cmp, forward: make(nodes, maxLevels), widths: make(widths, maxLevels), } }
[ "func", "newNode", "(", "cmp", "common", ".", "Comparator", ",", "maxLevels", "uint8", ")", "*", "node", "{", "return", "&", "node", "{", "entry", ":", "cmp", ",", "forward", ":", "make", "(", "nodes", ",", "maxLevels", ")", ",", "widths", ":", "make...
// newNode will allocate and return a new node with the entry // provided. maxLevels will determine the length of the forward // pointer list associated with this node.
[ "newNode", "will", "allocate", "and", "return", "a", "new", "node", "with", "the", "entry", "provided", ".", "maxLevels", "will", "determine", "the", "length", "of", "the", "forward", "pointer", "list", "associated", "with", "this", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/node.go#L44-L50
train
Workiva/go-datastructures
futures/futures.go
GetResult
func (f *Future) GetResult() (interface{}, error) { f.lock.Lock() if f.triggered { f.lock.Unlock() return f.item, f.err } f.lock.Unlock() f.wg.Wait() return f.item, f.err }
go
func (f *Future) GetResult() (interface{}, error) { f.lock.Lock() if f.triggered { f.lock.Unlock() return f.item, f.err } f.lock.Unlock() f.wg.Wait() return f.item, f.err }
[ "func", "(", "f", "*", "Future", ")", "GetResult", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "if", "f", ".", "triggered", "{", "f", ".", "lock", ".", "Unlock", "(", ")", "\n",...
// GetResult will immediately fetch the result if it exists // or wait on the result until it is ready.
[ "GetResult", "will", "immediately", "fetch", "the", "result", "if", "it", "exists", "or", "wait", "on", "the", "result", "until", "it", "is", "ready", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L52-L62
train
Workiva/go-datastructures
futures/futures.go
HasResult
func (f *Future) HasResult() bool { f.lock.Lock() hasResult := f.triggered f.lock.Unlock() return hasResult }
go
func (f *Future) HasResult() bool { f.lock.Lock() hasResult := f.triggered f.lock.Unlock() return hasResult }
[ "func", "(", "f", "*", "Future", ")", "HasResult", "(", ")", "bool", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "hasResult", ":=", "f", ".", "triggered", "\n", "f", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "hasResult", "\n",...
// HasResult will return true iff the result exists
[ "HasResult", "will", "return", "true", "iff", "the", "result", "exists" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L65-L70
train
Workiva/go-datastructures
futures/futures.go
New
func New(completer Completer, timeout time.Duration) *Future { f := &Future{} f.wg.Add(1) var wg sync.WaitGroup wg.Add(1) go listenForResult(f, completer, timeout, &wg) wg.Wait() return f }
go
func New(completer Completer, timeout time.Duration) *Future { f := &Future{} f.wg.Add(1) var wg sync.WaitGroup wg.Add(1) go listenForResult(f, completer, timeout, &wg) wg.Wait() return f }
[ "func", "New", "(", "completer", "Completer", ",", "timeout", "time", ".", "Duration", ")", "*", "Future", "{", "f", ":=", "&", "Future", "{", "}", "\n", "f", ".", "wg", ".", "Add", "(", "1", ")", "\n", "var", "wg", "sync", ".", "WaitGroup", "\n"...
// New is the constructor to generate a new future. Pass the completed // item to the toComplete channel and any listeners will get // notified. If timeout is hit before toComplete is called, // any listeners will get passed an error.
[ "New", "is", "the", "constructor", "to", "generate", "a", "new", "future", ".", "Pass", "the", "completed", "item", "to", "the", "toComplete", "channel", "and", "any", "listeners", "will", "get", "notified", ".", "If", "timeout", "is", "hit", "before", "to...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L97-L105
train
Workiva/go-datastructures
rangetree/ordered.go
addAt
func (nodes *orderedNodes) addAt(i int, node *node) *node { if i == len(*nodes) { *nodes = append(*nodes, node) return nil } if (*nodes)[i].value == node.value { overwritten := (*nodes)[i] // this is a duplicate, there can't be a duplicate // point in the last dimension (*nodes)[i] = node return overw...
go
func (nodes *orderedNodes) addAt(i int, node *node) *node { if i == len(*nodes) { *nodes = append(*nodes, node) return nil } if (*nodes)[i].value == node.value { overwritten := (*nodes)[i] // this is a duplicate, there can't be a duplicate // point in the last dimension (*nodes)[i] = node return overw...
[ "func", "(", "nodes", "*", "orderedNodes", ")", "addAt", "(", "i", "int", ",", "node", "*", "node", ")", "*", "node", "{", "if", "i", "==", "len", "(", "*", "nodes", ")", "{", "*", "nodes", "=", "append", "(", "*", "nodes", ",", "node", ")", ...
// addAt will add the provided node at the provided index. Returns // a node if one was overwritten.
[ "addAt", "will", "add", "the", "provided", "node", "at", "the", "provided", "index", ".", "Returns", "a", "node", "if", "one", "was", "overwritten", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/ordered.go#L34-L52
train
Workiva/go-datastructures
trie/yfast/yfast.go
getBucketKey
func (yfast *YFastTrie) getBucketKey(key uint64) uint64 { i := key/uint64(yfast.bits) + 1 return uint64(yfast.bits)*i - 1 }
go
func (yfast *YFastTrie) getBucketKey(key uint64) uint64 { i := key/uint64(yfast.bits) + 1 return uint64(yfast.bits)*i - 1 }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "getBucketKey", "(", "key", "uint64", ")", "uint64", "{", "i", ":=", "key", "/", "uint64", "(", "yfast", ".", "bits", ")", "+", "1", "\n", "return", "uint64", "(", "yfast", ".", "bits", ")", "*", "i", ...
// getBucketKey finds the largest possible value in this key's bucket. // This is the representative value for the entry in the x-fast trie.
[ "getBucketKey", "finds", "the", "largest", "possible", "value", "in", "this", "key", "s", "bucket", ".", "This", "is", "the", "representative", "value", "for", "the", "entry", "in", "the", "x", "-", "fast", "trie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L71-L74
train
Workiva/go-datastructures
trie/yfast/yfast.go
Insert
func (yfast *YFastTrie) Insert(entries ...Entry) Entries { overwritten := make(Entries, 0, len(entries)) for _, e := range entries { overwritten = append(overwritten, yfast.insert(e)) } return overwritten }
go
func (yfast *YFastTrie) Insert(entries ...Entry) Entries { overwritten := make(Entries, 0, len(entries)) for _, e := range entries { overwritten = append(overwritten, yfast.insert(e)) } return overwritten }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Insert", "(", "entries", "...", "Entry", ")", "Entries", "{", "overwritten", ":=", "make", "(", "Entries", ",", "0", ",", "len", "(", "entries", ")", ")", "\n", "for", "_", ",", "e", ":=", "range", "ent...
// Insert will insert the provided entries into the y-fast trie // and return a list of entries that were overwritten.
[ "Insert", "will", "insert", "the", "provided", "entries", "into", "the", "y", "-", "fast", "trie", "and", "return", "a", "list", "of", "entries", "that", "were", "overwritten", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L107-L114
train
Workiva/go-datastructures
trie/yfast/yfast.go
Delete
func (yfast *YFastTrie) Delete(keys ...uint64) Entries { entries := make(Entries, 0, len(keys)) for _, key := range keys { entries = append(entries, yfast.delete(key)) } return entries }
go
func (yfast *YFastTrie) Delete(keys ...uint64) Entries { entries := make(Entries, 0, len(keys)) for _, key := range keys { entries = append(entries, yfast.delete(key)) } return entries }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Delete", "(", "keys", "...", "uint64", ")", "Entries", "{", "entries", ":=", "make", "(", "Entries", ",", "0", ",", "len", "(", "keys", ")", ")", "\n", "for", "_", ",", "key", ":=", "range", "keys", "...
// Delete will delete the provided keys from the y-fast trie // and return a list of entries that were deleted.
[ "Delete", "will", "delete", "the", "provided", "keys", "from", "the", "y", "-", "fast", "trie", "and", "return", "a", "list", "of", "entries", "that", "were", "deleted", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L141-L148
train
Workiva/go-datastructures
trie/yfast/yfast.go
Get
func (yfast *YFastTrie) Get(key uint64) Entry { entry := yfast.get(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Get(key uint64) Entry { entry := yfast.get(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Get", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "get", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "entry", "\n", ...
// Get will look for the provided key in the y-fast trie and return // the associated value if it is found. If it is not found, this // method returns nil.
[ "Get", "will", "look", "for", "the", "provided", "key", "in", "the", "y", "-", "fast", "trie", "and", "return", "the", "associated", "value", "if", "it", "is", "found", ".", "If", "it", "is", "not", "found", "this", "method", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L168-L175
train
Workiva/go-datastructures
trie/yfast/yfast.go
Successor
func (yfast *YFastTrie) Successor(key uint64) Entry { entry := yfast.successor(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Successor(key uint64) Entry { entry := yfast.successor(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Successor", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "successor", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "entry"...
// Successor returns an Entry with a key equal to or immediately // greater than the provided key. If such an Entry does not exist // this returns nil.
[ "Successor", "returns", "an", "Entry", "with", "a", "key", "equal", "to", "or", "immediately", "greater", "than", "the", "provided", "key", ".", "If", "such", "an", "Entry", "does", "not", "exist", "this", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L199-L206
train
Workiva/go-datastructures
trie/yfast/yfast.go
Predecessor
func (yfast *YFastTrie) Predecessor(key uint64) Entry { entry := yfast.predecessor(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Predecessor(key uint64) Entry { entry := yfast.predecessor(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Predecessor", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "predecessor", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "en...
// Predecessor returns an Entry with a key equal to or immediately // preceeding than the provided key. If such an Entry does not exist // this returns nil.
[ "Predecessor", "returns", "an", "Entry", "with", "a", "key", "equal", "to", "or", "immediately", "preceeding", "than", "the", "provided", "key", ".", "If", "such", "an", "Entry", "does", "not", "exist", "this", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L242-L249
train
Workiva/go-datastructures
graph/simple.go
V
func (g *SimpleGraph) V() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.v }
go
func (g *SimpleGraph) V() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.v }
[ "func", "(", "g", "*", "SimpleGraph", ")", "V", "(", ")", "int", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "g", ".", "v", "\n", "}" ]
// V returns the number of vertices in the SimpleGraph
[ "V", "returns", "the", "number", "of", "vertices", "in", "the", "SimpleGraph" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L52-L57
train
Workiva/go-datastructures
graph/simple.go
E
func (g *SimpleGraph) E() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.e }
go
func (g *SimpleGraph) E() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.e }
[ "func", "(", "g", "*", "SimpleGraph", ")", "E", "(", ")", "int", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "g", ".", "e", "\n", "}" ]
// E returns the number of edges in the SimpleGraph
[ "E", "returns", "the", "number", "of", "edges", "in", "the", "SimpleGraph" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L60-L65
train
Workiva/go-datastructures
graph/simple.go
AddEdge
func (g *SimpleGraph) AddEdge(v, w interface{}) error { g.mutex.Lock() defer g.mutex.Unlock() if v == w { return ErrSelfLoop } g.addVertex(v) g.addVertex(w) if _, ok := g.adjacencyList[v][w]; ok { return ErrParallelEdge } g.adjacencyList[v][w] = struct{}{} g.adjacencyList[w][v] = struct{}{} g.e++ re...
go
func (g *SimpleGraph) AddEdge(v, w interface{}) error { g.mutex.Lock() defer g.mutex.Unlock() if v == w { return ErrSelfLoop } g.addVertex(v) g.addVertex(w) if _, ok := g.adjacencyList[v][w]; ok { return ErrParallelEdge } g.adjacencyList[v][w] = struct{}{} g.adjacencyList[w][v] = struct{}{} g.e++ re...
[ "func", "(", "g", "*", "SimpleGraph", ")", "AddEdge", "(", "v", ",", "w", "interface", "{", "}", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "v", "==", ...
// AddEdge will create an edge between vertices v and w
[ "AddEdge", "will", "create", "an", "edge", "between", "vertices", "v", "and", "w" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L68-L87
train
Workiva/go-datastructures
graph/simple.go
Adj
func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) { g.mutex.RLock() defer g.mutex.RUnlock() deg, err := g.Degree(v) if err != nil { return nil, ErrVertexNotFound } adj := make([]interface{}, deg) i := 0 for key := range g.adjacencyList[v] { adj[i] = key i++ } return adj, nil }
go
func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) { g.mutex.RLock() defer g.mutex.RUnlock() deg, err := g.Degree(v) if err != nil { return nil, ErrVertexNotFound } adj := make([]interface{}, deg) i := 0 for key := range g.adjacencyList[v] { adj[i] = key i++ } return adj, nil }
[ "func", "(", "g", "*", "SimpleGraph", ")", "Adj", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", ...
// Adj returns the list of all vertices connected to v
[ "Adj", "returns", "the", "list", "of", "all", "vertices", "connected", "to", "v" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L90-L106
train
Workiva/go-datastructures
graph/simple.go
Degree
func (g *SimpleGraph) Degree(v interface{}) (int, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, ok := g.adjacencyList[v] if !ok { return 0, ErrVertexNotFound } return len(val), nil }
go
func (g *SimpleGraph) Degree(v interface{}) (int, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, ok := g.adjacencyList[v] if !ok { return 0, ErrVertexNotFound } return len(val), nil }
[ "func", "(", "g", "*", "SimpleGraph", ")", "Degree", "(", "v", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "val",...
// Degree returns the number of vertices connected to v
[ "Degree", "returns", "the", "number", "of", "vertices", "connected", "to", "v" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L109-L118
train
Workiva/go-datastructures
btree/immutable/path.go
pop
func (p *path) pop() *pathBundle { if pb := p.tail; pb != nil { p.tail = pb.prev pb.prev = nil return pb } return nil }
go
func (p *path) pop() *pathBundle { if pb := p.tail; pb != nil { p.tail = pb.prev pb.prev = nil return pb } return nil }
[ "func", "(", "p", "*", "path", ")", "pop", "(", ")", "*", "pathBundle", "{", "if", "pb", ":=", "p", ".", "tail", ";", "pb", "!=", "nil", "{", "p", ".", "tail", "=", "pb", ".", "prev", "\n", "pb", ".", "prev", "=", "nil", "\n", "return", "pb...
// pop removes the last item from the path. Note that it also nils // out the returned pathBundle's prev field. Returns nil if no items // remain.
[ "pop", "removes", "the", "last", "item", "from", "the", "path", ".", "Note", "that", "it", "also", "nils", "out", "the", "returned", "pathBundle", "s", "prev", "field", ".", "Returns", "nil", "if", "no", "items", "remain", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/path.go#L53-L61
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
copyToGen
func (i *iNode) copyToGen(gen *generation, ctrie *Ctrie) *iNode { nin := &iNode{gen: gen} main := gcasRead(i, ctrie) atomic.StorePointer( (*unsafe.Pointer)(unsafe.Pointer(&nin.main)), unsafe.Pointer(main)) return nin }
go
func (i *iNode) copyToGen(gen *generation, ctrie *Ctrie) *iNode { nin := &iNode{gen: gen} main := gcasRead(i, ctrie) atomic.StorePointer( (*unsafe.Pointer)(unsafe.Pointer(&nin.main)), unsafe.Pointer(main)) return nin }
[ "func", "(", "i", "*", "iNode", ")", "copyToGen", "(", "gen", "*", "generation", ",", "ctrie", "*", "Ctrie", ")", "*", "iNode", "{", "nin", ":=", "&", "iNode", "{", "gen", ":", "gen", "}", "\n", "main", ":=", "gcasRead", "(", "i", ",", "ctrie", ...
// copyToGen returns a copy of this I-node copied to the given generation.
[ "copyToGen", "returns", "a", "copy", "of", "this", "I", "-", "node", "copied", "to", "the", "given", "generation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L80-L86
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
newMainNode
func newMainNode(x *sNode, xhc uint32, y *sNode, yhc uint32, lev uint, gen *generation) *mainNode { if lev < exp2 { xidx := (xhc >> lev) & 0x1f yidx := (yhc >> lev) & 0x1f bmp := uint32((1 << xidx) | (1 << yidx)) if xidx == yidx { // Recurse when indexes are equal. main := newMainNode(x, xhc, y, yhc, le...
go
func newMainNode(x *sNode, xhc uint32, y *sNode, yhc uint32, lev uint, gen *generation) *mainNode { if lev < exp2 { xidx := (xhc >> lev) & 0x1f yidx := (yhc >> lev) & 0x1f bmp := uint32((1 << xidx) | (1 << yidx)) if xidx == yidx { // Recurse when indexes are equal. main := newMainNode(x, xhc, y, yhc, le...
[ "func", "newMainNode", "(", "x", "*", "sNode", ",", "xhc", "uint32", ",", "y", "*", "sNode", ",", "yhc", "uint32", ",", "lev", "uint", ",", "gen", "*", "generation", ")", "*", "mainNode", "{", "if", "lev", "<", "exp2", "{", "xidx", ":=", "(", "xh...
// newMainNode is a recursive constructor which creates a new mainNode. This // mainNode will consist of cNodes as long as the hashcode chunks of the two // keys are equal at the given level. If the level exceeds 2^w, an lNode is // created.
[ "newMainNode", "is", "a", "recursive", "constructor", "which", "creates", "a", "new", "mainNode", ".", "This", "mainNode", "will", "consist", "of", "cNodes", "as", "long", "as", "the", "hashcode", "chunks", "of", "the", "two", "keys", "are", "equal", "at", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L116-L135
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
inserted
func (c *cNode) inserted(pos, flag uint32, br branch, gen *generation) *cNode { length := uint32(len(c.array)) bmp := c.bmp array := make([]branch, length+1) copy(array, c.array) array[pos] = br for i, x := pos, uint32(0); x < length-pos; i++ { array[i+1] = c.array[i] x++ } ncn := &cNode{bmp: bmp | flag, ar...
go
func (c *cNode) inserted(pos, flag uint32, br branch, gen *generation) *cNode { length := uint32(len(c.array)) bmp := c.bmp array := make([]branch, length+1) copy(array, c.array) array[pos] = br for i, x := pos, uint32(0); x < length-pos; i++ { array[i+1] = c.array[i] x++ } ncn := &cNode{bmp: bmp | flag, ar...
[ "func", "(", "c", "*", "cNode", ")", "inserted", "(", "pos", ",", "flag", "uint32", ",", "br", "branch", ",", "gen", "*", "generation", ")", "*", "cNode", "{", "length", ":=", "uint32", "(", "len", "(", "c", ".", "array", ")", ")", "\n", "bmp", ...
// inserted returns a copy of this cNode with the new entry at the given // position.
[ "inserted", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "new", "entry", "at", "the", "given", "position", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L139-L151
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
updated
func (c *cNode) updated(pos uint32, br branch, gen *generation) *cNode { array := make([]branch, len(c.array)) copy(array, c.array) array[pos] = br ncn := &cNode{bmp: c.bmp, array: array, gen: gen} return ncn }
go
func (c *cNode) updated(pos uint32, br branch, gen *generation) *cNode { array := make([]branch, len(c.array)) copy(array, c.array) array[pos] = br ncn := &cNode{bmp: c.bmp, array: array, gen: gen} return ncn }
[ "func", "(", "c", "*", "cNode", ")", "updated", "(", "pos", "uint32", ",", "br", "branch", ",", "gen", "*", "generation", ")", "*", "cNode", "{", "array", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "c", ".", "array", ")", ")", "\n"...
// updated returns a copy of this cNode with the entry at the given index // updated.
[ "updated", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "entry", "at", "the", "given", "index", "updated", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L155-L161
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
renewed
func (c *cNode) renewed(gen *generation, ctrie *Ctrie) *cNode { array := make([]branch, len(c.array)) for i, br := range c.array { switch t := br.(type) { case *iNode: array[i] = t.copyToGen(gen, ctrie) default: array[i] = br } } return &cNode{bmp: c.bmp, array: array, gen: gen} }
go
func (c *cNode) renewed(gen *generation, ctrie *Ctrie) *cNode { array := make([]branch, len(c.array)) for i, br := range c.array { switch t := br.(type) { case *iNode: array[i] = t.copyToGen(gen, ctrie) default: array[i] = br } } return &cNode{bmp: c.bmp, array: array, gen: gen} }
[ "func", "(", "c", "*", "cNode", ")", "renewed", "(", "gen", "*", "generation", ",", "ctrie", "*", "Ctrie", ")", "*", "cNode", "{", "array", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "c", ".", "array", ")", ")", "\n", "for", "i", ...
// renewed returns a copy of this cNode with the I-nodes below it copied to the // given generation.
[ "renewed", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "I", "-", "nodes", "below", "it", "copied", "to", "the", "given", "generation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L182-L193
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
untombed
func (t *tNode) untombed() *sNode { return &sNode{&Entry{Key: t.Key, hash: t.hash, Value: t.Value}} }
go
func (t *tNode) untombed() *sNode { return &sNode{&Entry{Key: t.Key, hash: t.hash, Value: t.Value}} }
[ "func", "(", "t", "*", "tNode", ")", "untombed", "(", ")", "*", "sNode", "{", "return", "&", "sNode", "{", "&", "Entry", "{", "Key", ":", "t", ".", "Key", ",", "hash", ":", "t", ".", "hash", ",", "Value", ":", "t", ".", "Value", "}", "}", "...
// untombed returns the S-node contained by the T-node.
[ "untombed", "returns", "the", "S", "-", "node", "contained", "by", "the", "T", "-", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L202-L204
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
entry
func (l *lNode) entry() *sNode { head, _ := l.Head() return head.(*sNode) }
go
func (l *lNode) entry() *sNode { head, _ := l.Head() return head.(*sNode) }
[ "func", "(", "l", "*", "lNode", ")", "entry", "(", ")", "*", "sNode", "{", "head", ",", "_", ":=", "l", ".", "Head", "(", ")", "\n", "return", "head", ".", "(", "*", "sNode", ")", "\n", "}" ]
// entry returns the first S-node contained in the L-node.
[ "entry", "returns", "the", "first", "S", "-", "node", "contained", "in", "the", "L", "-", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L213-L216
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
lookup
func (l *lNode) lookup(e *Entry) (interface{}, bool) { found, ok := l.Find(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if !ok { return nil, false } return found.(*sNode).Value, true }
go
func (l *lNode) lookup(e *Entry) (interface{}, bool) { found, ok := l.Find(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if !ok { return nil, false } return found.(*sNode).Value, true }
[ "func", "(", "l", "*", "lNode", ")", "lookup", "(", "e", "*", "Entry", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "found", ",", "ok", ":=", "l", ".", "Find", "(", "func", "(", "sn", "interface", "{", "}", ")", "bool", "{", "retur...
// lookup returns the value at the given entry in the L-node or returns false // if it's not contained.
[ "lookup", "returns", "the", "value", "at", "the", "given", "entry", "in", "the", "L", "-", "node", "or", "returns", "false", "if", "it", "s", "not", "contained", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L220-L228
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
inserted
func (l *lNode) inserted(entry *Entry) *lNode { return &lNode{l.removed(entry).Add(&sNode{entry})} }
go
func (l *lNode) inserted(entry *Entry) *lNode { return &lNode{l.removed(entry).Add(&sNode{entry})} }
[ "func", "(", "l", "*", "lNode", ")", "inserted", "(", "entry", "*", "Entry", ")", "*", "lNode", "{", "return", "&", "lNode", "{", "l", ".", "removed", "(", "entry", ")", ".", "Add", "(", "&", "sNode", "{", "entry", "}", ")", "}", "\n", "}" ]
// inserted creates a new L-node with the added entry.
[ "inserted", "creates", "a", "new", "L", "-", "node", "with", "the", "added", "entry", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L231-L233
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
removed
func (l *lNode) removed(e *Entry) *lNode { idx := l.FindIndex(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if idx < 0 { return l } nl, _ := l.Remove(uint(idx)) return &lNode{nl} }
go
func (l *lNode) removed(e *Entry) *lNode { idx := l.FindIndex(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if idx < 0 { return l } nl, _ := l.Remove(uint(idx)) return &lNode{nl} }
[ "func", "(", "l", "*", "lNode", ")", "removed", "(", "e", "*", "Entry", ")", "*", "lNode", "{", "idx", ":=", "l", ".", "FindIndex", "(", "func", "(", "sn", "interface", "{", "}", ")", "bool", "{", "return", "bytes", ".", "Equal", "(", "e", ".",...
// removed creates a new L-node with the entry removed.
[ "removed", "creates", "a", "new", "L", "-", "node", "with", "the", "entry", "removed", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L236-L245
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
New
func New(hashFactory HashFactory) *Ctrie { if hashFactory == nil { hashFactory = defaultHashFactory } root := &iNode{main: &mainNode{cNode: &cNode{}}} return newCtrie(root, hashFactory, false) }
go
func New(hashFactory HashFactory) *Ctrie { if hashFactory == nil { hashFactory = defaultHashFactory } root := &iNode{main: &mainNode{cNode: &cNode{}}} return newCtrie(root, hashFactory, false) }
[ "func", "New", "(", "hashFactory", "HashFactory", ")", "*", "Ctrie", "{", "if", "hashFactory", "==", "nil", "{", "hashFactory", "=", "defaultHashFactory", "\n", "}", "\n", "root", ":=", "&", "iNode", "{", "main", ":", "&", "mainNode", "{", "cNode", ":", ...
// New creates an empty Ctrie which uses the provided HashFactory for key // hashing. If nil is passed in, it will default to FNV-1a hashing.
[ "New", "creates", "an", "empty", "Ctrie", "which", "uses", "the", "provided", "HashFactory", "for", "key", "hashing", ".", "If", "nil", "is", "passed", "in", "it", "will", "default", "to", "FNV", "-", "1a", "hashing", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L269-L275
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Insert
func (c *Ctrie) Insert(key []byte, value interface{}) { c.assertReadWrite() c.insert(&Entry{ Key: key, Value: value, hash: c.hash(key), }) }
go
func (c *Ctrie) Insert(key []byte, value interface{}) { c.assertReadWrite() c.insert(&Entry{ Key: key, Value: value, hash: c.hash(key), }) }
[ "func", "(", "c", "*", "Ctrie", ")", "Insert", "(", "key", "[", "]", "byte", ",", "value", "interface", "{", "}", ")", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "c", ".", "insert", "(", "&", "Entry", "{", "Key", ":", "key", ",", "Value"...
// Insert adds the key-value pair to the Ctrie, replacing the existing value if // the key already exists.
[ "Insert", "adds", "the", "key", "-", "value", "pair", "to", "the", "Ctrie", "replacing", "the", "existing", "value", "if", "the", "key", "already", "exists", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L287-L294
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Lookup
func (c *Ctrie) Lookup(key []byte) (interface{}, bool) { return c.lookup(&Entry{Key: key, hash: c.hash(key)}) }
go
func (c *Ctrie) Lookup(key []byte) (interface{}, bool) { return c.lookup(&Entry{Key: key, hash: c.hash(key)}) }
[ "func", "(", "c", "*", "Ctrie", ")", "Lookup", "(", "key", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "return", "c", ".", "lookup", "(", "&", "Entry", "{", "Key", ":", "key", ",", "hash", ":", "c", ".", "hash", ...
// Lookup returns the value for the associated key or returns false if the key // doesn't exist.
[ "Lookup", "returns", "the", "value", "for", "the", "associated", "key", "or", "returns", "false", "if", "the", "key", "doesn", "t", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L298-L300
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Remove
func (c *Ctrie) Remove(key []byte) (interface{}, bool) { c.assertReadWrite() return c.remove(&Entry{Key: key, hash: c.hash(key)}) }
go
func (c *Ctrie) Remove(key []byte) (interface{}, bool) { c.assertReadWrite() return c.remove(&Entry{Key: key, hash: c.hash(key)}) }
[ "func", "(", "c", "*", "Ctrie", ")", "Remove", "(", "key", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "return", "c", ".", "remove", "(", "&", "Entry", "{", "Key", ":", ...
// Remove deletes the value for the associated key, returning true if it was // removed or false if the entry doesn't exist.
[ "Remove", "deletes", "the", "value", "for", "the", "associated", "key", "returning", "true", "if", "it", "was", "removed", "or", "false", "if", "the", "entry", "doesn", "t", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L304-L307
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
snapshot
func (c *Ctrie) snapshot(readOnly bool) *Ctrie { if readOnly && c.readOnly { return c } for { root := c.readRoot() main := gcasRead(root, c) if c.rdcssRoot(root, main, root.copyToGen(&generation{}, c)) { if readOnly { // For a read-only snapshot, we can share the old generation // root. return...
go
func (c *Ctrie) snapshot(readOnly bool) *Ctrie { if readOnly && c.readOnly { return c } for { root := c.readRoot() main := gcasRead(root, c) if c.rdcssRoot(root, main, root.copyToGen(&generation{}, c)) { if readOnly { // For a read-only snapshot, we can share the old generation // root. return...
[ "func", "(", "c", "*", "Ctrie", ")", "snapshot", "(", "readOnly", "bool", ")", "*", "Ctrie", "{", "if", "readOnly", "&&", "c", ".", "readOnly", "{", "return", "c", "\n", "}", "\n", "for", "{", "root", ":=", "c", ".", "readRoot", "(", ")", "\n", ...
// snapshot wraps up the CAS logic to make a snapshot or a read-only snapshot.
[ "snapshot", "wraps", "up", "the", "CAS", "logic", "to", "make", "a", "snapshot", "or", "a", "read", "-", "only", "snapshot", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L322-L340
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Clear
func (c *Ctrie) Clear() { for { root := c.readRoot() gen := &generation{} newRoot := &iNode{ main: &mainNode{cNode: &cNode{array: make([]branch, 0), gen: gen}}, gen: gen, } if c.rdcssRoot(root, gcasRead(root, c), newRoot) { return } } }
go
func (c *Ctrie) Clear() { for { root := c.readRoot() gen := &generation{} newRoot := &iNode{ main: &mainNode{cNode: &cNode{array: make([]branch, 0), gen: gen}}, gen: gen, } if c.rdcssRoot(root, gcasRead(root, c), newRoot) { return } } }
[ "func", "(", "c", "*", "Ctrie", ")", "Clear", "(", ")", "{", "for", "{", "root", ":=", "c", ".", "readRoot", "(", ")", "\n", "gen", ":=", "&", "generation", "{", "}", "\n", "newRoot", ":=", "&", "iNode", "{", "main", ":", "&", "mainNode", "{", ...
// Clear removes all keys from the Ctrie.
[ "Clear", "removes", "all", "keys", "from", "the", "Ctrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L343-L355
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Iterator
func (c *Ctrie) Iterator(cancel <-chan struct{}) <-chan *Entry { ch := make(chan *Entry) snapshot := c.ReadOnlySnapshot() go func() { snapshot.traverse(snapshot.readRoot(), ch, cancel) close(ch) }() return ch }
go
func (c *Ctrie) Iterator(cancel <-chan struct{}) <-chan *Entry { ch := make(chan *Entry) snapshot := c.ReadOnlySnapshot() go func() { snapshot.traverse(snapshot.readRoot(), ch, cancel) close(ch) }() return ch }
[ "func", "(", "c", "*", "Ctrie", ")", "Iterator", "(", "cancel", "<-", "chan", "struct", "{", "}", ")", "<-", "chan", "*", "Entry", "{", "ch", ":=", "make", "(", "chan", "*", "Entry", ")", "\n", "snapshot", ":=", "c", ".", "ReadOnlySnapshot", "(", ...
// Iterator returns a channel which yields the Entries of the Ctrie. If a // cancel channel is provided, closing it will terminate and close the iterator // channel. Note that if a cancel channel is not used and not every entry is // read from the iterator, a goroutine will leak.
[ "Iterator", "returns", "a", "channel", "which", "yields", "the", "Entries", "of", "the", "Ctrie", ".", "If", "a", "cancel", "channel", "is", "provided", "closing", "it", "will", "terminate", "and", "close", "the", "iterator", "channel", ".", "Note", "that", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L361-L369
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Size
func (c *Ctrie) Size() uint { // TODO: The size operation can be optimized further by caching the size // information in main nodes of a read-only Ctrie – this reduces the // amortized complexity of the size operation to O(1) because the size // computation is amortized across the update operations that occurred /...
go
func (c *Ctrie) Size() uint { // TODO: The size operation can be optimized further by caching the size // information in main nodes of a read-only Ctrie – this reduces the // amortized complexity of the size operation to O(1) because the size // computation is amortized across the update operations that occurred /...
[ "func", "(", "c", "*", "Ctrie", ")", "Size", "(", ")", "uint", "{", "// TODO: The size operation can be optimized further by caching the size", "// information in main nodes of a read-only Ctrie – this reduces the", "// amortized complexity of the size operation to O(1) because the size", ...
// Size returns the number of keys in the Ctrie.
[ "Size", "returns", "the", "number", "of", "keys", "in", "the", "Ctrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L372-L383
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
iinsert
func (c *Ctrie) iinsert(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) bool { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the relevant bit is not in the bit...
go
func (c *Ctrie) iinsert(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) bool { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the relevant bit is not in the bit...
[ "func", "(", "c", "*", "Ctrie", ")", "iinsert", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "bool", "{", "// Linearization point.", "main", ":=", "gcasRea...
// iinsert attempts to insert the entry into the Ctrie. If false is returned, // the operation should be retried.
[ "iinsert", "attempts", "to", "insert", "the", "entry", "into", "the", "Ctrie", ".", "If", "false", "is", "returned", "the", "operation", "should", "be", "retried", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L464-L532
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
ilookup
func (c *Ctrie) ilookup(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap do...
go
func (c *Ctrie) ilookup(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap do...
[ "func", "(", "c", "*", "Ctrie", ")", "ilookup", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "(", "interface", "{", "}", ",", "bool", ",", "bool", ")...
// ilookup attempts to fetch the entry from the Ctrie. The first two return // values are the entry value and whether or not the entry was contained in the // Ctrie. The last bool indicates if the operation succeeded. False means it // should be retried.
[ "ilookup", "attempts", "to", "fetch", "the", "entry", "from", "the", "Ctrie", ".", "The", "first", "two", "return", "values", "are", "the", "entry", "value", "and", "whether", "or", "not", "the", "entry", "was", "contained", "in", "the", "Ctrie", ".", "T...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L538-L588
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
iremove
func (c *Ctrie) iremove(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap do...
go
func (c *Ctrie) iremove(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap do...
[ "func", "(", "c", "*", "Ctrie", ")", "iremove", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "(", "interface", "{", "}", ",", "bool", ",", "bool", ")...
// iremove attempts to remove the entry from the Ctrie. The first two return // values are the entry value and whether or not the entry was contained in the // Ctrie. The last bool indicates if the operation succeeded. False means it // should be retried.
[ "iremove", "attempts", "to", "remove", "the", "entry", "from", "the", "Ctrie", ".", "The", "first", "two", "return", "values", "are", "the", "entry", "value", "and", "whether", "or", "not", "the", "entry", "was", "contained", "in", "the", "Ctrie", ".", "...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L594-L665
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
toContracted
func toContracted(cn *cNode, lev uint) *mainNode { if lev > 0 && len(cn.array) == 1 { branch := cn.array[0] switch branch.(type) { case *sNode: return entomb(branch.(*sNode)) default: return &mainNode{cNode: cn} } } return &mainNode{cNode: cn} }
go
func toContracted(cn *cNode, lev uint) *mainNode { if lev > 0 && len(cn.array) == 1 { branch := cn.array[0] switch branch.(type) { case *sNode: return entomb(branch.(*sNode)) default: return &mainNode{cNode: cn} } } return &mainNode{cNode: cn} }
[ "func", "toContracted", "(", "cn", "*", "cNode", ",", "lev", "uint", ")", "*", "mainNode", "{", "if", "lev", ">", "0", "&&", "len", "(", "cn", ".", "array", ")", "==", "1", "{", "branch", ":=", "cn", ".", "array", "[", "0", "]", "\n", "switch",...
// toContracted ensures that every I-node except the root points to a C-node // with at least one branch. If a given C-Node has only a single S-node below // it and is not at the root level, a T-node which wraps the S-node is // returned.
[ "toContracted", "ensures", "that", "every", "I", "-", "node", "except", "the", "root", "points", "to", "a", "C", "-", "node", "with", "at", "least", "one", "branch", ".", "If", "a", "given", "C", "-", "Node", "has", "only", "a", "single", "S", "-", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L671-L682
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
toCompressed
func toCompressed(cn *cNode, lev uint) *mainNode { tmpArray := make([]branch, len(cn.array)) for i, sub := range cn.array { switch sub.(type) { case *iNode: inode := sub.(*iNode) mainPtr := (*unsafe.Pointer)(unsafe.Pointer(&inode.main)) main := (*mainNode)(atomic.LoadPointer(mainPtr)) tmpArray[i] = re...
go
func toCompressed(cn *cNode, lev uint) *mainNode { tmpArray := make([]branch, len(cn.array)) for i, sub := range cn.array { switch sub.(type) { case *iNode: inode := sub.(*iNode) mainPtr := (*unsafe.Pointer)(unsafe.Pointer(&inode.main)) main := (*mainNode)(atomic.LoadPointer(mainPtr)) tmpArray[i] = re...
[ "func", "toCompressed", "(", "cn", "*", "cNode", ",", "lev", "uint", ")", "*", "mainNode", "{", "tmpArray", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "cn", ".", "array", ")", ")", "\n", "for", "i", ",", "sub", ":=", "range", "cn", ...
// toCompressed compacts the C-node as a performance optimization.
[ "toCompressed", "compacts", "the", "C", "-", "node", "as", "a", "performance", "optimization", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L685-L702
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcas
func gcas(in *iNode, old, n *mainNode, ct *Ctrie) bool { prevPtr := (*unsafe.Pointer)(unsafe.Pointer(&n.prev)) atomic.StorePointer(prevPtr, unsafe.Pointer(old)) if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&in.main)), unsafe.Pointer(old), unsafe.Pointer(n)) { gcasComplete(in, n, ct) retu...
go
func gcas(in *iNode, old, n *mainNode, ct *Ctrie) bool { prevPtr := (*unsafe.Pointer)(unsafe.Pointer(&n.prev)) atomic.StorePointer(prevPtr, unsafe.Pointer(old)) if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&in.main)), unsafe.Pointer(old), unsafe.Pointer(n)) { gcasComplete(in, n, ct) retu...
[ "func", "gcas", "(", "in", "*", "iNode", ",", "old", ",", "n", "*", "mainNode", ",", "ct", "*", "Ctrie", ")", "bool", "{", "prevPtr", ":=", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer", "(", "&", "n", ".", "prev", ")",...
// gcas is a generation-compare-and-swap which has semantics similar to RDCSS, // but it does not create the intermediate object except in the case of // failures that occur due to the snapshot being taken. This ensures that the // write occurs only if the Ctrie root generation has remained the same in // addition to t...
[ "gcas", "is", "a", "generation", "-", "compare", "-", "and", "-", "swap", "which", "has", "semantics", "similar", "to", "RDCSS", "but", "it", "does", "not", "create", "the", "intermediate", "object", "except", "in", "the", "case", "of", "failures", "that",...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L776-L786
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcasRead
func gcasRead(in *iNode, ctrie *Ctrie) *mainNode { m := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&in.main)))) prev := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) if prev == nil { return m } return gcasComplete(in, m, ctrie) }
go
func gcasRead(in *iNode, ctrie *Ctrie) *mainNode { m := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&in.main)))) prev := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) if prev == nil { return m } return gcasComplete(in, m, ctrie) }
[ "func", "gcasRead", "(", "in", "*", "iNode", ",", "ctrie", "*", "Ctrie", ")", "*", "mainNode", "{", "m", ":=", "(", "*", "mainNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer"...
// gcasRead performs a GCAS-linearizable read of the I-node's main node.
[ "gcasRead", "performs", "a", "GCAS", "-", "linearizable", "read", "of", "the", "I", "-", "node", "s", "main", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L789-L796
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcasComplete
func gcasComplete(i *iNode, m *mainNode, ctrie *Ctrie) *mainNode { for { if m == nil { return nil } prev := (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) root := ctrie.rdcssReadRoot(true) if prev == nil { return m } if prev.failed != nil { // Signals GCAS failu...
go
func gcasComplete(i *iNode, m *mainNode, ctrie *Ctrie) *mainNode { for { if m == nil { return nil } prev := (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) root := ctrie.rdcssReadRoot(true) if prev == nil { return m } if prev.failed != nil { // Signals GCAS failu...
[ "func", "gcasComplete", "(", "i", "*", "iNode", ",", "m", "*", "mainNode", ",", "ctrie", "*", "Ctrie", ")", "*", "mainNode", "{", "for", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "prev", ":=", "(", "*", "mainNode", ")", ...
// gcasComplete commits the GCAS operation.
[ "gcasComplete", "commits", "the", "GCAS", "operation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L799-L841
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssReadRoot
func (c *Ctrie) rdcssReadRoot(abort bool) *iNode { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss != nil { return c.rdcssComplete(abort) } return r }
go
func (c *Ctrie) rdcssReadRoot(abort bool) *iNode { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss != nil { return c.rdcssComplete(abort) } return r }
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssReadRoot", "(", "abort", "bool", ")", "*", "iNode", "{", "r", ":=", "(", "*", "iNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer", ...
// rdcssReadRoot performs a RDCSS-linearizable read of the Ctrie root with the // given priority.
[ "rdcssReadRoot", "performs", "a", "RDCSS", "-", "linearizable", "read", "of", "the", "Ctrie", "root", "with", "the", "given", "priority", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L862-L868
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssRoot
func (c *Ctrie) rdcssRoot(old *iNode, expected *mainNode, nv *iNode) bool { desc := &iNode{ rdcss: &rdcssDescriptor{ old: old, expected: expected, nv: nv, }, } if c.casRoot(old, desc) { c.rdcssComplete(false) return atomic.LoadInt32(&desc.rdcss.committed) == 1 } return false }
go
func (c *Ctrie) rdcssRoot(old *iNode, expected *mainNode, nv *iNode) bool { desc := &iNode{ rdcss: &rdcssDescriptor{ old: old, expected: expected, nv: nv, }, } if c.casRoot(old, desc) { c.rdcssComplete(false) return atomic.LoadInt32(&desc.rdcss.committed) == 1 } return false }
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssRoot", "(", "old", "*", "iNode", ",", "expected", "*", "mainNode", ",", "nv", "*", "iNode", ")", "bool", "{", "desc", ":=", "&", "iNode", "{", "rdcss", ":", "&", "rdcssDescriptor", "{", "old", ":", "old", ...
// rdcssRoot performs a RDCSS on the Ctrie root. This is used to create a // snapshot of the Ctrie by copying the root I-node and setting it to a new // generation.
[ "rdcssRoot", "performs", "a", "RDCSS", "on", "the", "Ctrie", "root", ".", "This", "is", "used", "to", "create", "a", "snapshot", "of", "the", "Ctrie", "by", "copying", "the", "root", "I", "-", "node", "and", "setting", "it", "to", "a", "new", "generati...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L873-L886
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssComplete
func (c *Ctrie) rdcssComplete(abort bool) *iNode { for { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss == nil { return r } var ( desc = r.rdcss ov = desc.old exp = desc.expected nv = desc.nv ) if abort { if c.casRoot(r, ov) { return ov...
go
func (c *Ctrie) rdcssComplete(abort bool) *iNode { for { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss == nil { return r } var ( desc = r.rdcss ov = desc.old exp = desc.expected nv = desc.nv ) if abort { if c.casRoot(r, ov) { return ov...
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssComplete", "(", "abort", "bool", ")", "*", "iNode", "{", "for", "{", "r", ":=", "(", "*", "iNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", "."...
// rdcssComplete commits the RDCSS operation.
[ "rdcssComplete", "commits", "the", "RDCSS", "operation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L889-L924
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
casRoot
func (c *Ctrie) casRoot(ov, nv *iNode) bool { c.assertReadWrite() return atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&c.root)), unsafe.Pointer(ov), unsafe.Pointer(nv)) }
go
func (c *Ctrie) casRoot(ov, nv *iNode) bool { c.assertReadWrite() return atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&c.root)), unsafe.Pointer(ov), unsafe.Pointer(nv)) }
[ "func", "(", "c", "*", "Ctrie", ")", "casRoot", "(", "ov", ",", "nv", "*", "iNode", ")", "bool", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "return", "atomic", ".", "CompareAndSwapPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", ...
// casRoot performs a CAS on the Ctrie root.
[ "casRoot", "performs", "a", "CAS", "on", "the", "Ctrie", "root", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L927-L931
train
Workiva/go-datastructures
btree/immutable/node.go
copy
func (n *Node) copy() *Node { cpValues := make([]interface{}, len(n.ChildValues)) copy(cpValues, n.ChildValues) cpKeys := make(Keys, len(n.ChildKeys)) copy(cpKeys, n.ChildKeys) return &Node{ ID: newID(), IsLeaf: n.IsLeaf, ChildValues: cpValues, ChildKeys: cpKeys, } }
go
func (n *Node) copy() *Node { cpValues := make([]interface{}, len(n.ChildValues)) copy(cpValues, n.ChildValues) cpKeys := make(Keys, len(n.ChildKeys)) copy(cpKeys, n.ChildKeys) return &Node{ ID: newID(), IsLeaf: n.IsLeaf, ChildValues: cpValues, ChildKeys: cpKeys, } }
[ "func", "(", "n", "*", "Node", ")", "copy", "(", ")", "*", "Node", "{", "cpValues", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "n", ".", "ChildValues", ")", ")", "\n", "copy", "(", "cpValues", ",", "n", ".", "ChildValu...
// copy makes a deep copy of this node. Required before any mutation.
[ "copy", "makes", "a", "deep", "copy", "of", "this", "node", ".", "Required", "before", "any", "mutation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L127-L139
train
Workiva/go-datastructures
btree/immutable/node.go
searchKey
func (n *Node) searchKey(comparator Comparator, value interface{}) (*Key, int) { i := n.search(comparator, value) if n.IsLeaf && i == len(n.ChildValues) { // not found return nil, i } if n.IsLeaf { // equal number of ids and values return n.ChildKeys[i], i } if i == len(n.ChildValues) { // we need to go to...
go
func (n *Node) searchKey(comparator Comparator, value interface{}) (*Key, int) { i := n.search(comparator, value) if n.IsLeaf && i == len(n.ChildValues) { // not found return nil, i } if n.IsLeaf { // equal number of ids and values return n.ChildKeys[i], i } if i == len(n.ChildValues) { // we need to go to...
[ "func", "(", "n", "*", "Node", ")", "searchKey", "(", "comparator", "Comparator", ",", "value", "interface", "{", "}", ")", "(", "*", "Key", ",", "int", ")", "{", "i", ":=", "n", ".", "search", "(", "comparator", ",", "value", ")", "\n\n", "if", ...
// searchKey returns the key associated with the provided value. If the // provided value is greater than the highest value in this node and this // node is an internal node, this method returns the last ID and an index // equal to lenValues.
[ "searchKey", "returns", "the", "key", "associated", "with", "the", "provided", "value", ".", "If", "the", "provided", "value", "is", "greater", "than", "the", "highest", "value", "in", "this", "node", "and", "this", "node", "is", "an", "internal", "node", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L145-L161
train
Workiva/go-datastructures
btree/immutable/node.go
insert
func (n *Node) insert(comparator Comparator, key *Key) *Key { var overwrittenKey *Key i := n.search(comparator, key.Value) if i == len(n.ChildValues) { n.ChildValues = append(n.ChildValues, key.Value) } else { if n.ChildValues[i] == key.Value { overwrittenKey = n.ChildKeys[i] n.ChildKeys[i] = key retur...
go
func (n *Node) insert(comparator Comparator, key *Key) *Key { var overwrittenKey *Key i := n.search(comparator, key.Value) if i == len(n.ChildValues) { n.ChildValues = append(n.ChildValues, key.Value) } else { if n.ChildValues[i] == key.Value { overwrittenKey = n.ChildKeys[i] n.ChildKeys[i] = key retur...
[ "func", "(", "n", "*", "Node", ")", "insert", "(", "comparator", "Comparator", ",", "key", "*", "Key", ")", "*", "Key", "{", "var", "overwrittenKey", "*", "Key", "\n", "i", ":=", "n", ".", "search", "(", "comparator", ",", "key", ".", "Value", ")",...
// insert adds the provided key to this node and returns any ID that has // been overwritten. This method should only be called on leaf nodes.
[ "insert", "adds", "the", "provided", "key", "to", "this", "node", "and", "returns", "any", "ID", "that", "has", "been", "overwritten", ".", "This", "method", "should", "only", "be", "called", "on", "leaf", "nodes", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L165-L191
train
Workiva/go-datastructures
btree/immutable/node.go
delete
func (n *Node) delete(comparator Comparator, key *Key) *Key { i := n.search(comparator, key.Value) if i == len(n.ChildValues) { return nil } n.deleteValueAt(i) n.deleteKeyAt(i) return key }
go
func (n *Node) delete(comparator Comparator, key *Key) *Key { i := n.search(comparator, key.Value) if i == len(n.ChildValues) { return nil } n.deleteValueAt(i) n.deleteKeyAt(i) return key }
[ "func", "(", "n", "*", "Node", ")", "delete", "(", "comparator", "Comparator", ",", "key", "*", "Key", ")", "*", "Key", "{", "i", ":=", "n", ".", "search", "(", "comparator", ",", "key", ".", "Value", ")", "\n", "if", "i", "==", "len", "(", "n"...
// delete removes the provided key from the node and returns any key that // was deleted. Returns nil of the key could not be found.
[ "delete", "removes", "the", "provided", "key", "from", "the", "node", "and", "returns", "any", "key", "that", "was", "deleted", ".", "Returns", "nil", "of", "the", "key", "could", "not", "be", "found", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L195-L205
train
Workiva/go-datastructures
btree/immutable/node.go
replaceKeyAt
func (n *Node) replaceKeyAt(key *Key, i int) { n.ChildKeys[i] = key }
go
func (n *Node) replaceKeyAt(key *Key, i int) { n.ChildKeys[i] = key }
[ "func", "(", "n", "*", "Node", ")", "replaceKeyAt", "(", "key", "*", "Key", ",", "i", "int", ")", "{", "n", ".", "ChildKeys", "[", "i", "]", "=", "key", "\n", "}" ]
// replaceKeyAt replaces the key at index i with the provided id. This does // not do any bounds checking.
[ "replaceKeyAt", "replaces", "the", "key", "at", "index", "i", "with", "the", "provided", "id", ".", "This", "does", "not", "do", "any", "bounds", "checking", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L245-L247
train
Workiva/go-datastructures
btree/immutable/node.go
iter
func (n *Node) iter(comparator Comparator, start, stop interface{}) iterator { pointer := n.search(comparator, start) pointer-- return &sliceIterator{ stop: stop, n: n, pointer: pointer, comparator: comparator, } }
go
func (n *Node) iter(comparator Comparator, start, stop interface{}) iterator { pointer := n.search(comparator, start) pointer-- return &sliceIterator{ stop: stop, n: n, pointer: pointer, comparator: comparator, } }
[ "func", "(", "n", "*", "Node", ")", "iter", "(", "comparator", "Comparator", ",", "start", ",", "stop", "interface", "{", "}", ")", "iterator", "{", "pointer", ":=", "n", ".", "search", "(", "comparator", ",", "start", ")", "\n", "pointer", "--", "\n...
// iter returns an iterator that will iterate through the provided Morton // numbers as they exist in this node.
[ "iter", "returns", "an", "iterator", "that", "will", "iterate", "through", "the", "provided", "Morton", "numbers", "as", "they", "exist", "in", "this", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L256-L265
train
Workiva/go-datastructures
btree/immutable/node.go
splitAt
func (n *Node) splitAt(i int) (interface{}, *Node) { if n.IsLeaf { return n.splitLeafAt(i) } return n.splitInternalAt(i) }
go
func (n *Node) splitAt(i int) (interface{}, *Node) { if n.IsLeaf { return n.splitLeafAt(i) } return n.splitInternalAt(i) }
[ "func", "(", "n", "*", "Node", ")", "splitAt", "(", "i", "int", ")", "(", "interface", "{", "}", ",", "*", "Node", ")", "{", "if", "n", ".", "IsLeaf", "{", "return", "n", ".", "splitLeafAt", "(", "i", ")", "\n", "}", "\n\n", "return", "n", "....
// splitAt breaks this node into two parts and conceptually // returns the left part
[ "splitAt", "breaks", "this", "node", "into", "two", "parts", "and", "conceptually", "returns", "the", "left", "part" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L352-L358
train
Workiva/go-datastructures
btree/immutable/node.go
nodeFromBytes
func nodeFromBytes(t *Tr, data []byte) (*Node, error) { n := &Node{} _, err := n.UnmarshalMsg(data) if err != nil { panic(err) return nil, err } return n, nil }
go
func nodeFromBytes(t *Tr, data []byte) (*Node, error) { n := &Node{} _, err := n.UnmarshalMsg(data) if err != nil { panic(err) return nil, err } return n, nil }
[ "func", "nodeFromBytes", "(", "t", "*", "Tr", ",", "data", "[", "]", "byte", ")", "(", "*", "Node", ",", "error", ")", "{", "n", ":=", "&", "Node", "{", "}", "\n", "_", ",", "err", ":=", "n", ".", "UnmarshalMsg", "(", "data", ")", "\n", "if",...
// nodeFromBytes returns a new node struct deserialized from the provided // bytes. An error is returned for any deserialization errors.
[ "nodeFromBytes", "returns", "a", "new", "node", "struct", "deserialized", "from", "the", "provided", "bytes", ".", "An", "error", "is", "returned", "for", "any", "deserialization", "errors", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L420-L429
train
Workiva/go-datastructures
bitarray/encoding.go
Marshal
func Marshal(ba BitArray) ([]byte, error) { if eba, ok := ba.(*bitArray); ok { return eba.Serialize() } else if sba, ok := ba.(*sparseBitArray); ok { return sba.Serialize() } else { return nil, errors.New("not a valid BitArray") } }
go
func Marshal(ba BitArray) ([]byte, error) { if eba, ok := ba.(*bitArray); ok { return eba.Serialize() } else if sba, ok := ba.(*sparseBitArray); ok { return sba.Serialize() } else { return nil, errors.New("not a valid BitArray") } }
[ "func", "Marshal", "(", "ba", "BitArray", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "eba", ",", "ok", ":=", "ba", ".", "(", "*", "bitArray", ")", ";", "ok", "{", "return", "eba", ".", "Serialize", "(", ")", "\n", "}", "else", ...
// Marshal takes a dense or sparse bit array and serializes it to a // byte slice.
[ "Marshal", "takes", "a", "dense", "or", "sparse", "bit", "array", "and", "serializes", "it", "to", "a", "byte", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L28-L36
train
Workiva/go-datastructures
bitarray/encoding.go
Unmarshal
func Unmarshal(input []byte) (BitArray, error) { if len(input) == 0 { return nil, errors.New("no data in input") } if input[0] == 'B' { ret := newBitArray(0) err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else if input[0] == 'S' { ret := newSparseBitArray() err ...
go
func Unmarshal(input []byte) (BitArray, error) { if len(input) == 0 { return nil, errors.New("no data in input") } if input[0] == 'B' { ret := newBitArray(0) err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else if input[0] == 'S' { ret := newSparseBitArray() err ...
[ "func", "Unmarshal", "(", "input", "[", "]", "byte", ")", "(", "BitArray", ",", "error", ")", "{", "if", "len", "(", "input", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "input",...
// Unmarshal takes a byte slice, of the same format produced by Marshal, // and returns a BitArray.
[ "Unmarshal", "takes", "a", "byte", "slice", "of", "the", "same", "format", "produced", "by", "Marshal", "and", "returns", "a", "BitArray", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L40-L61
train
Workiva/go-datastructures
bitarray/encoding.go
Serialize
func (ba *sparseBitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'S' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } blocksLen := uint64(len(ba.blocks)) indexLen := uint64(len(ba.indices)) err = binary.Write(w, binary.LittleEndi...
go
func (ba *sparseBitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'S' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } blocksLen := uint64(len(ba.blocks)) indexLen := uint64(len(ba.indices)) err = binary.Write(w, binary.LittleEndi...
[ "func", "(", "ba", "*", "sparseBitArray", ")", "Serialize", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "var", "identifier", "uint8", "=", "'S'", "\n", "err", ":=", "binary", ...
// Serialize converts the sparseBitArray to a byte slice
[ "Serialize", "converts", "the", "sparseBitArray", "to", "a", "byte", "slice" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L64-L96
train
Workiva/go-datastructures
bitarray/encoding.go
Uint64FromBytes
func Uint64FromBytes(b []byte) (uint64, int) { if len(b) < 8 { return 0, -1 } val := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 return val, 8 }
go
func Uint64FromBytes(b []byte) (uint64, int) { if len(b) < 8 { return 0, -1 } val := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 return val, 8 }
[ "func", "Uint64FromBytes", "(", "b", "[", "]", "byte", ")", "(", "uint64", ",", "int", ")", "{", "if", "len", "(", "b", ")", "<", "8", "{", "return", "0", ",", "-", "1", "\n", "}", "\n\n", "val", ":=", "uint64", "(", "b", "[", "0", "]", ")"...
// This function is a copy from the binary package, with some added error // checking to avoid panics. The function will return the value, and the number // of bytes read from the buffer. If the number of bytes is negative, then // not enough bytes were passed in and the return value will be zero.
[ "This", "function", "is", "a", "copy", "from", "the", "binary", "package", "with", "some", "added", "error", "checking", "to", "avoid", "panics", ".", "The", "function", "will", "return", "the", "value", "and", "the", "number", "of", "bytes", "read", "from...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L102-L110
train
Workiva/go-datastructures
bitarray/encoding.go
Deserialize
func (ret *sparseBitArray) Deserialize(incoming []byte) error { var intsize = uint64(s / 8) var curLoc = uint64(1) // Ignore the identifier byte var intsToRead uint64 var bytesRead int intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data ...
go
func (ret *sparseBitArray) Deserialize(incoming []byte) error { var intsize = uint64(s / 8) var curLoc = uint64(1) // Ignore the identifier byte var intsToRead uint64 var bytesRead int intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data ...
[ "func", "(", "ret", "*", "sparseBitArray", ")", "Deserialize", "(", "incoming", "[", "]", "byte", ")", "error", "{", "var", "intsize", "=", "uint64", "(", "s", "/", "8", ")", "\n", "var", "curLoc", "=", "uint64", "(", "1", ")", "// Ignore the identifie...
// Deserialize takes the incoming byte slice, and populates the sparseBitArray // with data in the bytes. Note that this will overwrite any capacity // specified when creating the sparseBitArray. Also note that if an error // is returned, the sparseBitArray this is called on might be populated // with partial data.
[ "Deserialize", "takes", "the", "incoming", "byte", "slice", "and", "populates", "the", "sparseBitArray", "with", "data", "in", "the", "bytes", ".", "Note", "that", "this", "will", "overwrite", "any", "capacity", "specified", "when", "creating", "the", "sparseBit...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L117-L157
train
Workiva/go-datastructures
bitarray/encoding.go
Serialize
func (ba *bitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'B' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.lowest) if err != nil { return nil, err } err = binary.Write(w, binar...
go
func (ba *bitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'B' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.lowest) if err != nil { return nil, err } err = binary.Write(w, binar...
[ "func", "(", "ba", "*", "bitArray", ")", "Serialize", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "var", "identifier", "uint8", "=", "'B'", "\n", "err", ":=", "binary", ".",...
// Serialize converts the bitArray to a byte slice.
[ "Serialize", "converts", "the", "bitArray", "to", "a", "byte", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L160-L194
train
Workiva/go-datastructures
bitarray/encoding.go
Deserialize
func (ret *bitArray) Deserialize(incoming []byte) error { r := bytes.NewReader(incoming[1:]) // Discard identifier err := binary.Read(r, binary.LittleEndian, &ret.lowest) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &ret.highest) if err != nil { return err } var encodedanyset ui...
go
func (ret *bitArray) Deserialize(incoming []byte) error { r := bytes.NewReader(incoming[1:]) // Discard identifier err := binary.Read(r, binary.LittleEndian, &ret.lowest) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &ret.highest) if err != nil { return err } var encodedanyset ui...
[ "func", "(", "ret", "*", "bitArray", ")", "Deserialize", "(", "incoming", "[", "]", "byte", ")", "error", "{", "r", ":=", "bytes", ".", "NewReader", "(", "incoming", "[", "1", ":", "]", ")", "// Discard identifier", "\n\n", "err", ":=", "binary", ".", ...
// Deserialize takes the incoming byte slice, and populates the bitArray // with data in the bytes. Note that this will overwrite any capacity // specified when creating the bitArray. Also note that if an error is returned, // the bitArray this is called on might be populated with partial data.
[ "Deserialize", "takes", "the", "incoming", "byte", "slice", "and", "populates", "the", "bitArray", "with", "data", "in", "the", "bytes", ".", "Note", "that", "this", "will", "overwrite", "any", "capacity", "specified", "when", "creating", "the", "bitArray", "....
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L200-L234
train
Workiva/go-datastructures
btree/plus/btree.go
Iter
func (tree *btree) Iter(key Key) Iterator { if tree.root == nil { return nilIterator() } return tree.root.find(key) }
go
func (tree *btree) Iter(key Key) Iterator { if tree.root == nil { return nilIterator() } return tree.root.find(key) }
[ "func", "(", "tree", "*", "btree", ")", "Iter", "(", "key", "Key", ")", "Iterator", "{", "if", "tree", ".", "root", "==", "nil", "{", "return", "nilIterator", "(", ")", "\n", "}", "\n\n", "return", "tree", ".", "root", ".", "find", "(", "key", ")...
// Iter returns an iterator that can be used to traverse the b-tree // starting from the specified key or its successor.
[ "Iter", "returns", "an", "iterator", "that", "can", "be", "used", "to", "traverse", "the", "b", "-", "tree", "starting", "from", "the", "specified", "key", "or", "its", "successor", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/plus/btree.go#L87-L93
train
Workiva/go-datastructures
btree/palm/tree.go
Get
func (ptree *ptree) Get(keys ...common.Comparator) common.Comparators { ga := newGetAction(keys) ptree.checkAndRun(ga) ga.completer.Wait() return ga.result }
go
func (ptree *ptree) Get(keys ...common.Comparator) common.Comparators { ga := newGetAction(keys) ptree.checkAndRun(ga) ga.completer.Wait() return ga.result }
[ "func", "(", "ptree", "*", "ptree", ")", "Get", "(", "keys", "...", "common", ".", "Comparator", ")", "common", ".", "Comparators", "{", "ga", ":=", "newGetAction", "(", "keys", ")", "\n", "ptree", ".", "checkAndRun", "(", "ga", ")", "\n", "ga", ".",...
// Get will retrieve a list of keys from the provided keys.
[ "Get", "will", "retrieve", "a", "list", "of", "keys", "from", "the", "provided", "keys", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/palm/tree.go#L503-L508
train
Workiva/go-datastructures
btree/palm/tree.go
Query
func (ptree *ptree) Query(start, stop common.Comparator) common.Comparators { cmps := make(common.Comparators, 0, 32) aa := newApplyAction(func(cmp common.Comparator) bool { cmps = append(cmps, cmp) return true }, start, stop) ptree.checkAndRun(aa) aa.completer.Wait() return cmps }
go
func (ptree *ptree) Query(start, stop common.Comparator) common.Comparators { cmps := make(common.Comparators, 0, 32) aa := newApplyAction(func(cmp common.Comparator) bool { cmps = append(cmps, cmp) return true }, start, stop) ptree.checkAndRun(aa) aa.completer.Wait() return cmps }
[ "func", "(", "ptree", "*", "ptree", ")", "Query", "(", "start", ",", "stop", "common", ".", "Comparator", ")", "common", ".", "Comparators", "{", "cmps", ":=", "make", "(", "common", ".", "Comparators", ",", "0", ",", "32", ")", "\n", "aa", ":=", "...
// Query will return a list of Comparators that fall within the // provided start and stop Comparators. Start is inclusive while // stop is exclusive, ie [start, stop).
[ "Query", "will", "return", "a", "list", "of", "Comparators", "that", "fall", "within", "the", "provided", "start", "and", "stop", "Comparators", ".", "Start", "is", "inclusive", "while", "stop", "is", "exclusive", "ie", "[", "start", "stop", ")", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/palm/tree.go#L518-L527
train
Workiva/go-datastructures
rtree/hilbert/hilbert.go
chunkRectangles
func chunkRectangles(slice rtree.Rectangles, numParts int64) []rtree.Rectangles { parts := make([]rtree.Rectangles, numParts) for i := int64(0); i < numParts; i++ { parts[i] = slice[i*int64(len(slice))/numParts : (i+1)*int64(len(slice))/numParts] } return parts }
go
func chunkRectangles(slice rtree.Rectangles, numParts int64) []rtree.Rectangles { parts := make([]rtree.Rectangles, numParts) for i := int64(0); i < numParts; i++ { parts[i] = slice[i*int64(len(slice))/numParts : (i+1)*int64(len(slice))/numParts] } return parts }
[ "func", "chunkRectangles", "(", "slice", "rtree", ".", "Rectangles", ",", "numParts", "int64", ")", "[", "]", "rtree", ".", "Rectangles", "{", "parts", ":=", "make", "(", "[", "]", "rtree", ".", "Rectangles", ",", "numParts", ")", "\n", "for", "i", ":=...
// chunkRectangles takes a slice of rtree.Rectangle values and chunks it into `numParts` subslices.
[ "chunkRectangles", "takes", "a", "slice", "of", "rtree", ".", "Rectangle", "values", "and", "chunks", "it", "into", "numParts", "subslices", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rtree/hilbert/hilbert.go#L73-L79
train
Workiva/go-datastructures
sort/sort.go
MultithreadedSortComparators
func MultithreadedSortComparators(comparators Comparators) Comparators { toBeSorted := make(Comparators, len(comparators)) copy(toBeSorted, comparators) var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) if numCPU%2 == 1 { // single core machine numCPU++ } chunks := chunk(toBeSorted, numCPU) wg.Add(le...
go
func MultithreadedSortComparators(comparators Comparators) Comparators { toBeSorted := make(Comparators, len(comparators)) copy(toBeSorted, comparators) var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) if numCPU%2 == 1 { // single core machine numCPU++ } chunks := chunk(toBeSorted, numCPU) wg.Add(le...
[ "func", "MultithreadedSortComparators", "(", "comparators", "Comparators", ")", "Comparators", "{", "toBeSorted", ":=", "make", "(", "Comparators", ",", "len", "(", "comparators", ")", ")", "\n", "copy", "(", "toBeSorted", ",", "comparators", ")", "\n\n", "var",...
// MultithreadedSortComparators will take a list of comparators // and sort it using as many threads as are available. The list // is split into buckets for a bucket sort and then recursively // merged using SymMerge.
[ "MultithreadedSortComparators", "will", "take", "a", "list", "of", "comparators", "and", "sort", "it", "using", "as", "many", "threads", "as", "are", "available", ".", "The", "list", "is", "split", "into", "buckets", "for", "a", "bucket", "sort", "and", "the...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/sort.go#L23-L64
train
Workiva/go-datastructures
rtree/hilbert/tree.go
Search
func (tree *tree) Search(rect rtree.Rectangle) rtree.Rectangles { ga := newGetAction(rect) tree.checkAndRun(ga) ga.completer.Wait() return ga.result }
go
func (tree *tree) Search(rect rtree.Rectangle) rtree.Rectangles { ga := newGetAction(rect) tree.checkAndRun(ga) ga.completer.Wait() return ga.result }
[ "func", "(", "tree", "*", "tree", ")", "Search", "(", "rect", "rtree", ".", "Rectangle", ")", "rtree", ".", "Rectangles", "{", "ga", ":=", "newGetAction", "(", "rect", ")", "\n", "tree", ".", "checkAndRun", "(", "ga", ")", "\n", "ga", ".", "completer...
// Search will return a list of rectangles that intersect the provided // rectangle.
[ "Search", "will", "return", "a", "list", "of", "rectangles", "that", "intersect", "the", "provided", "rectangle", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rtree/hilbert/tree.go#L403-L408
train
Workiva/go-datastructures
list/persistent.go
Length
func (l *list) Length() uint { curr := l length := uint(0) for { length += 1 tail, _ := curr.Tail() if tail.IsEmpty() { return length } curr = tail.(*list) } }
go
func (l *list) Length() uint { curr := l length := uint(0) for { length += 1 tail, _ := curr.Tail() if tail.IsEmpty() { return length } curr = tail.(*list) } }
[ "func", "(", "l", "*", "list", ")", "Length", "(", ")", "uint", "{", "curr", ":=", "l", "\n", "length", ":=", "uint", "(", "0", ")", "\n", "for", "{", "length", "+=", "1", "\n", "tail", ",", "_", ":=", "curr", ".", "Tail", "(", ")", "\n", "...
// Length returns the number of items in the list.
[ "Length", "returns", "the", "number", "of", "items", "in", "the", "list", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L169-L180
train
Workiva/go-datastructures
list/persistent.go
Get
func (l *list) Get(pos uint) (interface{}, bool) { if pos == 0 { return l.head, true } return l.tail.Get(pos - 1) }
go
func (l *list) Get(pos uint) (interface{}, bool) { if pos == 0 { return l.head, true } return l.tail.Get(pos - 1) }
[ "func", "(", "l", "*", "list", ")", "Get", "(", "pos", "uint", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "pos", "==", "0", "{", "return", "l", ".", "head", ",", "true", "\n", "}", "\n", "return", "l", ".", "tail", ".", "...
// Get returns the item at the given position or an error if the position is // invalid.
[ "Get", "returns", "the", "item", "at", "the", "given", "position", "or", "an", "error", "if", "the", "position", "is", "invalid", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L202-L207
train
Workiva/go-datastructures
list/persistent.go
Remove
func (l *list) Remove(pos uint) (PersistentList, error) { if pos == 0 { nl, _ := l.Tail() return nl, nil } nl, err := l.tail.Remove(pos - 1) if err != nil { return nil, err } return &list{l.head, nl}, nil }
go
func (l *list) Remove(pos uint) (PersistentList, error) { if pos == 0 { nl, _ := l.Tail() return nl, nil } nl, err := l.tail.Remove(pos - 1) if err != nil { return nil, err } return &list{l.head, nl}, nil }
[ "func", "(", "l", "*", "list", ")", "Remove", "(", "pos", "uint", ")", "(", "PersistentList", ",", "error", ")", "{", "if", "pos", "==", "0", "{", "nl", ",", "_", ":=", "l", ".", "Tail", "(", ")", "\n", "return", "nl", ",", "nil", "\n", "}", ...
// Remove will remove the item at the given position, returning the new list or // an error if the position is invalid.
[ "Remove", "will", "remove", "the", "item", "at", "the", "given", "position", "returning", "the", "new", "list", "or", "an", "error", "if", "the", "position", "is", "invalid", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L211-L222
train
Workiva/go-datastructures
list/persistent.go
Find
func (l *list) Find(pred func(interface{}) bool) (interface{}, bool) { if pred(l.head) { return l.head, true } return l.tail.Find(pred) }
go
func (l *list) Find(pred func(interface{}) bool) (interface{}, bool) { if pred(l.head) { return l.head, true } return l.tail.Find(pred) }
[ "func", "(", "l", "*", "list", ")", "Find", "(", "pred", "func", "(", "interface", "{", "}", ")", "bool", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "pred", "(", "l", ".", "head", ")", "{", "return", "l", ".", "head", ",", ...
// Find applies the predicate function to the list and returns the first item // which matches.
[ "Find", "applies", "the", "predicate", "function", "to", "the", "list", "and", "returns", "the", "first", "item", "which", "matches", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L226-L231
train
Workiva/go-datastructures
list/persistent.go
FindIndex
func (l *list) FindIndex(pred func(interface{}) bool) int { curr := l idx := 0 for { if pred(curr.head) { return idx } tail, _ := curr.Tail() if tail.IsEmpty() { return -1 } curr = tail.(*list) idx += 1 } }
go
func (l *list) FindIndex(pred func(interface{}) bool) int { curr := l idx := 0 for { if pred(curr.head) { return idx } tail, _ := curr.Tail() if tail.IsEmpty() { return -1 } curr = tail.(*list) idx += 1 } }
[ "func", "(", "l", "*", "list", ")", "FindIndex", "(", "pred", "func", "(", "interface", "{", "}", ")", "bool", ")", "int", "{", "curr", ":=", "l", "\n", "idx", ":=", "0", "\n", "for", "{", "if", "pred", "(", "curr", ".", "head", ")", "{", "re...
// FindIndex applies the predicate function to the list and returns the index // of the first item which matches or -1 if there is no match.
[ "FindIndex", "applies", "the", "predicate", "function", "to", "the", "list", "and", "returns", "the", "index", "of", "the", "first", "item", "which", "matches", "or", "-", "1", "if", "there", "is", "no", "match", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L235-L249
train
Workiva/go-datastructures
list/persistent.go
Map
func (l *list) Map(f func(interface{}) interface{}) []interface{} { return append(l.tail.Map(f), f(l.head)) }
go
func (l *list) Map(f func(interface{}) interface{}) []interface{} { return append(l.tail.Map(f), f(l.head)) }
[ "func", "(", "l", "*", "list", ")", "Map", "(", "f", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "[", "]", "interface", "{", "}", "{", "return", "append", "(", "l", ".", "tail", ".", "Map", "(", "f", ")", ",", "f", ...
// Map applies the function to each entry in the list and returns the resulting // slice.
[ "Map", "applies", "the", "function", "to", "each", "entry", "in", "the", "list", "and", "returns", "the", "resulting", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L253-L255
train
Workiva/go-datastructures
numerics/hilbert/hilbert.go
Encode
func Encode(x, y int32) int64 { var rx, ry int32 var d int64 for s := int32(n / 2); s > 0; s /= 2 { rx = boolToInt(x&s > 0) ry = boolToInt(y&s > 0) d += int64(int64(s) * int64(s) * int64(((3 * rx) ^ ry))) rotate(s, rx, ry, &x, &y) } return d }
go
func Encode(x, y int32) int64 { var rx, ry int32 var d int64 for s := int32(n / 2); s > 0; s /= 2 { rx = boolToInt(x&s > 0) ry = boolToInt(y&s > 0) d += int64(int64(s) * int64(s) * int64(((3 * rx) ^ ry))) rotate(s, rx, ry, &x, &y) } return d }
[ "func", "Encode", "(", "x", ",", "y", "int32", ")", "int64", "{", "var", "rx", ",", "ry", "int32", "\n", "var", "d", "int64", "\n", "for", "s", ":=", "int32", "(", "n", "/", "2", ")", ";", "s", ">", "0", ";", "s", "/=", "2", "{", "rx", "=...
// Encode will encode the provided x and y coordinates into a Hilbert // distance.
[ "Encode", "will", "encode", "the", "provided", "x", "and", "y", "coordinates", "into", "a", "Hilbert", "distance", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/hilbert/hilbert.go#L62-L73
train
Workiva/go-datastructures
numerics/hilbert/hilbert.go
Decode
func Decode(h int64) (int32, int32) { var ry, rx int64 var x, y int32 t := h for s := int64(1); s < int64(n); s *= 2 { rx = 1 & (t / 2) ry = 1 & (t ^ rx) rotate(int32(s), int32(rx), int32(ry), &x, &y) x += int32(s * rx) y += int32(s * ry) t /= 4 } return x, y }
go
func Decode(h int64) (int32, int32) { var ry, rx int64 var x, y int32 t := h for s := int64(1); s < int64(n); s *= 2 { rx = 1 & (t / 2) ry = 1 & (t ^ rx) rotate(int32(s), int32(rx), int32(ry), &x, &y) x += int32(s * rx) y += int32(s * ry) t /= 4 } return x, y }
[ "func", "Decode", "(", "h", "int64", ")", "(", "int32", ",", "int32", ")", "{", "var", "ry", ",", "rx", "int64", "\n", "var", "x", ",", "y", "int32", "\n", "t", ":=", "h", "\n\n", "for", "s", ":=", "int64", "(", "1", ")", ";", "s", "<", "in...
// Decode will decode the provided Hilbert distance into a corresponding // x and y value, respectively.
[ "Decode", "will", "decode", "the", "provided", "Hilbert", "distance", "into", "a", "corresponding", "x", "and", "y", "value", "respectively", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/hilbert/hilbert.go#L77-L92
train
Workiva/go-datastructures
trie/yfast/entries.go
insert
func (entries *Entries) insert(entry Entry) Entry { i := entries.search(entry.Key()) if i == len(*entries) { *entries = append(*entries, entry) return nil } if (*entries)[i].Key() == entry.Key() { oldEntry := (*entries)[i] (*entries)[i] = entry return oldEntry } (*entries) = append(*entries, nil) co...
go
func (entries *Entries) insert(entry Entry) Entry { i := entries.search(entry.Key()) if i == len(*entries) { *entries = append(*entries, entry) return nil } if (*entries)[i].Key() == entry.Key() { oldEntry := (*entries)[i] (*entries)[i] = entry return oldEntry } (*entries) = append(*entries, nil) co...
[ "func", "(", "entries", "*", "Entries", ")", "insert", "(", "entry", "Entry", ")", "Entry", "{", "i", ":=", "entries", ".", "search", "(", "entry", ".", "Key", "(", ")", ")", "\n\n", "if", "i", "==", "len", "(", "*", "entries", ")", "{", "*", "...
// insert will insert the provided entry into this list of // entries. Returned is an entry if an entry already exists // for the provided key. If nothing is overwritten, Entry // will be nil.
[ "insert", "will", "insert", "the", "provided", "entry", "into", "this", "list", "of", "entries", ".", "Returned", "is", "an", "entry", "if", "an", "entry", "already", "exists", "for", "the", "provided", "key", ".", "If", "nothing", "is", "overwritten", "En...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L53-L71
train
Workiva/go-datastructures
trie/yfast/entries.go
delete
func (entries *Entries) delete(key uint64) Entry { i := entries.search(key) if i == len(*entries) { // key not found return nil } if (*entries)[i].Key() != key { return nil } oldEntry := (*entries)[i] copy((*entries)[i:], (*entries)[i+1:]) (*entries)[len(*entries)-1] = nil // GC *entries = (*entries)[:le...
go
func (entries *Entries) delete(key uint64) Entry { i := entries.search(key) if i == len(*entries) { // key not found return nil } if (*entries)[i].Key() != key { return nil } oldEntry := (*entries)[i] copy((*entries)[i:], (*entries)[i+1:]) (*entries)[len(*entries)-1] = nil // GC *entries = (*entries)[:le...
[ "func", "(", "entries", "*", "Entries", ")", "delete", "(", "key", "uint64", ")", "Entry", "{", "i", ":=", "entries", ".", "search", "(", "key", ")", "\n", "if", "i", "==", "len", "(", "*", "entries", ")", "{", "// key not found", "return", "nil", ...
// delete will remove the provided key from this list of entries. // Returned is a deleted Entry. This will be nil if the key // cannot be found.
[ "delete", "will", "remove", "the", "provided", "key", "from", "this", "list", "of", "entries", ".", "Returned", "is", "a", "deleted", "Entry", ".", "This", "will", "be", "nil", "if", "the", "key", "cannot", "be", "found", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L76-L91
train
Workiva/go-datastructures
trie/yfast/entries.go
max
func (entries Entries) max() (uint64, bool) { if len(entries) == 0 { return 0, false } return entries[len(entries)-1].Key(), true }
go
func (entries Entries) max() (uint64, bool) { if len(entries) == 0 { return 0, false } return entries[len(entries)-1].Key(), true }
[ "func", "(", "entries", "Entries", ")", "max", "(", ")", "(", "uint64", ",", "bool", ")", "{", "if", "len", "(", "entries", ")", "==", "0", "{", "return", "0", ",", "false", "\n", "}", "\n\n", "return", "entries", "[", "len", "(", "entries", ")",...
// max returns the value of the highest key in this list // of entries. The bool indicates if it's a valid key, that // is if there is more than zero entries in this list.
[ "max", "returns", "the", "value", "of", "the", "highest", "key", "in", "this", "list", "of", "entries", ".", "The", "bool", "indicates", "if", "it", "s", "a", "valid", "key", "that", "is", "if", "there", "is", "more", "than", "zero", "entries", "in", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L96-L102
train
Workiva/go-datastructures
trie/yfast/entries.go
get
func (entries Entries) get(key uint64) Entry { i := entries.search(key) if i == len(entries) { return nil } if entries[i].Key() == key { return entries[i] } return nil }
go
func (entries Entries) get(key uint64) Entry { i := entries.search(key) if i == len(entries) { return nil } if entries[i].Key() == key { return entries[i] } return nil }
[ "func", "(", "entries", "Entries", ")", "get", "(", "key", "uint64", ")", "Entry", "{", "i", ":=", "entries", ".", "search", "(", "key", ")", "\n", "if", "i", "==", "len", "(", "entries", ")", "{", "return", "nil", "\n", "}", "\n\n", "if", "entri...
// get will perform a lookup over this list of entries // and return an Entry if it exists. Returns nil if the // entry does not exist.
[ "get", "will", "perform", "a", "lookup", "over", "this", "list", "of", "entries", "and", "return", "an", "Entry", "if", "it", "exists", ".", "Returns", "nil", "if", "the", "entry", "does", "not", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L107-L118
train
Workiva/go-datastructures
trie/yfast/entries.go
successor
func (entries Entries) successor(key uint64) (Entry, int) { i := entries.search(key) if i == len(entries) { return nil, -1 } return entries[i], i }
go
func (entries Entries) successor(key uint64) (Entry, int) { i := entries.search(key) if i == len(entries) { return nil, -1 } return entries[i], i }
[ "func", "(", "entries", "Entries", ")", "successor", "(", "key", "uint64", ")", "(", "Entry", ",", "int", ")", "{", "i", ":=", "entries", ".", "search", "(", "key", ")", "\n", "if", "i", "==", "len", "(", "entries", ")", "{", "return", "nil", ","...
// successor will return the first entry that has a key // greater than or equal to provided key. Also returned // is the index of the find. Returns nil, -1 if a successor does // not exist.
[ "successor", "will", "return", "the", "first", "entry", "that", "has", "a", "key", "greater", "than", "or", "equal", "to", "provided", "key", ".", "Also", "returned", "is", "the", "index", "of", "the", "find", ".", "Returns", "nil", "-", "1", "if", "a"...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L124-L131
train
Workiva/go-datastructures
trie/yfast/entries.go
predecessor
func (entries Entries) predecessor(key uint64) (Entry, int) { if len(entries) == 0 { return nil, -1 } i := entries.search(key) if i == len(entries) { return entries[i-1], i - 1 } if entries[i].Key() == key { return entries[i], i } i-- if i < 0 { return nil, -1 } return entries[i], i }
go
func (entries Entries) predecessor(key uint64) (Entry, int) { if len(entries) == 0 { return nil, -1 } i := entries.search(key) if i == len(entries) { return entries[i-1], i - 1 } if entries[i].Key() == key { return entries[i], i } i-- if i < 0 { return nil, -1 } return entries[i], i }
[ "func", "(", "entries", "Entries", ")", "predecessor", "(", "key", "uint64", ")", "(", "Entry", ",", "int", ")", "{", "if", "len", "(", "entries", ")", "==", "0", "{", "return", "nil", ",", "-", "1", "\n", "}", "\n\n", "i", ":=", "entries", ".", ...
// predecessor will return the first entry that has a key // less than or equal to the provided key. Also returned // is the index of the find. Returns nil, -1 if a predecessor // does not exist.
[ "predecessor", "will", "return", "the", "first", "entry", "that", "has", "a", "key", "less", "than", "or", "equal", "to", "the", "provided", "key", ".", "Also", "returned", "is", "the", "index", "of", "the", "find", ".", "Returns", "nil", "-", "1", "if...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L137-L158
train
Workiva/go-datastructures
queue/priority_queue.go
Put
func (pq *PriorityQueue) Put(items ...Item) error { if len(items) == 0 { return nil } pq.lock.Lock() defer pq.lock.Unlock() if pq.disposed { return ErrDisposed } for _, item := range items { if pq.allowDuplicates { pq.items.push(item) } else if _, ok := pq.itemMap[item]; !ok { pq.itemMap[item] =...
go
func (pq *PriorityQueue) Put(items ...Item) error { if len(items) == 0 { return nil } pq.lock.Lock() defer pq.lock.Unlock() if pq.disposed { return ErrDisposed } for _, item := range items { if pq.allowDuplicates { pq.items.push(item) } else if _, ok := pq.itemMap[item]; !ok { pq.itemMap[item] =...
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Put", "(", "items", "...", "Item", ")", "error", "{", "if", "len", "(", "items", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "pq", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "p...
// Put adds items to the queue.
[ "Put", "adds", "items", "to", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L118-L154
train
Workiva/go-datastructures
queue/priority_queue.go
Get
func (pq *PriorityQueue) Get(number int) ([]Item, error) { if number < 1 { return nil, nil } pq.lock.Lock() if pq.disposed { pq.lock.Unlock() return nil, ErrDisposed } var items []Item // Remove references to popped items. deleteItems := func(items []Item) { for _, item := range items { delete(pq...
go
func (pq *PriorityQueue) Get(number int) ([]Item, error) { if number < 1 { return nil, nil } pq.lock.Lock() if pq.disposed { pq.lock.Unlock() return nil, ErrDisposed } var items []Item // Remove references to popped items. deleteItems := func(items []Item) { for _, item := range items { delete(pq...
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Get", "(", "number", "int", ")", "(", "[", "]", "Item", ",", "error", ")", "{", "if", "number", "<", "1", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "pq", ".", "lock", ".", "Lock", "(", ...
// Get retrieves items from the queue. If the queue is empty, // this call blocks until the next item is added to the queue. This // will attempt to retrieve number of items.
[ "Get", "retrieves", "items", "from", "the", "queue", ".", "If", "the", "queue", "is", "empty", "this", "call", "blocks", "until", "the", "next", "item", "is", "added", "to", "the", "queue", ".", "This", "will", "attempt", "to", "retrieve", "number", "of"...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L159-L203
train
Workiva/go-datastructures
queue/priority_queue.go
Peek
func (pq *PriorityQueue) Peek() Item { pq.lock.Lock() defer pq.lock.Unlock() if len(pq.items) > 0 { return pq.items[0] } return nil }
go
func (pq *PriorityQueue) Peek() Item { pq.lock.Lock() defer pq.lock.Unlock() if len(pq.items) > 0 { return pq.items[0] } return nil }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Peek", "(", ")", "Item", "{", "pq", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pq", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "len", "(", "pq", ".", "items", ")", ">", "0", "{", ...
// Peek will look at the next item without removing it from the queue.
[ "Peek", "will", "look", "at", "the", "next", "item", "without", "removing", "it", "from", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L206-L213
train
Workiva/go-datastructures
queue/priority_queue.go
Empty
func (pq *PriorityQueue) Empty() bool { pq.lock.Lock() defer pq.lock.Unlock() return len(pq.items) == 0 }
go
func (pq *PriorityQueue) Empty() bool { pq.lock.Lock() defer pq.lock.Unlock() return len(pq.items) == 0 }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Empty", "(", ")", "bool", "{", "pq", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pq", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "return", "len", "(", "pq", ".", "items", ")", "==", "0",...
// Empty returns a bool indicating if there are any items left // in the queue.
[ "Empty", "returns", "a", "bool", "indicating", "if", "there", "are", "any", "items", "left", "in", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L217-L222
train
Workiva/go-datastructures
queue/priority_queue.go
Len
func (pq *PriorityQueue) Len() int { pq.lock.Lock() defer pq.lock.Unlock() return len(pq.items) }
go
func (pq *PriorityQueue) Len() int { pq.lock.Lock() defer pq.lock.Unlock() return len(pq.items) }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Len", "(", ")", "int", "{", "pq", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pq", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "return", "len", "(", "pq", ".", "items", ")", "\n", "}" ]
// Len returns a number indicating how many items are in the queue.
[ "Len", "returns", "a", "number", "indicating", "how", "many", "items", "are", "in", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L225-L230
train
Workiva/go-datastructures
queue/priority_queue.go
Disposed
func (pq *PriorityQueue) Disposed() bool { pq.disposeLock.Lock() defer pq.disposeLock.Unlock() return pq.disposed }
go
func (pq *PriorityQueue) Disposed() bool { pq.disposeLock.Lock() defer pq.disposeLock.Unlock() return pq.disposed }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Disposed", "(", ")", "bool", "{", "pq", ".", "disposeLock", ".", "Lock", "(", ")", "\n", "defer", "pq", ".", "disposeLock", ".", "Unlock", "(", ")", "\n\n", "return", "pq", ".", "disposed", "\n", "}" ]
// Disposed returns a bool indicating if this queue has been disposed.
[ "Disposed", "returns", "a", "bool", "indicating", "if", "this", "queue", "has", "been", "disposed", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L233-L238
train
Workiva/go-datastructures
queue/priority_queue.go
NewPriorityQueue
func NewPriorityQueue(hint int, allowDuplicates bool) *PriorityQueue { return &PriorityQueue{ items: make(priorityItems, 0, hint), itemMap: make(map[Item]struct{}, hint), allowDuplicates: allowDuplicates, } }
go
func NewPriorityQueue(hint int, allowDuplicates bool) *PriorityQueue { return &PriorityQueue{ items: make(priorityItems, 0, hint), itemMap: make(map[Item]struct{}, hint), allowDuplicates: allowDuplicates, } }
[ "func", "NewPriorityQueue", "(", "hint", "int", ",", "allowDuplicates", "bool", ")", "*", "PriorityQueue", "{", "return", "&", "PriorityQueue", "{", "items", ":", "make", "(", "priorityItems", ",", "0", ",", "hint", ")", ",", "itemMap", ":", "make", "(", ...
// NewPriorityQueue is the constructor for a priority queue.
[ "NewPriorityQueue", "is", "the", "constructor", "for", "a", "priority", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/priority_queue.go#L260-L266
train
Workiva/go-datastructures
btree/immutable/rt.go
contextOrCachedNode
func (t *Tr) contextOrCachedNode(id ID, cache bool) (*Node, error) { if t.context != nil { n := t.context.getNode(id) if n != nil { return n, nil } } return t.cacher.getNode(t, id, cache) }
go
func (t *Tr) contextOrCachedNode(id ID, cache bool) (*Node, error) { if t.context != nil { n := t.context.getNode(id) if n != nil { return n, nil } } return t.cacher.getNode(t, id, cache) }
[ "func", "(", "t", "*", "Tr", ")", "contextOrCachedNode", "(", "id", "ID", ",", "cache", "bool", ")", "(", "*", "Node", ",", "error", ")", "{", "if", "t", ".", "context", "!=", "nil", "{", "n", ":=", "t", ".", "context", ".", "getNode", "(", "id...
// contextOrCachedNode is a convenience function for either fetching // a node from the context or persistence.
[ "contextOrCachedNode", "is", "a", "convenience", "function", "for", "either", "fetching", "a", "node", "from", "the", "context", "or", "persistence", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/rt.go#L80-L89
train
Workiva/go-datastructures
btree/immutable/rt.go
toBytes
func (t *Tr) toBytes() []byte { buf, err := t.MarshalMsg(nil) if err != nil { panic(`unable to encode tree`) } return buf }
go
func (t *Tr) toBytes() []byte { buf, err := t.MarshalMsg(nil) if err != nil { panic(`unable to encode tree`) } return buf }
[ "func", "(", "t", "*", "Tr", ")", "toBytes", "(", ")", "[", "]", "byte", "{", "buf", ",", "err", ":=", "t", ".", "MarshalMsg", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "`unable to encode tree`", ")", "\n", "}", "\n\n", ...
// toBytes encodes this tree into a byte array. Panics if unable // as this error has to be fixed in code.
[ "toBytes", "encodes", "this", "tree", "into", "a", "byte", "array", ".", "Panics", "if", "unable", "as", "this", "error", "has", "to", "be", "fixed", "in", "code", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/rt.go#L97-L104
train
Workiva/go-datastructures
btree/immutable/rt.go
commit
func (t *Tr) commit() []*Payload { items := make([]*Payload, 0, len(t.context.seenNodes)) for _, n := range t.context.seenNodes { n.ChildValues, n.ChildKeys = n.flatten() buf, err := n.MarshalMsg(nil) if err != nil { panic(`unable to encode node`) } n.ChildValues, n.ChildKeys = nil, nil item := &Paylo...
go
func (t *Tr) commit() []*Payload { items := make([]*Payload, 0, len(t.context.seenNodes)) for _, n := range t.context.seenNodes { n.ChildValues, n.ChildKeys = n.flatten() buf, err := n.MarshalMsg(nil) if err != nil { panic(`unable to encode node`) } n.ChildValues, n.ChildKeys = nil, nil item := &Paylo...
[ "func", "(", "t", "*", "Tr", ")", "commit", "(", ")", "[", "]", "*", "Payload", "{", "items", ":=", "make", "(", "[", "]", "*", "Payload", ",", "0", ",", "len", "(", "t", ".", "context", ".", "seenNodes", ")", ")", "\n", "for", "_", ",", "n...
// commit will gather up all created nodes and serialize them into // items that can be persisted.
[ "commit", "will", "gather", "up", "all", "created", "nodes", "and", "serialize", "them", "into", "items", "that", "can", "be", "persisted", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/rt.go#L114-L129
train
Workiva/go-datastructures
btree/immutable/rt.go
Load
func Load(p Persister, id []byte, comparator Comparator) (ReadableTree, error) { items, err := p.Load(id) if err != nil { return nil, err } if len(items) == 0 || items[0] == nil { return nil, ErrTreeNotFound } rt, err := treeFromBytes(p, items[0].Payload, comparator) if err != nil { return nil, err } ...
go
func Load(p Persister, id []byte, comparator Comparator) (ReadableTree, error) { items, err := p.Load(id) if err != nil { return nil, err } if len(items) == 0 || items[0] == nil { return nil, ErrTreeNotFound } rt, err := treeFromBytes(p, items[0].Payload, comparator) if err != nil { return nil, err } ...
[ "func", "Load", "(", "p", "Persister", ",", "id", "[", "]", "byte", ",", "comparator", "Comparator", ")", "(", "ReadableTree", ",", "error", ")", "{", "items", ",", "err", ":=", "p", ".", "Load", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{...
// Load returns a ReadableTree from persistence. The provided // config should contain a persister that can be used for this purpose. // An error is returned if the tree could not be found or an error // occurred in the persistence layer.
[ "Load", "returns", "a", "ReadableTree", "from", "persistence", ".", "The", "provided", "config", "should", "contain", "a", "persister", "that", "can", "be", "used", "for", "this", "purpose", ".", "An", "error", "is", "returned", "if", "the", "tree", "could",...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/rt.go#L210-L226
train
Workiva/go-datastructures
bitarray/bitmap.go
PopCount
func (b Bitmap32) PopCount() int { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel b -= (b >> 1) & 0x55555555 b = (b>>2)&0x33333333 + b&0x33333333 b += b >> 4 b &= 0x0f0f0f0f b *= 0x01010101 return int(byte(b >> 24)) }
go
func (b Bitmap32) PopCount() int { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel b -= (b >> 1) & 0x55555555 b = (b>>2)&0x33333333 + b&0x33333333 b += b >> 4 b &= 0x0f0f0f0f b *= 0x01010101 return int(byte(b >> 24)) }
[ "func", "(", "b", "Bitmap32", ")", "PopCount", "(", ")", "int", "{", "// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel", "b", "-=", "(", "b", ">>", "1", ")", "&", "0x55555555", "\n", "b", "=", "(", "b", ">>", "2", ")", "&", "0x3333...
// PopCount returns the amount of bits set to 1 in the Bitmap32
[ "PopCount", "returns", "the", "amount", "of", "bits", "set", "to", "1", "in", "the", "Bitmap32" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitmap.go#L50-L58
train
Workiva/go-datastructures
bitarray/bitmap.go
PopCount
func (b Bitmap64) PopCount() int { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel b -= (b >> 1) & 0x5555555555555555 b = (b>>2)&0x3333333333333333 + b&0x3333333333333333 b += b >> 4 b &= 0x0f0f0f0f0f0f0f0f b *= 0x0101010101010101 return int(byte(b >> 56)) }
go
func (b Bitmap64) PopCount() int { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel b -= (b >> 1) & 0x5555555555555555 b = (b>>2)&0x3333333333333333 + b&0x3333333333333333 b += b >> 4 b &= 0x0f0f0f0f0f0f0f0f b *= 0x0101010101010101 return int(byte(b >> 56)) }
[ "func", "(", "b", "Bitmap64", ")", "PopCount", "(", ")", "int", "{", "// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel", "b", "-=", "(", "b", ">>", "1", ")", "&", "0x5555555555555555", "\n", "b", "=", "(", "b", ">>", "2", ")", "&", ...
// PopCount returns the amount of bits set to 1 in the Bitmap64
[ "PopCount", "returns", "the", "amount", "of", "bits", "set", "to", "1", "in", "the", "Bitmap64" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitmap.go#L79-L87
train
Workiva/go-datastructures
btree/immutable/cacher.go
clear
func (c *cacher) clear() { c.lock.Lock() defer c.lock.Unlock() c.cache = make(map[string]*futures.Future, 10) }
go
func (c *cacher) clear() { c.lock.Lock() defer c.lock.Unlock() c.cache = make(map[string]*futures.Future, 10) }
[ "func", "(", "c", "*", "cacher", ")", "clear", "(", ")", "{", "c", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "c", ".", "cache", "=", "make", "(", "map", "[", "string", "]", "*", "f...
// clear deletes all items from the cache.
[ "clear", "deletes", "all", "items", "from", "the", "cache", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/cacher.go#L54-L59
train
Workiva/go-datastructures
btree/immutable/cacher.go
deleteFromCache
func (c *cacher) deleteFromCache(id ID) { c.lock.Lock() defer c.lock.Unlock() delete(c.cache, string(id)) }
go
func (c *cacher) deleteFromCache(id ID) { c.lock.Lock() defer c.lock.Unlock() delete(c.cache, string(id)) }
[ "func", "(", "c", "*", "cacher", ")", "deleteFromCache", "(", "id", "ID", ")", "{", "c", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "c", ".", "cache", ",", "string", "(",...
// deleteFromCache will remove the provided ID from the cache. This // is a threadsafe operation.
[ "deleteFromCache", "will", "remove", "the", "provided", "ID", "from", "the", "cache", ".", "This", "is", "a", "threadsafe", "operation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/cacher.go#L63-L68
train
Workiva/go-datastructures
btree/immutable/cacher.go
getNode
func (c *cacher) getNode(t *Tr, key ID, useCache bool) (*Node, error) { if !useCache { return c.loadNode(t, key) } c.lock.Lock() future, ok := c.cache[string(key)] if ok { c.lock.Unlock() ifc, err := future.GetResult() if err != nil { return nil, err } return ifc.(*Node), nil } completer := mak...
go
func (c *cacher) getNode(t *Tr, key ID, useCache bool) (*Node, error) { if !useCache { return c.loadNode(t, key) } c.lock.Lock() future, ok := c.cache[string(key)] if ok { c.lock.Unlock() ifc, err := future.GetResult() if err != nil { return nil, err } return ifc.(*Node), nil } completer := mak...
[ "func", "(", "c", "*", "cacher", ")", "getNode", "(", "t", "*", "Tr", ",", "key", "ID", ",", "useCache", "bool", ")", "(", "*", "Node", ",", "error", ")", "{", "if", "!", "useCache", "{", "return", "c", ".", "loadNode", "(", "t", ",", "key", ...
// getNode will return a Node matching the provided id. An error is returned // if the cacher could not go to the persister or the node could not be found. // All found nodes are cached so subsequent calls should be faster than // the initial. This blocks until the node is loaded, but is also threadsafe.
[ "getNode", "will", "return", "a", "Node", "matching", "the", "provided", "id", ".", "An", "error", "is", "returned", "if", "the", "cacher", "could", "not", "go", "to", "the", "persister", "or", "the", "node", "could", "not", "be", "found", ".", "All", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/cacher.go#L88-L124
train
Workiva/go-datastructures
btree/immutable/cacher.go
newCacher
func newCacher(persister Persister) *cacher { return &cacher{ persister: persister, cache: make(map[string]*futures.Future, 10), } }
go
func newCacher(persister Persister) *cacher { return &cacher{ persister: persister, cache: make(map[string]*futures.Future, 10), } }
[ "func", "newCacher", "(", "persister", "Persister", ")", "*", "cacher", "{", "return", "&", "cacher", "{", "persister", ":", "persister", ",", "cache", ":", "make", "(", "map", "[", "string", "]", "*", "futures", ".", "Future", ",", "10", ")", ",", "...
// newCacher is the constructor for a cacher that caches nodes for // an indefinite period of time.
[ "newCacher", "is", "the", "constructor", "for", "a", "cacher", "that", "caches", "nodes", "for", "an", "indefinite", "period", "of", "time", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/cacher.go#L128-L133
train
Workiva/go-datastructures
trie/dtrie/node.go
get
func get(n *node, keyHash uint32, key interface{}) Entry { index := uint(mask(keyHash, n.level)) if n.dataMap.GetBit(index) { return n.entries[index] } if n.nodeMap.GetBit(index) { return get(n.entries[index].(*node), keyHash, key) } if n.level == 6 { // get from collisionNode if n.entries[index] == nil { ...
go
func get(n *node, keyHash uint32, key interface{}) Entry { index := uint(mask(keyHash, n.level)) if n.dataMap.GetBit(index) { return n.entries[index] } if n.nodeMap.GetBit(index) { return get(n.entries[index].(*node), keyHash, key) } if n.level == 6 { // get from collisionNode if n.entries[index] == nil { ...
[ "func", "get", "(", "n", "*", "node", ",", "keyHash", "uint32", ",", "key", "interface", "{", "}", ")", "Entry", "{", "index", ":=", "uint", "(", "mask", "(", "keyHash", ",", "n", ".", "level", ")", ")", "\n", "if", "n", ".", "dataMap", ".", "G...
// returns nil if not found
[ "returns", "nil", "if", "not", "found" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/node.go#L128-L148
train