repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
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", "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", "if", "entries...
// 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", "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] = struct{}{} pq.items.push(item) } } for { sema := pq.waiters.get() if sema == nil { break } sema.response.Add(1) sema.ready <- true sema.response.Wait() if len(pq.items) == 0 { break } } return nil }
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] = struct{}{} pq.items.push(item) } } for { sema := pq.waiters.get() if sema == nil { break } sema.response.Add(1) sema.ready <- true sema.response.Wait() if len(pq.items) == 0 { break } } return nil }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Put", "(", "items", "...", "Item", ")", "error", "{", "if", "len", "(", "items", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "pq", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pq"...
// 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.itemMap, item) } } if len(pq.items) == 0 { sema := newSema() pq.waiters.put(sema) pq.lock.Unlock() <-sema.ready if pq.Disposed() { return nil, ErrDisposed } items = pq.items.get(number) if !pq.allowDuplicates { deleteItems(items) } sema.response.Done() return items, nil } items = pq.items.get(number) deleteItems(items) pq.lock.Unlock() return items, nil }
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.itemMap, item) } } if len(pq.items) == 0 { sema := newSema() pq.waiters.put(sema) pq.lock.Unlock() <-sema.ready if pq.Disposed() { return nil, ErrDisposed } items = pq.items.get(number) if !pq.allowDuplicates { deleteItems(items) } sema.response.Done() return items, nil } items = pq.items.get(number) deleteItems(items) pq.lock.Unlock() return items, nil }
[ "func", "(", "pq", "*", "PriorityQueue", ")", "Get", "(", "number", "int", ")", "(", "[", "]", "Item", ",", "error", ")", "{", "if", "number", "<", "1", "{", "return", "nil", ",", "nil", "\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", "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", "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", "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", ...
// 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 := &Payload{n.ID, buf} items = append(items, item) } return items }
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 := &Payload{n.ID, buf} items = append(items, item) } return items }
[ "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 } return rt, nil }
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 } return rt, nil }
[ "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", "{", "b", "-=", "(", "b", ">>", "1", ")", "&", "0x55555555", "\n", "b", "=", "(", "b", ">>", "2", ")", "&", "0x33333333", "+", "b", "&", "0x33333333", "\n", "b", "+=", "b", ">>",...
// 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", "{", "b", "-=", "(", "b", ">>", "1", ")", "&", "0x5555555555555555", "\n", "b", "=", "(", "b", ">>", "2", ")", "&", "0x3333333333333333", "+", "b", "&", "0x3333333333333333", "\n", "b"...
// 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", "c", ".", "cache", "=", "make", "(", "map", "[", "string", "]", "*", "fut...
// 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", "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 := make(chan interface{}, 1) future = futures.New(completer, 30*time.Second) c.cache[string(key)] = future c.lock.Unlock() go c.asyncLoadNode(t, key, completer) ifc, err := future.GetResult() if err != nil { c.deleteFromCache(key) return nil, err } if err, ok := ifc.(error); ok { c.deleteFromCache(key) return nil, err } return ifc.(*Node), nil }
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 := make(chan interface{}, 1) future = futures.New(completer, 30*time.Second) c.cache[string(key)] = future c.lock.Unlock() go c.asyncLoadNode(t, key, completer) ifc, err := future.GetResult() if err != nil { c.deleteFromCache(key) return nil, err } if err, ok := ifc.(error); ok { c.deleteFromCache(key) return nil, err } return ifc.(*Node), nil }
[ "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 { return nil } cNode := n.entries[index].(*collisionNode) for _, e := range cNode.entries { if e.Key() == key { return e } } } return 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 { return nil } cNode := n.entries[index].(*collisionNode) for _, e := range cNode.entries { if e.Key() == key { return e } } } return 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
Workiva/go-datastructures
bitarray/util.go
maxInt64
func maxInt64(ints ...int64) int64 { maxInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] > maxInt { maxInt = ints[i] } } return maxInt }
go
func maxInt64(ints ...int64) int64 { maxInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] > maxInt { maxInt = ints[i] } } return maxInt }
[ "func", "maxInt64", "(", "ints", "...", "int64", ")", "int64", "{", "maxInt", ":=", "ints", "[", "0", "]", "\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "ints", ")", ";", "i", "++", "{", "if", "ints", "[", "i", "]", ">", "maxInt", ...
// maxInt64 returns the highest integer in the provided list of int64s
[ "maxInt64", "returns", "the", "highest", "integer", "in", "the", "provided", "list", "of", "int64s" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L20-L29
train
Workiva/go-datastructures
bitarray/util.go
maxUint64
func maxUint64(ints ...uint64) uint64 { maxInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] > maxInt { maxInt = ints[i] } } return maxInt }
go
func maxUint64(ints ...uint64) uint64 { maxInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] > maxInt { maxInt = ints[i] } } return maxInt }
[ "func", "maxUint64", "(", "ints", "...", "uint64", ")", "uint64", "{", "maxInt", ":=", "ints", "[", "0", "]", "\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "ints", ")", ";", "i", "++", "{", "if", "ints", "[", "i", "]", ">", "maxInt"...
// maxUint64 returns the highest integer in the provided list of uint64s
[ "maxUint64", "returns", "the", "highest", "integer", "in", "the", "provided", "list", "of", "uint64s" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L32-L41
train
Workiva/go-datastructures
bitarray/util.go
minUint64
func minUint64(ints ...uint64) uint64 { minInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] < minInt { minInt = ints[i] } } return minInt }
go
func minUint64(ints ...uint64) uint64 { minInt := ints[0] for i := 1; i < len(ints); i++ { if ints[i] < minInt { minInt = ints[i] } } return minInt }
[ "func", "minUint64", "(", "ints", "...", "uint64", ")", "uint64", "{", "minInt", ":=", "ints", "[", "0", "]", "\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "ints", ")", ";", "i", "++", "{", "if", "ints", "[", "i", "]", "<", "minInt"...
// minUint64 returns the lowest integer in the provided list of int32s
[ "minUint64", "returns", "the", "lowest", "integer", "in", "the", "provided", "list", "of", "int32s" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L44-L53
train
Workiva/go-datastructures
bitarray/bitarray.go
ToNums
func (ba *bitArray) ToNums() []uint64 { nums := make([]uint64, 0, ba.highest-ba.lowest/4) for i, block := range ba.blocks { block.toNums(uint64(i)*s, &nums) } return nums }
go
func (ba *bitArray) ToNums() []uint64 { nums := make([]uint64, 0, ba.highest-ba.lowest/4) for i, block := range ba.blocks { block.toNums(uint64(i)*s, &nums) } return nums }
[ "func", "(", "ba", "*", "bitArray", ")", "ToNums", "(", ")", "[", "]", "uint64", "{", "nums", ":=", "make", "(", "[", "]", "uint64", ",", "0", ",", "ba", ".", "highest", "-", "ba", ".", "lowest", "/", "4", ")", "\n", "for", "i", ",", "block",...
// ToNums converts this bitarray to a list of numbers contained within it.
[ "ToNums", "converts", "this", "bitarray", "to", "a", "list", "of", "numbers", "contained", "within", "it", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L75-L82
train
Workiva/go-datastructures
bitarray/bitarray.go
SetBit
func (ba *bitArray) SetBit(k uint64) error { if k >= ba.Capacity() { return OutOfRangeError(k) } if !ba.anyset { ba.lowest = k ba.highest = k ba.anyset = true } else { if k < ba.lowest { ba.lowest = k } else if k > ba.highest { ba.highest = k } } i, pos := getIndexAndRemainder(k) ba.blocks[i] = ba.blocks[i].insert(pos) return nil }
go
func (ba *bitArray) SetBit(k uint64) error { if k >= ba.Capacity() { return OutOfRangeError(k) } if !ba.anyset { ba.lowest = k ba.highest = k ba.anyset = true } else { if k < ba.lowest { ba.lowest = k } else if k > ba.highest { ba.highest = k } } i, pos := getIndexAndRemainder(k) ba.blocks[i] = ba.blocks[i].insert(pos) return nil }
[ "func", "(", "ba", "*", "bitArray", ")", "SetBit", "(", "k", "uint64", ")", "error", "{", "if", "k", ">=", "ba", ".", "Capacity", "(", ")", "{", "return", "OutOfRangeError", "(", "k", ")", "\n", "}", "\n", "if", "!", "ba", ".", "anyset", "{", "...
// SetBit sets a bit at the given index to true.
[ "SetBit", "sets", "a", "bit", "at", "the", "given", "index", "to", "true", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L85-L105
train
Workiva/go-datastructures
bitarray/bitarray.go
GetBit
func (ba *bitArray) GetBit(k uint64) (bool, error) { if k >= ba.Capacity() { return false, OutOfRangeError(k) } i, pos := getIndexAndRemainder(k) result := ba.blocks[i]&block(1<<pos) != 0 return result, nil }
go
func (ba *bitArray) GetBit(k uint64) (bool, error) { if k >= ba.Capacity() { return false, OutOfRangeError(k) } i, pos := getIndexAndRemainder(k) result := ba.blocks[i]&block(1<<pos) != 0 return result, nil }
[ "func", "(", "ba", "*", "bitArray", ")", "GetBit", "(", "k", "uint64", ")", "(", "bool", ",", "error", ")", "{", "if", "k", ">=", "ba", ".", "Capacity", "(", ")", "{", "return", "false", ",", "OutOfRangeError", "(", "k", ")", "\n", "}", "\n", "...
// GetBit returns a bool indicating if the value at the given // index has been set.
[ "GetBit", "returns", "a", "bool", "indicating", "if", "the", "value", "at", "the", "given", "index", "has", "been", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L109-L117
train
Workiva/go-datastructures
bitarray/bitarray.go
ClearBit
func (ba *bitArray) ClearBit(k uint64) error { if k >= ba.Capacity() { return OutOfRangeError(k) } if !ba.anyset { // nothing is set, might as well bail return nil } i, pos := getIndexAndRemainder(k) ba.blocks[i] &^= block(1 << pos) if k == ba.highest { ba.setHighest() } else if k == ba.lowest { ba.setLowest() } return nil }
go
func (ba *bitArray) ClearBit(k uint64) error { if k >= ba.Capacity() { return OutOfRangeError(k) } if !ba.anyset { // nothing is set, might as well bail return nil } i, pos := getIndexAndRemainder(k) ba.blocks[i] &^= block(1 << pos) if k == ba.highest { ba.setHighest() } else if k == ba.lowest { ba.setLowest() } return nil }
[ "func", "(", "ba", "*", "bitArray", ")", "ClearBit", "(", "k", "uint64", ")", "error", "{", "if", "k", ">=", "ba", ".", "Capacity", "(", ")", "{", "return", "OutOfRangeError", "(", "k", ")", "\n", "}", "\n", "if", "!", "ba", ".", "anyset", "{", ...
//ClearBit will unset a bit at the given index if it is set.
[ "ClearBit", "will", "unset", "a", "bit", "at", "the", "given", "index", "if", "it", "is", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L120-L138
train
Workiva/go-datastructures
bitarray/bitarray.go
Or
func (ba *bitArray) Or(other BitArray) BitArray { if dba, ok := other.(*bitArray); ok { return orDenseWithDenseBitArray(ba, dba) } return orSparseWithDenseBitArray(other.(*sparseBitArray), ba) }
go
func (ba *bitArray) Or(other BitArray) BitArray { if dba, ok := other.(*bitArray); ok { return orDenseWithDenseBitArray(ba, dba) } return orSparseWithDenseBitArray(other.(*sparseBitArray), ba) }
[ "func", "(", "ba", "*", "bitArray", ")", "Or", "(", "other", "BitArray", ")", "BitArray", "{", "if", "dba", ",", "ok", ":=", "other", ".", "(", "*", "bitArray", ")", ";", "ok", "{", "return", "orDenseWithDenseBitArray", "(", "ba", ",", "dba", ")", ...
// Or will bitwise or two bit arrays and return a new bit array // representing the result.
[ "Or", "will", "bitwise", "or", "two", "bit", "arrays", "and", "return", "a", "new", "bit", "array", "representing", "the", "result", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L142-L148
train
Workiva/go-datastructures
bitarray/bitarray.go
And
func (ba *bitArray) And(other BitArray) BitArray { if dba, ok := other.(*bitArray); ok { return andDenseWithDenseBitArray(ba, dba) } return andSparseWithDenseBitArray(other.(*sparseBitArray), ba) }
go
func (ba *bitArray) And(other BitArray) BitArray { if dba, ok := other.(*bitArray); ok { return andDenseWithDenseBitArray(ba, dba) } return andSparseWithDenseBitArray(other.(*sparseBitArray), ba) }
[ "func", "(", "ba", "*", "bitArray", ")", "And", "(", "other", "BitArray", ")", "BitArray", "{", "if", "dba", ",", "ok", ":=", "other", ".", "(", "*", "bitArray", ")", ";", "ok", "{", "return", "andDenseWithDenseBitArray", "(", "ba", ",", "dba", ")", ...
// And will bitwise and two bit arrays and return a new bit array // representing the result.
[ "And", "will", "bitwise", "and", "two", "bit", "arrays", "and", "return", "a", "new", "bit", "array", "representing", "the", "result", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L152-L158
train
Workiva/go-datastructures
bitarray/bitarray.go
Reset
func (ba *bitArray) Reset() { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] &= block(0) } ba.anyset = false }
go
func (ba *bitArray) Reset() { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] &= block(0) } ba.anyset = false }
[ "func", "(", "ba", "*", "bitArray", ")", "Reset", "(", ")", "{", "for", "i", ":=", "uint64", "(", "0", ")", ";", "i", "<", "uint64", "(", "len", "(", "ba", ".", "blocks", ")", ")", ";", "i", "++", "{", "ba", ".", "blocks", "[", "i", "]", ...
// Reset clears out the bit array.
[ "Reset", "clears", "out", "the", "bit", "array", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L171-L176
train
Workiva/go-datastructures
bitarray/bitarray.go
Equals
func (ba *bitArray) Equals(other BitArray) bool { if other.Capacity() == 0 && ba.highest > 0 { return false } if other.Capacity() == 0 && !ba.anyset { return true } var selfIndex uint64 for iter := other.Blocks(); iter.Next(); { toIndex, otherBlock := iter.Value() if toIndex > selfIndex { for i := selfIndex; i < toIndex; i++ { if ba.blocks[i] > 0 { return false } } } selfIndex = toIndex if !ba.blocks[selfIndex].equals(otherBlock) { return false } selfIndex++ } lastIndex, _ := getIndexAndRemainder(ba.highest) if lastIndex >= selfIndex { return false } return true }
go
func (ba *bitArray) Equals(other BitArray) bool { if other.Capacity() == 0 && ba.highest > 0 { return false } if other.Capacity() == 0 && !ba.anyset { return true } var selfIndex uint64 for iter := other.Blocks(); iter.Next(); { toIndex, otherBlock := iter.Value() if toIndex > selfIndex { for i := selfIndex; i < toIndex; i++ { if ba.blocks[i] > 0 { return false } } } selfIndex = toIndex if !ba.blocks[selfIndex].equals(otherBlock) { return false } selfIndex++ } lastIndex, _ := getIndexAndRemainder(ba.highest) if lastIndex >= selfIndex { return false } return true }
[ "func", "(", "ba", "*", "bitArray", ")", "Equals", "(", "other", "BitArray", ")", "bool", "{", "if", "other", ".", "Capacity", "(", ")", "==", "0", "&&", "ba", ".", "highest", ">", "0", "{", "return", "false", "\n", "}", "\n", "if", "other", ".",...
// Equals returns a bool indicating if these two bit arrays are equal.
[ "Equals", "returns", "a", "bool", "indicating", "if", "these", "two", "bit", "arrays", "are", "equal", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L179-L212
train
Workiva/go-datastructures
bitarray/bitarray.go
Intersects
func (ba *bitArray) Intersects(other BitArray) bool { if other.Capacity() > ba.Capacity() { return false } if sba, ok := other.(*sparseBitArray); ok { return ba.intersectsSparseBitArray(sba) } return ba.intersectsDenseBitArray(other.(*bitArray)) }
go
func (ba *bitArray) Intersects(other BitArray) bool { if other.Capacity() > ba.Capacity() { return false } if sba, ok := other.(*sparseBitArray); ok { return ba.intersectsSparseBitArray(sba) } return ba.intersectsDenseBitArray(other.(*bitArray)) }
[ "func", "(", "ba", "*", "bitArray", ")", "Intersects", "(", "other", "BitArray", ")", "bool", "{", "if", "other", ".", "Capacity", "(", ")", ">", "ba", ".", "Capacity", "(", ")", "{", "return", "false", "\n", "}", "\n", "if", "sba", ",", "ok", ":...
// Intersects returns a bool indicating if the supplied bitarray intersects // this bitarray. This will check for intersection up to the length of the supplied // bitarray. If the supplied bitarray is longer than this bitarray, this // function returns false.
[ "Intersects", "returns", "a", "bool", "indicating", "if", "the", "supplied", "bitarray", "intersects", "this", "bitarray", ".", "This", "will", "check", "for", "intersection", "up", "to", "the", "length", "of", "the", "supplied", "bitarray", ".", "If", "the", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L218-L228
train
Workiva/go-datastructures
bitarray/bitarray.go
complement
func (ba *bitArray) complement() { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] = ^ba.blocks[i] } ba.setLowest() if ba.anyset { ba.setHighest() } }
go
func (ba *bitArray) complement() { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] = ^ba.blocks[i] } ba.setLowest() if ba.anyset { ba.setHighest() } }
[ "func", "(", "ba", "*", "bitArray", ")", "complement", "(", ")", "{", "for", "i", ":=", "uint64", "(", "0", ")", ";", "i", "<", "uint64", "(", "len", "(", "ba", ".", "blocks", ")", ")", ";", "i", "++", "{", "ba", ".", "blocks", "[", "i", "]...
// complement flips all bits in this array.
[ "complement", "flips", "all", "bits", "in", "this", "array", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L240-L249
train
Workiva/go-datastructures
bitarray/bitarray.go
newBitArray
func newBitArray(size uint64, args ...bool) *bitArray { i, r := getIndexAndRemainder(size) if r > 0 { i++ } ba := &bitArray{ blocks: make([]block, i), anyset: false, } if len(args) > 0 && args[0] == true { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] = maximumBlock } ba.lowest = 0 ba.highest = i*s - 1 ba.anyset = true } return ba }
go
func newBitArray(size uint64, args ...bool) *bitArray { i, r := getIndexAndRemainder(size) if r > 0 { i++ } ba := &bitArray{ blocks: make([]block, i), anyset: false, } if len(args) > 0 && args[0] == true { for i := uint64(0); i < uint64(len(ba.blocks)); i++ { ba.blocks[i] = maximumBlock } ba.lowest = 0 ba.highest = i*s - 1 ba.anyset = true } return ba }
[ "func", "newBitArray", "(", "size", "uint64", ",", "args", "...", "bool", ")", "*", "bitArray", "{", "i", ",", "r", ":=", "getIndexAndRemainder", "(", "size", ")", "\n", "if", "r", ">", "0", "{", "i", "++", "\n", "}", "\n", "ba", ":=", "&", "bitA...
// newBitArray returns a new dense BitArray at the specified size. This is a // separate private constructor so unit tests don't have to constantly cast the // BitArray interface to the concrete type.
[ "newBitArray", "returns", "a", "new", "dense", "BitArray", "at", "the", "specified", "size", ".", "This", "is", "a", "separate", "private", "constructor", "so", "unit", "tests", "don", "t", "have", "to", "constantly", "cast", "the", "BitArray", "interface", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L285-L307
train
Workiva/go-datastructures
btree/plus/iterator.go
exhaust
func (iter *iterator) exhaust() keys { keys := make(keys, 0, 10) for iter := iter; iter.Next(); { keys = append(keys, iter.Value()) } return keys }
go
func (iter *iterator) exhaust() keys { keys := make(keys, 0, 10) for iter := iter; iter.Next(); { keys = append(keys, iter.Value()) } return keys }
[ "func", "(", "iter", "*", "iterator", ")", "exhaust", "(", ")", "keys", "{", "keys", ":=", "make", "(", "keys", ",", "0", ",", "10", ")", "\n", "for", "iter", ":=", "iter", ";", "iter", ".", "Next", "(", ")", ";", "{", "keys", "=", "append", ...
// exhaust is a test function that's not exported
[ "exhaust", "is", "a", "test", "function", "that", "s", "not", "exported" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/plus/iterator.go#L55-L62
train
Workiva/go-datastructures
cache/cache.go
setElementIfNotNil
func (c *cached) setElementIfNotNil(element *list.Element) { if element != nil { c.element = element } }
go
func (c *cached) setElementIfNotNil(element *list.Element) { if element != nil { c.element = element } }
[ "func", "(", "c", "*", "cached", ")", "setElementIfNotNil", "(", "element", "*", "list", ".", "Element", ")", "{", "if", "element", "!=", "nil", "{", "c", ".", "element", "=", "element", "\n", "}", "\n", "}" ]
// Sets the provided list element on the cached item if it is not nil
[ "Sets", "the", "provided", "list", "element", "on", "the", "cached", "item", "if", "it", "is", "not", "nil" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L37-L41
train
Workiva/go-datastructures
cache/cache.go
EvictionPolicy
func EvictionPolicy(policy Policy) CacheOption { return func(c *cache) { switch policy { case LeastRecentlyAdded: c.recordAccess = c.noop c.recordAdd = c.record case LeastRecentlyUsed: c.recordAccess = c.record c.recordAdd = c.noop } } }
go
func EvictionPolicy(policy Policy) CacheOption { return func(c *cache) { switch policy { case LeastRecentlyAdded: c.recordAccess = c.noop c.recordAdd = c.record case LeastRecentlyUsed: c.recordAccess = c.record c.recordAdd = c.noop } } }
[ "func", "EvictionPolicy", "(", "policy", "Policy", ")", "CacheOption", "{", "return", "func", "(", "c", "*", "cache", ")", "{", "switch", "policy", "{", "case", "LeastRecentlyAdded", ":", "c", ".", "recordAccess", "=", "c", ".", "noop", "\n", "c", ".", ...
// EvictionPolicy sets the eviction policy to be used to make room for new items. // If not provided, default is LeastRecentlyUsed.
[ "EvictionPolicy", "sets", "the", "eviction", "policy", "to", "be", "used", "to", "make", "room", "for", "new", "items", ".", "If", "not", "provided", "default", "is", "LeastRecentlyUsed", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L69-L80
train
Workiva/go-datastructures
cache/cache.go
New
func New(capacity uint64, options ...CacheOption) Cache { c := &cache{ cap: capacity, keyList: list.New(), items: map[string]*cached{}, } // Default LRU eviction policy EvictionPolicy(LeastRecentlyUsed)(c) for _, option := range options { option(c) } return c }
go
func New(capacity uint64, options ...CacheOption) Cache { c := &cache{ cap: capacity, keyList: list.New(), items: map[string]*cached{}, } // Default LRU eviction policy EvictionPolicy(LeastRecentlyUsed)(c) for _, option := range options { option(c) } return c }
[ "func", "New", "(", "capacity", "uint64", ",", "options", "...", "CacheOption", ")", "Cache", "{", "c", ":=", "&", "cache", "{", "cap", ":", "capacity", ",", "keyList", ":", "list", ".", "New", "(", ")", ",", "items", ":", "map", "[", "string", "]"...
// New returns a cache with the requested options configured. // The cache consumes memory bounded by a fixed capacity, // plus tracking overhead linear in the number of items.
[ "New", "returns", "a", "cache", "with", "the", "requested", "options", "configured", ".", "The", "cache", "consumes", "memory", "bounded", "by", "a", "fixed", "capacity", "plus", "tracking", "overhead", "linear", "in", "the", "number", "of", "items", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L85-L99
train
Workiva/go-datastructures
cache/cache.go
ensureCapacity
func (c *cache) ensureCapacity(toAdd uint64) { mustRemove := int64(c.size+toAdd) - int64(c.cap) for mustRemove > 0 { key := c.keyList.Back().Value.(string) mustRemove -= int64(c.items[key].item.Size()) c.remove(key) } }
go
func (c *cache) ensureCapacity(toAdd uint64) { mustRemove := int64(c.size+toAdd) - int64(c.cap) for mustRemove > 0 { key := c.keyList.Back().Value.(string) mustRemove -= int64(c.items[key].item.Size()) c.remove(key) } }
[ "func", "(", "c", "*", "cache", ")", "ensureCapacity", "(", "toAdd", "uint64", ")", "{", "mustRemove", ":=", "int64", "(", "c", ".", "size", "+", "toAdd", ")", "-", "int64", "(", "c", ".", "cap", ")", "\n", "for", "mustRemove", ">", "0", "{", "ke...
// Given the need to add some number of new bytes to the cache, // evict items according to the eviction policy until there is room. // The caller should hold the cache lock.
[ "Given", "the", "need", "to", "add", "some", "number", "of", "new", "bytes", "to", "the", "cache", "evict", "items", "according", "to", "the", "eviction", "policy", "until", "there", "is", "room", ".", "The", "caller", "should", "hold", "the", "cache", "...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L156-L163
train
Workiva/go-datastructures
cache/cache.go
remove
func (c *cache) remove(key string) { if cached, ok := c.items[key]; ok { delete(c.items, key) c.size -= cached.item.Size() c.keyList.Remove(cached.element) } }
go
func (c *cache) remove(key string) { if cached, ok := c.items[key]; ok { delete(c.items, key) c.size -= cached.item.Size() c.keyList.Remove(cached.element) } }
[ "func", "(", "c", "*", "cache", ")", "remove", "(", "key", "string", ")", "{", "if", "cached", ",", "ok", ":=", "c", ".", "items", "[", "key", "]", ";", "ok", "{", "delete", "(", "c", ".", "items", ",", "key", ")", "\n", "c", ".", "size", "...
// Remove the item associated with the given key. // The caller should hold the cache lock.
[ "Remove", "the", "item", "associated", "with", "the", "given", "key", ".", "The", "caller", "should", "hold", "the", "cache", "lock", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L167-L173
train
Workiva/go-datastructures
cache/cache.go
record
func (c *cache) record(key string) *list.Element { if item, ok := c.items[key]; ok { c.keyList.MoveToFront(item.element) return item.element } return c.keyList.PushFront(key) }
go
func (c *cache) record(key string) *list.Element { if item, ok := c.items[key]; ok { c.keyList.MoveToFront(item.element) return item.element } return c.keyList.PushFront(key) }
[ "func", "(", "c", "*", "cache", ")", "record", "(", "key", "string", ")", "*", "list", ".", "Element", "{", "if", "item", ",", "ok", ":=", "c", ".", "items", "[", "key", "]", ";", "ok", "{", "c", ".", "keyList", ".", "MoveToFront", "(", "item",...
// A function to record the given key and mark it as last to be evicted
[ "A", "function", "to", "record", "the", "given", "key", "and", "mark", "it", "as", "last", "to", "be", "evicted" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L179-L185
train
Workiva/go-datastructures
set/dict.go
Add
func (set *Set) Add(items ...interface{}) { set.lock.Lock() defer set.lock.Unlock() set.flattened = nil for _, item := range items { set.items[item] = struct{}{} } }
go
func (set *Set) Add(items ...interface{}) { set.lock.Lock() defer set.lock.Unlock() set.flattened = nil for _, item := range items { set.items[item] = struct{}{} } }
[ "func", "(", "set", "*", "Set", ")", "Add", "(", "items", "...", "interface", "{", "}", ")", "{", "set", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "set", ".", "lock", ".", "Unlock", "(", ")", "\n", "set", ".", "flattened", "=", "nil", ...
// Add will add the provided items to the set.
[ "Add", "will", "add", "the", "provided", "items", "to", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L42-L50
train
Workiva/go-datastructures
set/dict.go
Remove
func (set *Set) Remove(items ...interface{}) { set.lock.Lock() defer set.lock.Unlock() set.flattened = nil for _, item := range items { delete(set.items, item) } }
go
func (set *Set) Remove(items ...interface{}) { set.lock.Lock() defer set.lock.Unlock() set.flattened = nil for _, item := range items { delete(set.items, item) } }
[ "func", "(", "set", "*", "Set", ")", "Remove", "(", "items", "...", "interface", "{", "}", ")", "{", "set", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "set", ".", "lock", ".", "Unlock", "(", ")", "\n", "set", ".", "flattened", "=", "nil...
// Remove will remove the given items from the set.
[ "Remove", "will", "remove", "the", "given", "items", "from", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L53-L61
train
Workiva/go-datastructures
set/dict.go
Exists
func (set *Set) Exists(item interface{}) bool { set.lock.RLock() _, ok := set.items[item] set.lock.RUnlock() return ok }
go
func (set *Set) Exists(item interface{}) bool { set.lock.RLock() _, ok := set.items[item] set.lock.RUnlock() return ok }
[ "func", "(", "set", "*", "Set", ")", "Exists", "(", "item", "interface", "{", "}", ")", "bool", "{", "set", ".", "lock", ".", "RLock", "(", ")", "\n", "_", ",", "ok", ":=", "set", ".", "items", "[", "item", "]", "\n", "set", ".", "lock", ".",...
// Exists returns a bool indicating if the given item exists in the set.
[ "Exists", "returns", "a", "bool", "indicating", "if", "the", "given", "item", "exists", "in", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L64-L72
train
Workiva/go-datastructures
set/dict.go
Flatten
func (set *Set) Flatten() []interface{} { set.lock.Lock() defer set.lock.Unlock() if set.flattened != nil { return set.flattened } set.flattened = make([]interface{}, 0, len(set.items)) for item := range set.items { set.flattened = append(set.flattened, item) } return set.flattened }
go
func (set *Set) Flatten() []interface{} { set.lock.Lock() defer set.lock.Unlock() if set.flattened != nil { return set.flattened } set.flattened = make([]interface{}, 0, len(set.items)) for item := range set.items { set.flattened = append(set.flattened, item) } return set.flattened }
[ "func", "(", "set", "*", "Set", ")", "Flatten", "(", ")", "[", "]", "interface", "{", "}", "{", "set", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "set", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "set", ".", "flattened", "!=", ...
// Flatten will return a list of the items in the set.
[ "Flatten", "will", "return", "a", "list", "of", "the", "items", "in", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L75-L88
train
Workiva/go-datastructures
set/dict.go
Len
func (set *Set) Len() int64 { set.lock.RLock() size := int64(len(set.items)) set.lock.RUnlock() return size }
go
func (set *Set) Len() int64 { set.lock.RLock() size := int64(len(set.items)) set.lock.RUnlock() return size }
[ "func", "(", "set", "*", "Set", ")", "Len", "(", ")", "int64", "{", "set", ".", "lock", ".", "RLock", "(", ")", "\n", "size", ":=", "int64", "(", "len", "(", "set", ".", "items", ")", ")", "\n", "set", ".", "lock", ".", "RUnlock", "(", ")", ...
// Len returns the number of items in the set.
[ "Len", "returns", "the", "number", "of", "items", "in", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L91-L99
train
Workiva/go-datastructures
set/dict.go
Clear
func (set *Set) Clear() { set.lock.Lock() set.items = map[interface{}]struct{}{} set.lock.Unlock() }
go
func (set *Set) Clear() { set.lock.Lock() set.items = map[interface{}]struct{}{} set.lock.Unlock() }
[ "func", "(", "set", "*", "Set", ")", "Clear", "(", ")", "{", "set", ".", "lock", ".", "Lock", "(", ")", "\n", "set", ".", "items", "=", "map", "[", "interface", "{", "}", "]", "struct", "{", "}", "{", "}", "\n", "set", ".", "lock", ".", "Un...
// Clear will remove all items from the set.
[ "Clear", "will", "remove", "all", "items", "from", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L102-L108
train
Workiva/go-datastructures
set/dict.go
All
func (set *Set) All(items ...interface{}) bool { set.lock.RLock() defer set.lock.RUnlock() for _, item := range items { if _, ok := set.items[item]; !ok { return false } } return true }
go
func (set *Set) All(items ...interface{}) bool { set.lock.RLock() defer set.lock.RUnlock() for _, item := range items { if _, ok := set.items[item]; !ok { return false } } return true }
[ "func", "(", "set", "*", "Set", ")", "All", "(", "items", "...", "interface", "{", "}", ")", "bool", "{", "set", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "set", ".", "lock", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "item", ...
// All returns a bool indicating if all of the supplied items exist in the set.
[ "All", "returns", "a", "bool", "indicating", "if", "all", "of", "the", "supplied", "items", "exist", "in", "the", "set", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L111-L122
train
Workiva/go-datastructures
set/dict.go
Dispose
func (set *Set) Dispose() { set.lock.Lock() defer set.lock.Unlock() for k := range set.items { delete(set.items, k) } //this is so we don't hang onto any references for i := 0; i < len(set.flattened); i++ { set.flattened[i] = nil } set.flattened = set.flattened[:0] pool.Put(set) }
go
func (set *Set) Dispose() { set.lock.Lock() defer set.lock.Unlock() for k := range set.items { delete(set.items, k) } //this is so we don't hang onto any references for i := 0; i < len(set.flattened); i++ { set.flattened[i] = nil } set.flattened = set.flattened[:0] pool.Put(set) }
[ "func", "(", "set", "*", "Set", ")", "Dispose", "(", ")", "{", "set", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "set", ".", "lock", ".", "Unlock", "(", ")", "\n", "for", "k", ":=", "range", "set", ".", "items", "{", "delete", "(", "s...
// Dispose will add this set back into the pool.
[ "Dispose", "will", "add", "this", "set", "back", "into", "the", "pool", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L125-L140
train
Workiva/go-datastructures
set/dict.go
New
func New(items ...interface{}) *Set { set := pool.Get().(*Set) for _, item := range items { set.items[item] = struct{}{} } if len(items) > 0 { set.flattened = nil } return set }
go
func New(items ...interface{}) *Set { set := pool.Get().(*Set) for _, item := range items { set.items[item] = struct{}{} } if len(items) > 0 { set.flattened = nil } return set }
[ "func", "New", "(", "items", "...", "interface", "{", "}", ")", "*", "Set", "{", "set", ":=", "pool", ".", "Get", "(", ")", ".", "(", "*", "Set", ")", "\n", "for", "_", ",", "item", ":=", "range", "items", "{", "set", ".", "items", "[", "item...
// New is the constructor for sets. It will pull from a reuseable memory pool if it can. // Takes a list of items to initialize the set with.
[ "New", "is", "the", "constructor", "for", "sets", ".", "It", "will", "pull", "from", "a", "reuseable", "memory", "pool", "if", "it", "can", ".", "Takes", "a", "list", "of", "items", "to", "initialize", "the", "set", "with", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L144-L155
train
Workiva/go-datastructures
augmentedtree/intervals.go
Dispose
func (ivs *Intervals) Dispose() { for i := 0; i < len(*ivs); i++ { (*ivs)[i] = nil } *ivs = (*ivs)[:0] intervalsPool.Put(*ivs) }
go
func (ivs *Intervals) Dispose() { for i := 0; i < len(*ivs); i++ { (*ivs)[i] = nil } *ivs = (*ivs)[:0] intervalsPool.Put(*ivs) }
[ "func", "(", "ivs", "*", "Intervals", ")", "Dispose", "(", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "*", "ivs", ")", ";", "i", "++", "{", "(", "*", "ivs", ")", "[", "i", "]", "=", "nil", "\n", "}", "\n", "*", "ivs", "...
// Dispose will free any consumed resources and allow this list to be // re-allocated.
[ "Dispose", "will", "free", "any", "consumed", "resources", "and", "allow", "this", "list", "to", "be", "re", "-", "allocated", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/intervals.go#L32-L39
train
Workiva/go-datastructures
slice/skip/iterator.go
Next
func (iter *iterator) Next() bool { if iter.first { iter.first = false return iter.n != nil } if iter.n == nil { return false } iter.n = iter.n.forward[0] return iter.n != nil }
go
func (iter *iterator) Next() bool { if iter.first { iter.first = false return iter.n != nil } if iter.n == nil { return false } iter.n = iter.n.forward[0] return iter.n != nil }
[ "func", "(", "iter", "*", "iterator", ")", "Next", "(", ")", "bool", "{", "if", "iter", ".", "first", "{", "iter", ".", "first", "=", "false", "\n", "return", "iter", ".", "n", "!=", "nil", "\n", "}", "\n", "if", "iter", ".", "n", "==", "nil", ...
// Next returns a bool indicating if there are any further values // in this iterator.
[ "Next", "returns", "a", "bool", "indicating", "if", "there", "are", "any", "further", "values", "in", "this", "iterator", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L33-L45
train
Workiva/go-datastructures
slice/skip/iterator.go
Value
func (iter *iterator) Value() common.Comparator { if iter.n == nil { return nil } return iter.n.entry }
go
func (iter *iterator) Value() common.Comparator { if iter.n == nil { return nil } return iter.n.entry }
[ "func", "(", "iter", "*", "iterator", ")", "Value", "(", ")", "common", ".", "Comparator", "{", "if", "iter", ".", "n", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "iter", ".", "n", ".", "entry", "\n", "}" ]
// Value returns a Comparator representing the iterator's present // position in the query. Returns nil if no values remain to iterate.
[ "Value", "returns", "a", "Comparator", "representing", "the", "iterator", "s", "present", "position", "in", "the", "query", ".", "Returns", "nil", "if", "no", "values", "remain", "to", "iterate", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L49-L55
train
Workiva/go-datastructures
slice/skip/iterator.go
exhaust
func (iter *iterator) exhaust() common.Comparators { entries := make(common.Comparators, 0, 10) for i := iter; i.Next(); { entries = append(entries, i.Value()) } return entries }
go
func (iter *iterator) exhaust() common.Comparators { entries := make(common.Comparators, 0, 10) for i := iter; i.Next(); { entries = append(entries, i.Value()) } return entries }
[ "func", "(", "iter", "*", "iterator", ")", "exhaust", "(", ")", "common", ".", "Comparators", "{", "entries", ":=", "make", "(", "common", ".", "Comparators", ",", "0", ",", "10", ")", "\n", "for", "i", ":=", "iter", ";", "i", ".", "Next", "(", "...
// exhaust is a helper method to exhaust this iterator and return // all remaining entries.
[ "exhaust", "is", "a", "helper", "method", "to", "exhaust", "this", "iterator", "and", "return", "all", "remaining", "entries", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L59-L66
train
Workiva/go-datastructures
futures/selectable.go
WaitChan
func (f *Selectable) WaitChan() <-chan struct{} { if atomic.LoadUint32(&f.filled) == 1 { return closed } return f.wchan() }
go
func (f *Selectable) WaitChan() <-chan struct{} { if atomic.LoadUint32(&f.filled) == 1 { return closed } return f.wchan() }
[ "func", "(", "f", "*", "Selectable", ")", "WaitChan", "(", ")", "<-", "chan", "struct", "{", "}", "{", "if", "atomic", ".", "LoadUint32", "(", "&", "f", ".", "filled", ")", "==", "1", "{", "return", "closed", "\n", "}", "\n", "return", "f", ".", ...
// WaitChan returns channel, which is closed when future is fullfilled.
[ "WaitChan", "returns", "channel", "which", "is", "closed", "when", "future", "is", "fullfilled", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L60-L65
train
Workiva/go-datastructures
futures/selectable.go
GetResult
func (f *Selectable) GetResult() (interface{}, error) { if atomic.LoadUint32(&f.filled) == 0 { <-f.wchan() } return f.val, f.err }
go
func (f *Selectable) GetResult() (interface{}, error) { if atomic.LoadUint32(&f.filled) == 0 { <-f.wchan() } return f.val, f.err }
[ "func", "(", "f", "*", "Selectable", ")", "GetResult", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "atomic", ".", "LoadUint32", "(", "&", "f", ".", "filled", ")", "==", "0", "{", "<-", "f", ".", "wchan", "(", ")", "\n", ...
// GetResult waits for future to be fullfilled and returns value or error, // whatever is set first
[ "GetResult", "waits", "for", "future", "to", "be", "fullfilled", "and", "returns", "value", "or", "error", "whatever", "is", "set", "first" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L69-L74
train
Workiva/go-datastructures
futures/selectable.go
Fill
func (f *Selectable) Fill(v interface{}, e error) error { f.m.Lock() if f.filled == 0 { f.val = v f.err = e atomic.StoreUint32(&f.filled, 1) w := f.wait f.wait = closed if w != nil { close(w) } } f.m.Unlock() return f.err }
go
func (f *Selectable) Fill(v interface{}, e error) error { f.m.Lock() if f.filled == 0 { f.val = v f.err = e atomic.StoreUint32(&f.filled, 1) w := f.wait f.wait = closed if w != nil { close(w) } } f.m.Unlock() return f.err }
[ "func", "(", "f", "*", "Selectable", ")", "Fill", "(", "v", "interface", "{", "}", ",", "e", "error", ")", "error", "{", "f", ".", "m", ".", "Lock", "(", ")", "\n", "if", "f", ".", "filled", "==", "0", "{", "f", ".", "val", "=", "v", "\n", ...
// Fill sets value for future, if it were not already fullfilled // Returns error, if it were already set to future.
[ "Fill", "sets", "value", "for", "future", "if", "it", "were", "not", "already", "fullfilled", "Returns", "error", "if", "it", "were", "already", "set", "to", "future", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L78-L92
train
Workiva/go-datastructures
queue/queue.go
Put
func (q *Queue) Put(items ...interface{}) error { if len(items) == 0 { return nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return ErrDisposed } q.items = append(q.items, items...) for { sema := q.waiters.get() if sema == nil { break } sema.response.Add(1) select { case sema.ready <- true: sema.response.Wait() default: // This semaphore timed out. } if len(q.items) == 0 { break } } q.lock.Unlock() return nil }
go
func (q *Queue) Put(items ...interface{}) error { if len(items) == 0 { return nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return ErrDisposed } q.items = append(q.items, items...) for { sema := q.waiters.get() if sema == nil { break } sema.response.Add(1) select { case sema.ready <- true: sema.response.Wait() default: // This semaphore timed out. } if len(q.items) == 0 { break } } q.lock.Unlock() return nil }
[ "func", "(", "q", "*", "Queue", ")", "Put", "(", "items", "...", "interface", "{", "}", ")", "error", "{", "if", "len", "(", "items", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "if", ...
// Put will add the specified items to the queue.
[ "Put", "will", "add", "the", "specified", "items", "to", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L170-L202
train
Workiva/go-datastructures
queue/queue.go
Poll
func (q *Queue) Poll(number int64, timeout time.Duration) ([]interface{}, error) { if number < 1 { // thanks again go return []interface{}{}, nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return nil, ErrDisposed } var items []interface{} if len(q.items) == 0 { sema := newSema() q.waiters.put(sema) q.lock.Unlock() var timeoutC <-chan time.Time if timeout > 0 { timeoutC = time.After(timeout) } select { case <-sema.ready: // we are now inside the put's lock if q.disposed { return nil, ErrDisposed } items = q.items.get(number) sema.response.Done() return items, nil case <-timeoutC: // cleanup the sema that was added to waiters select { case sema.ready <- true: // we called this before Put() could // Remove sema from waiters. q.lock.Lock() q.waiters.remove(sema) q.lock.Unlock() default: // Put() got it already, we need to call Done() so Put() can move on sema.response.Done() } return nil, ErrTimeout } } items = q.items.get(number) q.lock.Unlock() return items, nil }
go
func (q *Queue) Poll(number int64, timeout time.Duration) ([]interface{}, error) { if number < 1 { // thanks again go return []interface{}{}, nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return nil, ErrDisposed } var items []interface{} if len(q.items) == 0 { sema := newSema() q.waiters.put(sema) q.lock.Unlock() var timeoutC <-chan time.Time if timeout > 0 { timeoutC = time.After(timeout) } select { case <-sema.ready: // we are now inside the put's lock if q.disposed { return nil, ErrDisposed } items = q.items.get(number) sema.response.Done() return items, nil case <-timeoutC: // cleanup the sema that was added to waiters select { case sema.ready <- true: // we called this before Put() could // Remove sema from waiters. q.lock.Lock() q.waiters.remove(sema) q.lock.Unlock() default: // Put() got it already, we need to call Done() so Put() can move on sema.response.Done() } return nil, ErrTimeout } } items = q.items.get(number) q.lock.Unlock() return items, nil }
[ "func", "(", "q", "*", "Queue", ")", "Poll", "(", "number", "int64", ",", "timeout", "time", ".", "Duration", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "if", "number", "<", "1", "{", "return", "[", "]", "interface", "{", ...
// Poll retrieves items from the queue. If there are some items in the queue, // Poll will return a number UP TO the number passed in as a parameter. If no // items are in the queue, this method will pause until items are added to the // queue or the provided timeout is reached. A non-positive timeout will block // until items are added. If a timeout occurs, ErrTimeout is returned.
[ "Poll", "retrieves", "items", "from", "the", "queue", ".", "If", "there", "are", "some", "items", "in", "the", "queue", "Poll", "will", "return", "a", "number", "UP", "TO", "the", "number", "passed", "in", "as", "a", "parameter", ".", "If", "no", "item...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L217-L270
train
Workiva/go-datastructures
queue/queue.go
Peek
func (q *Queue) Peek() (interface{}, error) { q.lock.Lock() defer q.lock.Unlock() if q.disposed { return nil, ErrDisposed } peekItem, ok := q.items.peek() if !ok { return nil, ErrEmptyQueue } return peekItem, nil }
go
func (q *Queue) Peek() (interface{}, error) { q.lock.Lock() defer q.lock.Unlock() if q.disposed { return nil, ErrDisposed } peekItem, ok := q.items.peek() if !ok { return nil, ErrEmptyQueue } return peekItem, nil }
[ "func", "(", "q", "*", "Queue", ")", "Peek", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "q", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "q", ".", "disposed", ...
// Peek returns a the first item in the queue by value // without modifying the queue.
[ "Peek", "returns", "a", "the", "first", "item", "in", "the", "queue", "by", "value", "without", "modifying", "the", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L274-L288
train
Workiva/go-datastructures
queue/queue.go
TakeUntil
func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, error) { if checker == nil { return nil, nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return nil, ErrDisposed } result := q.items.getUntil(checker) q.lock.Unlock() return result, nil }
go
func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, error) { if checker == nil { return nil, nil } q.lock.Lock() if q.disposed { q.lock.Unlock() return nil, ErrDisposed } result := q.items.getUntil(checker) q.lock.Unlock() return result, nil }
[ "func", "(", "q", "*", "Queue", ")", "TakeUntil", "(", "checker", "func", "(", "item", "interface", "{", "}", ")", "bool", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "if", "checker", "==", "nil", "{", "return", "nil", ",",...
// TakeUntil takes a function and returns a list of items that // match the checker until the checker returns false. This does not // wait if there are no items in the queue.
[ "TakeUntil", "takes", "a", "function", "and", "returns", "a", "list", "of", "items", "that", "match", "the", "checker", "until", "the", "checker", "returns", "false", ".", "This", "does", "not", "wait", "if", "there", "are", "no", "items", "in", "the", "...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L293-L308
train
Workiva/go-datastructures
queue/queue.go
Empty
func (q *Queue) Empty() bool { q.lock.Lock() defer q.lock.Unlock() return len(q.items) == 0 }
go
func (q *Queue) Empty() bool { q.lock.Lock() defer q.lock.Unlock() return len(q.items) == 0 }
[ "func", "(", "q", "*", "Queue", ")", "Empty", "(", ")", "bool", "{", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "q", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "len", "(", "q", ".", "items", ")", "==", "0", "\n", "}"...
// Empty returns a bool indicating if this bool is empty.
[ "Empty", "returns", "a", "bool", "indicating", "if", "this", "bool", "is", "empty", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L311-L316
train
Workiva/go-datastructures
queue/queue.go
Len
func (q *Queue) Len() int64 { q.lock.Lock() defer q.lock.Unlock() return int64(len(q.items)) }
go
func (q *Queue) Len() int64 { q.lock.Lock() defer q.lock.Unlock() return int64(len(q.items)) }
[ "func", "(", "q", "*", "Queue", ")", "Len", "(", ")", "int64", "{", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "q", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "int64", "(", "len", "(", "q", ".", "items", ")", ")", "\...
// Len returns the number of items in this queue.
[ "Len", "returns", "the", "number", "of", "items", "in", "this", "queue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L319-L324
train
Workiva/go-datastructures
queue/queue.go
Disposed
func (q *Queue) Disposed() bool { q.lock.Lock() defer q.lock.Unlock() return q.disposed }
go
func (q *Queue) Disposed() bool { q.lock.Lock() defer q.lock.Unlock() return q.disposed }
[ "func", "(", "q", "*", "Queue", ")", "Disposed", "(", ")", "bool", "{", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "q", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "q", ".", "disposed", "\n", "}" ]
// Disposed returns a bool indicating if this queue // has had disposed called on it.
[ "Disposed", "returns", "a", "bool", "indicating", "if", "this", "queue", "has", "had", "disposed", "called", "on", "it", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L328-L333
train
Workiva/go-datastructures
queue/queue.go
Dispose
func (q *Queue) Dispose() []interface{} { q.lock.Lock() defer q.lock.Unlock() q.disposed = true for _, waiter := range q.waiters { waiter.response.Add(1) select { case waiter.ready <- true: // release Poll immediately default: // ignore if it's a timeout or in the get } } disposedItems := q.items q.items = nil q.waiters = nil return disposedItems }
go
func (q *Queue) Dispose() []interface{} { q.lock.Lock() defer q.lock.Unlock() q.disposed = true for _, waiter := range q.waiters { waiter.response.Add(1) select { case waiter.ready <- true: // release Poll immediately default: // ignore if it's a timeout or in the get } } disposedItems := q.items q.items = nil q.waiters = nil return disposedItems }
[ "func", "(", "q", "*", "Queue", ")", "Dispose", "(", ")", "[", "]", "interface", "{", "}", "{", "q", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "q", ".", "lock", ".", "Unlock", "(", ")", "\n", "q", ".", "disposed", "=", "true", "\n", ...
// Dispose will dispose of this queue and returns // the items disposed. Any subsequent calls to Get // or Put will return an error.
[ "Dispose", "will", "dispose", "of", "this", "queue", "and", "returns", "the", "items", "disposed", ".", "Any", "subsequent", "calls", "to", "Get", "or", "Put", "will", "return", "an", "error", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L338-L359
train
Workiva/go-datastructures
trie/dtrie/dtrie.go
New
func New(hasher func(v interface{}) uint32) *Dtrie { if hasher == nil { hasher = defaultHasher } return &Dtrie{ root: emptyNode(0, 32), hasher: hasher, } }
go
func New(hasher func(v interface{}) uint32) *Dtrie { if hasher == nil { hasher = defaultHasher } return &Dtrie{ root: emptyNode(0, 32), hasher: hasher, } }
[ "func", "New", "(", "hasher", "func", "(", "v", "interface", "{", "}", ")", "uint32", ")", "*", "Dtrie", "{", "if", "hasher", "==", "nil", "{", "hasher", "=", "defaultHasher", "\n", "}", "\n", "return", "&", "Dtrie", "{", "root", ":", "emptyNode", ...
// New creates an empty DTrie with the given hashing function. // If nil is passed in, the default hashing function will be used.
[ "New", "creates", "an", "empty", "DTrie", "with", "the", "given", "hashing", "function", ".", "If", "nil", "is", "passed", "in", "the", "default", "hashing", "function", "will", "be", "used", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L62-L70
train
Workiva/go-datastructures
trie/dtrie/dtrie.go
Size
func (d *Dtrie) Size() (size int) { for _ = range iterate(d.root, nil) { size++ } return size }
go
func (d *Dtrie) Size() (size int) { for _ = range iterate(d.root, nil) { size++ } return size }
[ "func", "(", "d", "*", "Dtrie", ")", "Size", "(", ")", "(", "size", "int", ")", "{", "for", "_", "=", "range", "iterate", "(", "d", ".", "root", ",", "nil", ")", "{", "size", "++", "\n", "}", "\n", "return", "size", "\n", "}" ]
// Size returns the number of entries in the Dtrie.
[ "Size", "returns", "the", "number", "of", "entries", "in", "the", "Dtrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L73-L78
train
Workiva/go-datastructures
trie/dtrie/dtrie.go
Get
func (d *Dtrie) Get(key interface{}) interface{} { return get(d.root, d.hasher(key), key).Value() }
go
func (d *Dtrie) Get(key interface{}) interface{} { return get(d.root, d.hasher(key), key).Value() }
[ "func", "(", "d", "*", "Dtrie", ")", "Get", "(", "key", "interface", "{", "}", ")", "interface", "{", "}", "{", "return", "get", "(", "d", ".", "root", ",", "d", ".", "hasher", "(", "key", ")", ",", "key", ")", ".", "Value", "(", ")", "\n", ...
// Get returns the value for the associated key or returns nil if the // key does not exist.
[ "Get", "returns", "the", "value", "for", "the", "associated", "key", "or", "returns", "nil", "if", "the", "key", "does", "not", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L82-L84
train
Workiva/go-datastructures
trie/dtrie/dtrie.go
Insert
func (d *Dtrie) Insert(key, value interface{}) *Dtrie { root := insert(d.root, &entry{d.hasher(key), key, value}) return &Dtrie{root, d.hasher} }
go
func (d *Dtrie) Insert(key, value interface{}) *Dtrie { root := insert(d.root, &entry{d.hasher(key), key, value}) return &Dtrie{root, d.hasher} }
[ "func", "(", "d", "*", "Dtrie", ")", "Insert", "(", "key", ",", "value", "interface", "{", "}", ")", "*", "Dtrie", "{", "root", ":=", "insert", "(", "d", ".", "root", ",", "&", "entry", "{", "d", ".", "hasher", "(", "key", ")", ",", "key", ",...
// Insert adds a key value pair to the Dtrie, replacing the existing value if // the key already exists and returns the resulting Dtrie.
[ "Insert", "adds", "a", "key", "value", "pair", "to", "the", "Dtrie", "replacing", "the", "existing", "value", "if", "the", "key", "already", "exists", "and", "returns", "the", "resulting", "Dtrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L88-L91
train
Workiva/go-datastructures
trie/dtrie/dtrie.go
Remove
func (d *Dtrie) Remove(key interface{}) *Dtrie { root := remove(d.root, d.hasher(key), key) return &Dtrie{root, d.hasher} }
go
func (d *Dtrie) Remove(key interface{}) *Dtrie { root := remove(d.root, d.hasher(key), key) return &Dtrie{root, d.hasher} }
[ "func", "(", "d", "*", "Dtrie", ")", "Remove", "(", "key", "interface", "{", "}", ")", "*", "Dtrie", "{", "root", ":=", "remove", "(", "d", ".", "root", ",", "d", ".", "hasher", "(", "key", ")", ",", "key", ")", "\n", "return", "&", "Dtrie", ...
// Remove deletes the value for the associated key if it exists and returns // the resulting Dtrie.
[ "Remove", "deletes", "the", "value", "for", "the", "associated", "key", "if", "it", "exists", "and", "returns", "the", "resulting", "Dtrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L95-L98
train
Workiva/go-datastructures
btree/immutable/query.go
filter
func (t *Tr) filter(start, stop interface{}, n *Node, fn func(key *Key) bool) bool { for iter := n.iter(t.config.Comparator, start, stop); iter.next(); { id, _ := iter.value() if !fn(id) { return false } } return true }
go
func (t *Tr) filter(start, stop interface{}, n *Node, fn func(key *Key) bool) bool { for iter := n.iter(t.config.Comparator, start, stop); iter.next(); { id, _ := iter.value() if !fn(id) { return false } } return true }
[ "func", "(", "t", "*", "Tr", ")", "filter", "(", "start", ",", "stop", "interface", "{", "}", ",", "n", "*", "Node", ",", "fn", "func", "(", "key", "*", "Key", ")", "bool", ")", "bool", "{", "for", "iter", ":=", "n", ".", "iter", "(", "t", ...
// filter performs an after fetch filtering of the values in the provided node. // Due to the nature of the UB-Tree, we may get results in the node that // aren't in the provided range. The returned list of keys is not necessarily // in the correct row-major order.
[ "filter", "performs", "an", "after", "fetch", "filtering", "of", "the", "values", "in", "the", "provided", "node", ".", "Due", "to", "the", "nature", "of", "the", "UB", "-", "Tree", "we", "may", "get", "results", "in", "the", "node", "that", "aren", "t...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/query.go#L92-L101
train
Workiva/go-datastructures
btree/immutable/query.go
iterativeFind
func (t *Tr) iterativeFind(value interface{}, id ID) (*path, error) { if len(id) == 0 { // can't find a matching node return nil, nil } path := &path{} var n *Node var err error var i int var key *Key for { n, err = t.contextOrCachedNode(id, t.mutable) if err != nil { return nil, err } key, i = n.searchKey(t.config.Comparator, value) pb := &pathBundle{i: i, n: n} path.append(pb) if n.IsLeaf { return path, nil } id = key.ID() } return path, nil }
go
func (t *Tr) iterativeFind(value interface{}, id ID) (*path, error) { if len(id) == 0 { // can't find a matching node return nil, nil } path := &path{} var n *Node var err error var i int var key *Key for { n, err = t.contextOrCachedNode(id, t.mutable) if err != nil { return nil, err } key, i = n.searchKey(t.config.Comparator, value) pb := &pathBundle{i: i, n: n} path.append(pb) if n.IsLeaf { return path, nil } id = key.ID() } return path, nil }
[ "func", "(", "t", "*", "Tr", ")", "iterativeFind", "(", "value", "interface", "{", "}", ",", "id", "ID", ")", "(", "*", "path", ",", "error", ")", "{", "if", "len", "(", "id", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n",...
// iterativeFind searches for the node with the provided value. This // is an iterative function and returns an error if there was a problem // with persistence.
[ "iterativeFind", "searches", "for", "the", "node", "with", "the", "provided", "value", ".", "This", "is", "an", "iterative", "function", "and", "returns", "an", "error", "if", "there", "was", "a", "problem", "with", "persistence", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/query.go#L138-L166
train
Workiva/go-datastructures
trie/xfast/xfast.go
isInternal
func isInternal(n *node) bool { if n == nil { return false } return n.entry == nil }
go
func isInternal(n *node) bool { if n == nil { return false } return n.entry == nil }
[ "func", "isInternal", "(", "n", "*", "node", ")", "bool", "{", "if", "n", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "n", ".", "entry", "==", "nil", "\n", "}" ]
// isInternal returns a bool indicating if the provided // node is an internal node, that is, non-leaf node.
[ "isInternal", "returns", "a", "bool", "indicating", "if", "the", "provided", "node", "is", "an", "internal", "node", "that", "is", "non", "-", "leaf", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L51-L56
train
Workiva/go-datastructures
trie/xfast/xfast.go
hasInternal
func hasInternal(n *node) bool { return isInternal(n.children[0]) || isInternal(n.children[1]) }
go
func hasInternal(n *node) bool { return isInternal(n.children[0]) || isInternal(n.children[1]) }
[ "func", "hasInternal", "(", "n", "*", "node", ")", "bool", "{", "return", "isInternal", "(", "n", ".", "children", "[", "0", "]", ")", "||", "isInternal", "(", "n", ".", "children", "[", "1", "]", ")", "\n", "}" ]
// hasInternal returns a bool indicating if the provided // node has a child that is an internal node.
[ "hasInternal", "returns", "a", "bool", "indicating", "if", "the", "provided", "node", "has", "a", "child", "that", "is", "an", "internal", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L60-L62
train
Workiva/go-datastructures
trie/xfast/xfast.go
newNode
func newNode(parent *node, entry Entry) *node { return &node{ children: [2]*node{}, entry: entry, parent: parent, } }
go
func newNode(parent *node, entry Entry) *node { return &node{ children: [2]*node{}, entry: entry, parent: parent, } }
[ "func", "newNode", "(", "parent", "*", "node", ",", "entry", "Entry", ")", "*", "node", "{", "return", "&", "node", "{", "children", ":", "[", "2", "]", "*", "node", "{", "}", ",", "entry", ":", "entry", ",", "parent", ":", "parent", ",", "}", ...
// newNode will allocate and initialize a newNode with the provided // parent and entry. Parent should never be nil, but entry may be // if constructing an internal node.
[ "newNode", "will", "allocate", "and", "initialize", "a", "newNode", "with", "the", "provided", "parent", "and", "entry", ".", "Parent", "should", "never", "be", "nil", "but", "entry", "may", "be", "if", "constructing", "an", "internal", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L131-L137
train
Workiva/go-datastructures
trie/xfast/xfast.go
binarySearchHashMaps
func binarySearchHashMaps(layers []map[uint64]*node, key uint64) (int, *node) { low, high := 0, len(layers)-1 diff := 64 - len(layers) var mid int var node *node for low <= high { mid = (low + high) / 2 n, ok := layers[mid][key&masks[diff+mid]] if ok { node = n low = mid + 1 } else { high = mid - 1 } } return low, node }
go
func binarySearchHashMaps(layers []map[uint64]*node, key uint64) (int, *node) { low, high := 0, len(layers)-1 diff := 64 - len(layers) var mid int var node *node for low <= high { mid = (low + high) / 2 n, ok := layers[mid][key&masks[diff+mid]] if ok { node = n low = mid + 1 } else { high = mid - 1 } } return low, node }
[ "func", "binarySearchHashMaps", "(", "layers", "[", "]", "map", "[", "uint64", "]", "*", "node", ",", "key", "uint64", ")", "(", "int", ",", "*", "node", ")", "{", "low", ",", "high", ":=", "0", ",", "len", "(", "layers", ")", "-", "1", "\n", "...
// binarySearchHashMaps will perform a binary search of the provided // maps to return a node that matches the longest prefix of the provided // key. This will return nil if a match could not be found, which would // also return layer 0. Layer information is useful when determining the // distance from the provided node to the leaves.
[ "binarySearchHashMaps", "will", "perform", "a", "binary", "search", "of", "the", "provided", "maps", "to", "return", "a", "node", "that", "matches", "the", "longest", "prefix", "of", "the", "provided", "key", ".", "This", "will", "return", "nil", "if", "a", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L144-L161
train
Workiva/go-datastructures
trie/xfast/xfast.go
init
func (xft *XFastTrie) init(intType interface{}) { bits := uint8(0) switch intType.(type) { case uint8: bits = 8 case uint16: bits = 16 case uint32: bits = 32 case uint, uint64: bits = 64 default: // we'll panic with a bad value to the constructor. panic(`Invalid universe size provided.`) } xft.layers = make([]map[uint64]*node, bits) xft.bits = bits xft.diff = 64 - bits for i := uint8(0); i < bits; i++ { xft.layers[i] = make(map[uint64]*node, 50) // we can obviously be more intelligent about this. } xft.num = 0 xft.root = newNode(nil, nil) }
go
func (xft *XFastTrie) init(intType interface{}) { bits := uint8(0) switch intType.(type) { case uint8: bits = 8 case uint16: bits = 16 case uint32: bits = 32 case uint, uint64: bits = 64 default: // we'll panic with a bad value to the constructor. panic(`Invalid universe size provided.`) } xft.layers = make([]map[uint64]*node, bits) xft.bits = bits xft.diff = 64 - bits for i := uint8(0); i < bits; i++ { xft.layers[i] = make(map[uint64]*node, 50) // we can obviously be more intelligent about this. } xft.num = 0 xft.root = newNode(nil, nil) }
[ "func", "(", "xft", "*", "XFastTrie", ")", "init", "(", "intType", "interface", "{", "}", ")", "{", "bits", ":=", "uint8", "(", "0", ")", "\n", "switch", "intType", ".", "(", "type", ")", "{", "case", "uint8", ":", "bits", "=", "8", "\n", "case",...
// init will initialize the XFastTrie with the provided byte-size. // I'd prefer generics here, but it is what it is. We expect uints // here when ints would perform just as well, but the public methods // on the XFastTrie all expect uint64, so we expect a uint in the // constructor for consistency's sake.
[ "init", "will", "initialize", "the", "XFastTrie", "with", "the", "provided", "byte", "-", "size", ".", "I", "d", "prefer", "generics", "here", "but", "it", "is", "what", "it", "is", ".", "We", "expect", "uints", "here", "when", "ints", "would", "perform"...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L216-L240
train
Workiva/go-datastructures
trie/xfast/xfast.go
walkUpSuccessor
func (xft *XFastTrie) walkUpSuccessor(root, node, successor *node) { n := successor.parent for n != nil && n != root { // we don't really want to overwrite existing internal nodes, // or where the child is a leaf that is the successor if !isInternal(n.children[0]) && n.children[0] != successor { n.children[0] = node } n = n.parent } }
go
func (xft *XFastTrie) walkUpSuccessor(root, node, successor *node) { n := successor.parent for n != nil && n != root { // we don't really want to overwrite existing internal nodes, // or where the child is a leaf that is the successor if !isInternal(n.children[0]) && n.children[0] != successor { n.children[0] = node } n = n.parent } }
[ "func", "(", "xft", "*", "XFastTrie", ")", "walkUpSuccessor", "(", "root", ",", "node", ",", "successor", "*", "node", ")", "{", "n", ":=", "successor", ".", "parent", "\n", "for", "n", "!=", "nil", "&&", "n", "!=", "root", "{", "if", "!", "isInter...
// walkUpSuccessor will walk up the successor branch setting // the predecessor where possible. This breaks when a common // ancestor between successor and node is found, ie, the root.
[ "walkUpSuccessor", "will", "walk", "up", "the", "successor", "branch", "setting", "the", "predecessor", "where", "possible", ".", "This", "breaks", "when", "a", "common", "ancestor", "between", "successor", "and", "node", "is", "found", "ie", "the", "root", "....
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L383-L393
train
Workiva/go-datastructures
trie/xfast/xfast.go
walkUpPredecessor
func (xft *XFastTrie) walkUpPredecessor(root, node, predecessor *node) { n := predecessor.parent for n != nil && n != root { if !isInternal(n.children[1]) && n.children[1] != predecessor { n.children[1] = node } n = n.parent } }
go
func (xft *XFastTrie) walkUpPredecessor(root, node, predecessor *node) { n := predecessor.parent for n != nil && n != root { if !isInternal(n.children[1]) && n.children[1] != predecessor { n.children[1] = node } n = n.parent } }
[ "func", "(", "xft", "*", "XFastTrie", ")", "walkUpPredecessor", "(", "root", ",", "node", ",", "predecessor", "*", "node", ")", "{", "n", ":=", "predecessor", ".", "parent", "\n", "for", "n", "!=", "nil", "&&", "n", "!=", "root", "{", "if", "!", "i...
// walkUpPredecessor will walk up the predecessor branch setting // the successor where possible. This breaks when a common // ancestor between predecessor and node is found, ie, the root.
[ "walkUpPredecessor", "will", "walk", "up", "the", "predecessor", "branch", "setting", "the", "successor", "where", "possible", ".", "This", "breaks", "when", "a", "common", "ancestor", "between", "predecessor", "and", "node", "is", "found", "ie", "the", "root", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L398-L406
train
Workiva/go-datastructures
trie/xfast/xfast.go
walkUpNode
func (xft *XFastTrie) walkUpNode(root, node, predecessor, successor *node) { n := node.parent for n != nil && n != root { if !isInternal(n.children[1]) && n.children[1] != successor && n.children[1] != node { n.children[1] = successor } if !isInternal(n.children[0]) && n.children[0] != predecessor && n.children[0] != node { n.children[0] = predecessor } n = n.parent } }
go
func (xft *XFastTrie) walkUpNode(root, node, predecessor, successor *node) { n := node.parent for n != nil && n != root { if !isInternal(n.children[1]) && n.children[1] != successor && n.children[1] != node { n.children[1] = successor } if !isInternal(n.children[0]) && n.children[0] != predecessor && n.children[0] != node { n.children[0] = predecessor } n = n.parent } }
[ "func", "(", "xft", "*", "XFastTrie", ")", "walkUpNode", "(", "root", ",", "node", ",", "predecessor", ",", "successor", "*", "node", ")", "{", "n", ":=", "node", ".", "parent", "\n", "for", "n", "!=", "nil", "&&", "n", "!=", "root", "{", "if", "...
// walkUpNode will walk up the newly created branch and set predecessor // and successor where possible. If predecessor or successor are nil, // this will set nil where possible.
[ "walkUpNode", "will", "walk", "up", "the", "newly", "created", "branch", "and", "set", "predecessor", "and", "successor", "where", "possible", ".", "If", "predecessor", "or", "successor", "are", "nil", "this", "will", "set", "nil", "where", "possible", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L411-L422
train
Workiva/go-datastructures
trie/xfast/xfast.go
predecessor
func (xft *XFastTrie) predecessor(key uint64) *node { if xft.root == nil || xft.max == nil { // no successor if no nodes return nil } if key >= xft.max.entry.Key() { return xft.max } if key < xft.min.entry.Key() { return nil } n := xft.layers[xft.bits-1][key] if n != nil { return n } layer, n := binarySearchHashMaps(xft.layers, key) if n == nil && layer > 1 { return nil } else if n == nil { n = xft.root } if isInternal(n.children[0]) && isLeaf(n.children[1]) { return n.children[1].children[0] } return n.children[0] }
go
func (xft *XFastTrie) predecessor(key uint64) *node { if xft.root == nil || xft.max == nil { // no successor if no nodes return nil } if key >= xft.max.entry.Key() { return xft.max } if key < xft.min.entry.Key() { return nil } n := xft.layers[xft.bits-1][key] if n != nil { return n } layer, n := binarySearchHashMaps(xft.layers, key) if n == nil && layer > 1 { return nil } else if n == nil { n = xft.root } if isInternal(n.children[0]) && isLeaf(n.children[1]) { return n.children[1].children[0] } return n.children[0] }
[ "func", "(", "xft", "*", "XFastTrie", ")", "predecessor", "(", "key", "uint64", ")", "*", "node", "{", "if", "xft", ".", "root", "==", "nil", "||", "xft", ".", "max", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "key", ">=", "xft", ...
// predecessor will find the node equal to or immediately less // than the provided key.
[ "predecessor", "will", "find", "the", "node", "equal", "to", "or", "immediately", "less", "than", "the", "provided", "key", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L510-L539
train
Workiva/go-datastructures
trie/xfast/xfast.go
Iter
func (xft *XFastTrie) Iter(key uint64) *Iterator { return &Iterator{ n: xft.successor(key), first: true, } }
go
func (xft *XFastTrie) Iter(key uint64) *Iterator { return &Iterator{ n: xft.successor(key), first: true, } }
[ "func", "(", "xft", "*", "XFastTrie", ")", "Iter", "(", "key", "uint64", ")", "*", "Iterator", "{", "return", "&", "Iterator", "{", "n", ":", "xft", ".", "successor", "(", "key", ")", ",", "first", ":", "true", ",", "}", "\n", "}" ]
// Iter will return an iterator that will iterate over all values // equal to or immediately greater than the provided key. Iterator // will iterate successor relationships.
[ "Iter", "will", "return", "an", "iterator", "that", "will", "iterate", "over", "all", "values", "equal", "to", "or", "immediately", "greater", "than", "the", "provided", "key", ".", "Iterator", "will", "iterate", "successor", "relationships", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L601-L606
train
tucnak/telebot
api.go
Raw
func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) { url := fmt.Sprintf("%s/bot%s/%s", b.URL, b.Token, method) var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(payload); err != nil { return []byte{}, wrapSystem(err) } resp, err := b.client.Post(url, "application/json", &buf) if err != nil { return []byte{}, errors.Wrap(err, "http.Post failed") } resp.Close = true defer resp.Body.Close() json, err := ioutil.ReadAll(resp.Body) if err != nil { return []byte{}, wrapSystem(err) } return json, nil }
go
func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) { url := fmt.Sprintf("%s/bot%s/%s", b.URL, b.Token, method) var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(payload); err != nil { return []byte{}, wrapSystem(err) } resp, err := b.client.Post(url, "application/json", &buf) if err != nil { return []byte{}, errors.Wrap(err, "http.Post failed") } resp.Close = true defer resp.Body.Close() json, err := ioutil.ReadAll(resp.Body) if err != nil { return []byte{}, wrapSystem(err) } return json, nil }
[ "func", "(", "b", "*", "Bot", ")", "Raw", "(", "method", "string", ",", "payload", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"%s/bot%s/%s\"", ",", "b", ".", "URL", ",", ...
// Raw lets you call any method of Bot API manually.
[ "Raw", "lets", "you", "call", "any", "method", "of", "Bot", "API", "manually", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/api.go#L21-L41
train
tucnak/telebot
message.go
IsForwarded
func (m *Message) IsForwarded() bool { return m.OriginalSender != nil || m.OriginalChat != nil }
go
func (m *Message) IsForwarded() bool { return m.OriginalSender != nil || m.OriginalChat != nil }
[ "func", "(", "m", "*", "Message", ")", "IsForwarded", "(", ")", "bool", "{", "return", "m", ".", "OriginalSender", "!=", "nil", "||", "m", ".", "OriginalChat", "!=", "nil", "\n", "}" ]
// IsForwarded says whether message is forwarded copy of another // message or not.
[ "IsForwarded", "says", "whether", "message", "is", "forwarded", "copy", "of", "another", "message", "or", "not", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L223-L225
train
tucnak/telebot
message.go
FromGroup
func (m *Message) FromGroup() bool { return m.Chat.Type == ChatGroup || m.Chat.Type == ChatSuperGroup }
go
func (m *Message) FromGroup() bool { return m.Chat.Type == ChatGroup || m.Chat.Type == ChatSuperGroup }
[ "func", "(", "m", "*", "Message", ")", "FromGroup", "(", ")", "bool", "{", "return", "m", ".", "Chat", ".", "Type", "==", "ChatGroup", "||", "m", ".", "Chat", ".", "Type", "==", "ChatSuperGroup", "\n", "}" ]
// FromGroup returns true, if message came from a group OR // a super group.
[ "FromGroup", "returns", "true", "if", "message", "came", "from", "a", "group", "OR", "a", "super", "group", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L239-L241
train
tucnak/telebot
message.go
IsService
func (m *Message) IsService() bool { fact := false fact = fact || m.UserJoined != nil fact = fact || len(m.UsersJoined) > 0 fact = fact || m.UserLeft != nil fact = fact || m.NewGroupTitle != "" fact = fact || m.NewGroupPhoto != nil fact = fact || m.GroupPhotoDeleted fact = fact || m.GroupCreated || m.SuperGroupCreated fact = fact || (m.MigrateTo != m.MigrateFrom) return fact }
go
func (m *Message) IsService() bool { fact := false fact = fact || m.UserJoined != nil fact = fact || len(m.UsersJoined) > 0 fact = fact || m.UserLeft != nil fact = fact || m.NewGroupTitle != "" fact = fact || m.NewGroupPhoto != nil fact = fact || m.GroupPhotoDeleted fact = fact || m.GroupCreated || m.SuperGroupCreated fact = fact || (m.MigrateTo != m.MigrateFrom) return fact }
[ "func", "(", "m", "*", "Message", ")", "IsService", "(", ")", "bool", "{", "fact", ":=", "false", "\n", "fact", "=", "fact", "||", "m", ".", "UserJoined", "!=", "nil", "\n", "fact", "=", "fact", "||", "len", "(", "m", ".", "UsersJoined", ")", ">"...
// IsService returns true, if message is a service message, // returns false otherwise. // // Service messages are automatically sent messages, which // typically occur on some global action. For instance, when // anyone leaves the chat or chat title changes.
[ "IsService", "returns", "true", "if", "message", "is", "a", "service", "message", "returns", "false", "otherwise", ".", "Service", "messages", "are", "automatically", "sent", "messages", "which", "typically", "occur", "on", "some", "global", "action", ".", "For"...
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L254-L267
train
tucnak/telebot
media.go
UnmarshalJSON
func (p *Photo) UnmarshalJSON(jsonStr []byte) error { var hq photoSize if jsonStr[0] == '{' { if err := json.Unmarshal(jsonStr, &hq); err != nil { return err } } else { var sizes []photoSize if err := json.Unmarshal(jsonStr, &sizes); err != nil { return err } hq = sizes[len(sizes)-1] } p.File = hq.File p.Width = hq.Width p.Height = hq.Height return nil }
go
func (p *Photo) UnmarshalJSON(jsonStr []byte) error { var hq photoSize if jsonStr[0] == '{' { if err := json.Unmarshal(jsonStr, &hq); err != nil { return err } } else { var sizes []photoSize if err := json.Unmarshal(jsonStr, &sizes); err != nil { return err } hq = sizes[len(sizes)-1] } p.File = hq.File p.Width = hq.Width p.Height = hq.Height return nil }
[ "func", "(", "p", "*", "Photo", ")", "UnmarshalJSON", "(", "jsonStr", "[", "]", "byte", ")", "error", "{", "var", "hq", "photoSize", "\n", "if", "jsonStr", "[", "0", "]", "==", "'{'", "{", "if", "err", ":=", "json", ".", "Unmarshal", "(", "jsonStr"...
// UnmarshalJSON is custom unmarshaller required to abstract // away the hassle of treating different thumbnail sizes. // Instead, Telebot chooses the hi-res one and just sticks to // it. // // I really do find it a beautiful solution.
[ "UnmarshalJSON", "is", "custom", "unmarshaller", "required", "to", "abstract", "away", "the", "hassle", "of", "treating", "different", "thumbnail", "sizes", ".", "Instead", "Telebot", "chooses", "the", "hi", "-", "res", "one", "and", "just", "sticks", "to", "i...
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/media.go#L50-L72
train
tucnak/telebot
webhook.go
ServeHTTP
func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { var update Update err := json.NewDecoder(r.Body).Decode(&update) if err != nil { h.bot.debug(fmt.Errorf("cannot decode update: %v", err)) return } h.dest <- update }
go
func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { var update Update err := json.NewDecoder(r.Body).Decode(&update) if err != nil { h.bot.debug(fmt.Errorf("cannot decode update: %v", err)) return } h.dest <- update }
[ "func", "(", "h", "*", "Webhook", ")", "ServeHTTP", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "var", "update", "Update", "\n", "err", ":=", "json", ".", "NewDecoder", "(", "r", ".", "Body", ")", ".", ...
// The handler simply reads the update from the body of the requests // and writes them to the update channel.
[ "The", "handler", "simply", "reads", "the", "update", "from", "the", "body", "of", "the", "requests", "and", "writes", "them", "to", "the", "update", "channel", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/webhook.go#L142-L150
train
tucnak/telebot
admin.go
AdminRights
func AdminRights() Rights { return Rights{ true, true, true, true, true, // 1-5 true, true, true, true, true, // 6-10 true, true, true} // 11-13 }
go
func AdminRights() Rights { return Rights{ true, true, true, true, true, // 1-5 true, true, true, true, true, // 6-10 true, true, true} // 11-13 }
[ "func", "AdminRights", "(", ")", "Rights", "{", "return", "Rights", "{", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", ",", "true", "}", "\n"...
// AdminRights could be used to promote user to admin.
[ "AdminRights", "could", "be", "used", "to", "promote", "user", "to", "admin", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L45-L50
train
tucnak/telebot
admin.go
Ban
func (b *Bot) Ban(chat *Chat, member *ChatMember) error { params := map[string]string{ "chat_id": chat.Recipient(), "user_id": member.User.Recipient(), "until_date": strconv.FormatInt(member.RestrictedUntil, 10), } respJSON, err := b.Raw("kickChatMember", params) if err != nil { return err } return extractOkResponse(respJSON) }
go
func (b *Bot) Ban(chat *Chat, member *ChatMember) error { params := map[string]string{ "chat_id": chat.Recipient(), "user_id": member.User.Recipient(), "until_date": strconv.FormatInt(member.RestrictedUntil, 10), } respJSON, err := b.Raw("kickChatMember", params) if err != nil { return err } return extractOkResponse(respJSON) }
[ "func", "(", "b", "*", "Bot", ")", "Ban", "(", "chat", "*", "Chat", ",", "member", "*", "ChatMember", ")", "error", "{", "params", ":=", "map", "[", "string", "]", "string", "{", "\"chat_id\"", ":", "chat", ".", "Recipient", "(", ")", ",", "\"user_...
// Ban will ban user from chat until `member.RestrictedUntil`.
[ "Ban", "will", "ban", "user", "from", "chat", "until", "member", ".", "RestrictedUntil", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L58-L71
train
tucnak/telebot
admin.go
Unban
func (b *Bot) Unban(chat *Chat, user *User) error { params := map[string]string{ "chat_id": chat.Recipient(), "user_id": user.Recipient(), } respJSON, err := b.Raw("unbanChatMember", params) if err != nil { return err } return extractOkResponse(respJSON) }
go
func (b *Bot) Unban(chat *Chat, user *User) error { params := map[string]string{ "chat_id": chat.Recipient(), "user_id": user.Recipient(), } respJSON, err := b.Raw("unbanChatMember", params) if err != nil { return err } return extractOkResponse(respJSON) }
[ "func", "(", "b", "*", "Bot", ")", "Unban", "(", "chat", "*", "Chat", ",", "user", "*", "User", ")", "error", "{", "params", ":=", "map", "[", "string", "]", "string", "{", "\"chat_id\"", ":", "chat", ".", "Recipient", "(", ")", ",", "\"user_id\"",...
// Unban will unban user from chat, who would have thought eh?
[ "Unban", "will", "unban", "user", "from", "chat", "who", "would", "have", "thought", "eh?" ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L74-L86
train
tucnak/telebot
admin.go
AdminsOf
func (b *Bot) AdminsOf(chat *Chat) ([]ChatMember, error) { params := map[string]string{ "chat_id": chat.Recipient(), } respJSON, err := b.Raw("getChatAdministrators", params) if err != nil { return nil, err } var resp struct { Ok bool Result []ChatMember Description string `json:"description"` } err = json.Unmarshal(respJSON, &resp) if err != nil { return nil, errors.Wrap(err, "bad response json") } if !resp.Ok { return nil, errors.Errorf("api error: %s", resp.Description) } return resp.Result, nil }
go
func (b *Bot) AdminsOf(chat *Chat) ([]ChatMember, error) { params := map[string]string{ "chat_id": chat.Recipient(), } respJSON, err := b.Raw("getChatAdministrators", params) if err != nil { return nil, err } var resp struct { Ok bool Result []ChatMember Description string `json:"description"` } err = json.Unmarshal(respJSON, &resp) if err != nil { return nil, errors.Wrap(err, "bad response json") } if !resp.Ok { return nil, errors.Errorf("api error: %s", resp.Description) } return resp.Result, nil }
[ "func", "(", "b", "*", "Bot", ")", "AdminsOf", "(", "chat", "*", "Chat", ")", "(", "[", "]", "ChatMember", ",", "error", ")", "{", "params", ":=", "map", "[", "string", "]", "string", "{", "\"chat_id\"", ":", "chat", ".", "Recipient", "(", ")", "...
// AdminsOf return a member list of chat admins. // // On success, returns an Array of ChatMember objects that // contains information about all chat administrators except other bots. // If the chat is a group or a supergroup and // no administrators were appointed, only the creator will be returned.
[ "AdminsOf", "return", "a", "member", "list", "of", "chat", "admins", ".", "On", "success", "returns", "an", "Array", "of", "ChatMember", "objects", "that", "contains", "information", "about", "all", "chat", "administrators", "except", "other", "bots", ".", "If...
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L150-L176
train
tucnak/telebot
poller.go
NewMiddlewarePoller
func NewMiddlewarePoller(original Poller, filter func(*Update) bool) *MiddlewarePoller { return &MiddlewarePoller{ Poller: original, Filter: filter, } }
go
func NewMiddlewarePoller(original Poller, filter func(*Update) bool) *MiddlewarePoller { return &MiddlewarePoller{ Poller: original, Filter: filter, } }
[ "func", "NewMiddlewarePoller", "(", "original", "Poller", ",", "filter", "func", "(", "*", "Update", ")", "bool", ")", "*", "MiddlewarePoller", "{", "return", "&", "MiddlewarePoller", "{", "Poller", ":", "original", ",", "Filter", ":", "filter", ",", "}", ...
// NewMiddlewarePoller wait for it... constructs a new middleware poller.
[ "NewMiddlewarePoller", "wait", "for", "it", "...", "constructs", "a", "new", "middleware", "poller", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L41-L46
train
tucnak/telebot
poller.go
Poll
func (p *MiddlewarePoller) Poll(b *Bot, dest chan Update, stop chan struct{}) { cap := 1 if p.Capacity > 1 { cap = p.Capacity } middle := make(chan Update, cap) stopPoller := make(chan struct{}) go p.Poller.Poll(b, middle, stopPoller) for { select { // call to stop case <-stop: stopPoller <- struct{}{} // poller is done case <-stopPoller: close(stop) return case upd := <-middle: if p.Filter(&upd) { dest <- upd } } } }
go
func (p *MiddlewarePoller) Poll(b *Bot, dest chan Update, stop chan struct{}) { cap := 1 if p.Capacity > 1 { cap = p.Capacity } middle := make(chan Update, cap) stopPoller := make(chan struct{}) go p.Poller.Poll(b, middle, stopPoller) for { select { // call to stop case <-stop: stopPoller <- struct{}{} // poller is done case <-stopPoller: close(stop) return case upd := <-middle: if p.Filter(&upd) { dest <- upd } } } }
[ "func", "(", "p", "*", "MiddlewarePoller", ")", "Poll", "(", "b", "*", "Bot", ",", "dest", "chan", "Update", ",", "stop", "chan", "struct", "{", "}", ")", "{", "cap", ":=", "1", "\n", "if", "p", ".", "Capacity", ">", "1", "{", "cap", "=", "p", ...
// Poll sieves updates through middleware filter.
[ "Poll", "sieves", "updates", "through", "middleware", "filter", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L49-L77
train
tucnak/telebot
poller.go
Poll
func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) { go func(stop chan struct{}) { <-stop close(stop) }(stop) for { updates, err := b.getUpdates(p.LastUpdateID+1, p.Timeout) if err != nil { b.debug(ErrCouldNotUpdate) continue } for _, update := range updates { p.LastUpdateID = update.ID dest <- update } } }
go
func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) { go func(stop chan struct{}) { <-stop close(stop) }(stop) for { updates, err := b.getUpdates(p.LastUpdateID+1, p.Timeout) if err != nil { b.debug(ErrCouldNotUpdate) continue } for _, update := range updates { p.LastUpdateID = update.ID dest <- update } } }
[ "func", "(", "p", "*", "LongPoller", ")", "Poll", "(", "b", "*", "Bot", ",", "dest", "chan", "Update", ",", "stop", "chan", "struct", "{", "}", ")", "{", "go", "func", "(", "stop", "chan", "struct", "{", "}", ")", "{", "<-", "stop", "\n", "clos...
// Poll does long polling.
[ "Poll", "does", "long", "polling", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L87-L106
train
tucnak/telebot
inline.go
MarshalJSON
func (results Results) MarshalJSON() ([]byte, error) { for _, result := range results { if result.ResultID() == "" { result.SetResultID(fmt.Sprintf("%d", &result)) } if err := inferIQR(result); err != nil { return nil, err } } return json.Marshal([]Result(results)) }
go
func (results Results) MarshalJSON() ([]byte, error) { for _, result := range results { if result.ResultID() == "" { result.SetResultID(fmt.Sprintf("%d", &result)) } if err := inferIQR(result); err != nil { return nil, err } } return json.Marshal([]Result(results)) }
[ "func", "(", "results", "Results", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "_", ",", "result", ":=", "range", "results", "{", "if", "result", ".", "ResultID", "(", ")", "==", "\"\"", "{", "result", ".", ...
// MarshalJSON makes sure IQRs have proper IDs and Type variables set.
[ "MarshalJSON", "makes", "sure", "IQRs", "have", "proper", "IDs", "and", "Type", "variables", "set", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/inline.go#L75-L87
train
tucnak/telebot
filters.go
Add
func (c *Chain) Add(filter interface{}) { switch filter.(type) { case Filter: break case FilterFunc: break case func(*Update) bool: break default: panic("telebot: unsupported filter type") } c.Filters = append(c.Filters, filter) }
go
func (c *Chain) Add(filter interface{}) { switch filter.(type) { case Filter: break case FilterFunc: break case func(*Update) bool: break default: panic("telebot: unsupported filter type") } c.Filters = append(c.Filters, filter) }
[ "func", "(", "c", "*", "Chain", ")", "Add", "(", "filter", "interface", "{", "}", ")", "{", "switch", "filter", ".", "(", "type", ")", "{", "case", "Filter", ":", "break", "\n", "case", "FilterFunc", ":", "break", "\n", "case", "func", "(", "*", ...
// Add accepts either Filter interface or FilterFunc
[ "Add", "accepts", "either", "Filter", "interface", "or", "FilterFunc" ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/filters.go#L53-L66
train
tucnak/telebot
bot.go
NewBot
func NewBot(pref Settings) (*Bot, error) { if pref.Updates == 0 { pref.Updates = 100 } client := pref.Client if client == nil { client = http.DefaultClient } if pref.URL == "" { pref.URL = DefaultApiURL } bot := &Bot{ Token: pref.Token, URL: pref.URL, Updates: make(chan Update, pref.Updates), Poller: pref.Poller, handlers: make(map[string]interface{}), stop: make(chan struct{}), reporter: pref.Reporter, client: client, } user, err := bot.getMe() if err != nil { return nil, err } bot.Me = user return bot, nil }
go
func NewBot(pref Settings) (*Bot, error) { if pref.Updates == 0 { pref.Updates = 100 } client := pref.Client if client == nil { client = http.DefaultClient } if pref.URL == "" { pref.URL = DefaultApiURL } bot := &Bot{ Token: pref.Token, URL: pref.URL, Updates: make(chan Update, pref.Updates), Poller: pref.Poller, handlers: make(map[string]interface{}), stop: make(chan struct{}), reporter: pref.Reporter, client: client, } user, err := bot.getMe() if err != nil { return nil, err } bot.Me = user return bot, nil }
[ "func", "NewBot", "(", "pref", "Settings", ")", "(", "*", "Bot", ",", "error", ")", "{", "if", "pref", ".", "Updates", "==", "0", "{", "pref", ".", "Updates", "=", "100", "\n", "}", "\n", "client", ":=", "pref", ".", "Client", "\n", "if", "client...
// NewBot does try to build a Bot with token `token`, which // is a secret API key assigned to particular bot.
[ "NewBot", "does", "try", "to", "build", "a", "Bot", "with", "token", "token", "which", "is", "a", "secret", "API", "key", "assigned", "to", "particular", "bot", "." ]
8c1c512262f2f97b1212eb1751efb498d2038a0c
https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L18-L51
train