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
numerics/optimization/nelder_mead.go
euclideanDistance
func (nm *nmVertex) euclideanDistance(other *nmVertex) float64 { sum := float64(0) // first we want to sum all the distances between the points for i, otherPoint := range other.vars { // distance between points is defined by (qi-ri)^2 sum += math.Pow(otherPoint-nm.vars[i], 2) } return math.Sqrt(sum) }
go
func (nm *nmVertex) euclideanDistance(other *nmVertex) float64 { sum := float64(0) // first we want to sum all the distances between the points for i, otherPoint := range other.vars { // distance between points is defined by (qi-ri)^2 sum += math.Pow(otherPoint-nm.vars[i], 2) } return math.Sqrt(sum) }
[ "func", "(", "nm", "*", "nmVertex", ")", "euclideanDistance", "(", "other", "*", "nmVertex", ")", "float64", "{", "sum", ":=", "float64", "(", "0", ")", "\n", "for", "i", ",", "otherPoint", ":=", "range", "other", ".", "vars", "{", "sum", "+=", "math...
// euclideanDistance determines the euclidean distance between two points.
[ "euclideanDistance", "determines", "the", "euclidean", "distance", "between", "two", "points", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L301-L310
train
Workiva/go-datastructures
numerics/optimization/nelder_mead.go
reflect
func (nm *nelderMead) reflect(vertices vertices, midpoint *nmVertex) *nmVertex { toScalar := midpoint.subtract(nm.lastVertex(vertices)) toScalar = toScalar.multiply(alpha) toScalar = midpoint.add(toScalar) return nm.evaluateWithConstraints(vertices, toScalar) }
go
func (nm *nelderMead) reflect(vertices vertices, midpoint *nmVertex) *nmVertex { toScalar := midpoint.subtract(nm.lastVertex(vertices)) toScalar = toScalar.multiply(alpha) toScalar = midpoint.add(toScalar) return nm.evaluateWithConstraints(vertices, toScalar) }
[ "func", "(", "nm", "*", "nelderMead", ")", "reflect", "(", "vertices", "vertices", ",", "midpoint", "*", "nmVertex", ")", "*", "nmVertex", "{", "toScalar", ":=", "midpoint", ".", "subtract", "(", "nm", ".", "lastVertex", "(", "vertices", ")", ")", "\n", ...
// reflect will find the reflection point between the two best guesses // with the provided midpoint.
[ "reflect", "will", "find", "the", "reflection", "point", "between", "the", "two", "best", "guesses", "with", "the", "provided", "midpoint", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L365-L370
train
Workiva/go-datastructures
numerics/optimization/nelder_mead.go
checkIteration
func (nm *nelderMead) checkIteration(vertices vertices) bool { // this will never be true for += inf if math.Abs(vertices[0].result-nm.config.Target) < delta { return false } best := vertices[0] // here we are checking distance convergence. If all vertices // are near convergence, that is they are all within some delta // from the expected value, we can go ahead and quit early. This // can only be performed on convergence checks, not for finding // min/max. if !isInf(nm.config.Target) { for _, v := range vertices[1:] { if math.Abs(best.distance-v.distance) >= delta { return true } } } // next we want to check to see if the changes in our polytopes // dip below some threshold. That is, we want to look at the // euclidean distances between the best guess and all the other // guesses to see if they are converged upon some point. If // all of the vertices have converged close enough, it may be // worth it to cease iteration. for _, v := range vertices[1:] { if best.euclideanDistance(v) >= delta { return true } } return false }
go
func (nm *nelderMead) checkIteration(vertices vertices) bool { // this will never be true for += inf if math.Abs(vertices[0].result-nm.config.Target) < delta { return false } best := vertices[0] // here we are checking distance convergence. If all vertices // are near convergence, that is they are all within some delta // from the expected value, we can go ahead and quit early. This // can only be performed on convergence checks, not for finding // min/max. if !isInf(nm.config.Target) { for _, v := range vertices[1:] { if math.Abs(best.distance-v.distance) >= delta { return true } } } // next we want to check to see if the changes in our polytopes // dip below some threshold. That is, we want to look at the // euclidean distances between the best guess and all the other // guesses to see if they are converged upon some point. If // all of the vertices have converged close enough, it may be // worth it to cease iteration. for _, v := range vertices[1:] { if best.euclideanDistance(v) >= delta { return true } } return false }
[ "func", "(", "nm", "*", "nelderMead", ")", "checkIteration", "(", "vertices", "vertices", ")", "bool", "{", "if", "math", ".", "Abs", "(", "vertices", "[", "0", "]", ".", "result", "-", "nm", ".", "config", ".", "Target", ")", "<", "delta", "{", "r...
// checkIteration checks some key values to determine if // iteration should be complete. Returns false if iteration // should be terminated and true if iteration should continue.
[ "checkIteration", "checks", "some", "key", "values", "to", "determine", "if", "iteration", "should", "be", "complete", ".", "Returns", "false", "if", "iteration", "should", "be", "terminated", "and", "true", "if", "iteration", "should", "continue", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L419-L452
train
Workiva/go-datastructures
numerics/optimization/nelder_mead.go
NelderMead
func NelderMead(config NelderMeadConfiguration) []float64 { nm := newNelderMead(config) nm.evaluate() return nm.results.vertices[0].vars }
go
func NelderMead(config NelderMeadConfiguration) []float64 { nm := newNelderMead(config) nm.evaluate() return nm.results.vertices[0].vars }
[ "func", "NelderMead", "(", "config", "NelderMeadConfiguration", ")", "[", "]", "float64", "{", "nm", ":=", "newNelderMead", "(", "config", ")", "\n", "nm", ".", "evaluate", "(", ")", "\n", "return", "nm", ".", "results", ".", "vertices", "[", "0", "]", ...
// NelderMead takes a configuration and returns a list // of floats that can be plugged into the provided function // to converge at the target value.
[ "NelderMead", "takes", "a", "configuration", "and", "returns", "a", "list", "of", "floats", "that", "can", "be", "plugged", "into", "the", "provided", "function", "to", "converge", "at", "the", "target", "value", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L555-L559
train
Workiva/go-datastructures
sort/symmerge.go
symSearch
func symSearch(u, w Comparators) int { start, stop, p := 0, len(u), len(w)-1 for start < stop { mid := (start + stop) / 2 if u[mid].Compare(w[p-mid]) <= 0 { start = mid + 1 } else { stop = mid } } return start }
go
func symSearch(u, w Comparators) int { start, stop, p := 0, len(u), len(w)-1 for start < stop { mid := (start + stop) / 2 if u[mid].Compare(w[p-mid]) <= 0 { start = mid + 1 } else { stop = mid } } return start }
[ "func", "symSearch", "(", "u", ",", "w", "Comparators", ")", "int", "{", "start", ",", "stop", ",", "p", ":=", "0", ",", "len", "(", "u", ")", ",", "len", "(", "w", ")", "-", "1", "\n", "for", "start", "<", "stop", "{", "mid", ":=", "(", "s...
// symSearch is like symBinarySearch but operates // on two sorted lists instead of a sorted list and an index. // It's duplication of code but you buy performance.
[ "symSearch", "is", "like", "symBinarySearch", "but", "operates", "on", "two", "sorted", "lists", "instead", "of", "a", "sorted", "list", "and", "an", "index", ".", "It", "s", "duplication", "of", "code", "but", "you", "buy", "performance", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L11-L23
train
Workiva/go-datastructures
sort/symmerge.go
swap
func swap(u, w Comparators, index int) { for i := index; i < len(u); i++ { u[i], w[i-index] = w[i-index], u[i] } }
go
func swap(u, w Comparators, index int) { for i := index; i < len(u); i++ { u[i], w[i-index] = w[i-index], u[i] } }
[ "func", "swap", "(", "u", ",", "w", "Comparators", ",", "index", "int", ")", "{", "for", "i", ":=", "index", ";", "i", "<", "len", "(", "u", ")", ";", "i", "++", "{", "u", "[", "i", "]", ",", "w", "[", "i", "-", "index", "]", "=", "w", ...
// swap will swap positions of the two lists from index // to the end of the list. It expects that these lists // are the same size or one different.
[ "swap", "will", "swap", "positions", "of", "the", "two", "lists", "from", "index", "to", "the", "end", "of", "the", "list", ".", "It", "expects", "that", "these", "lists", "are", "the", "same", "size", "or", "one", "different", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L28-L32
train
Workiva/go-datastructures
sort/symmerge.go
decomposeForSymMerge
func decomposeForSymMerge(length int, comparators Comparators) (v1 Comparators, w Comparators, v2 Comparators) { if length >= len(comparators) { panic(`INCORRECT PARAMS FOR SYM MERGE.`) } overhang := (len(comparators) - length) / 2 v1 = comparators[:overhang] w = comparators[overhang : overhang+length] v2 = comparators[overhang+length:] return }
go
func decomposeForSymMerge(length int, comparators Comparators) (v1 Comparators, w Comparators, v2 Comparators) { if length >= len(comparators) { panic(`INCORRECT PARAMS FOR SYM MERGE.`) } overhang := (len(comparators) - length) / 2 v1 = comparators[:overhang] w = comparators[overhang : overhang+length] v2 = comparators[overhang+length:] return }
[ "func", "decomposeForSymMerge", "(", "length", "int", ",", "comparators", "Comparators", ")", "(", "v1", "Comparators", ",", "w", "Comparators", ",", "v2", "Comparators", ")", "{", "if", "length", ">=", "len", "(", "comparators", ")", "{", "panic", "(", "`...
// decomposeForSymMerge pulls an active site out of the list // of length in size. W becomes the active site for future sym // merges and v1, v2 are decomposed and split among the other // list to be merged and w.
[ "decomposeForSymMerge", "pulls", "an", "active", "site", "out", "of", "the", "list", "of", "length", "in", "size", ".", "W", "becomes", "the", "active", "site", "for", "future", "sym", "merges", "and", "v1", "v2", "are", "decomposed", "and", "split", "amon...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L38-L51
train
Workiva/go-datastructures
sort/symmerge.go
symBinarySearch
func symBinarySearch(u Comparators, start, stop, total int) int { for start < stop { mid := (start + stop) / 2 if u[mid].Compare(u[total-mid]) <= 0 { start = mid + 1 } else { stop = mid } } return start }
go
func symBinarySearch(u Comparators, start, stop, total int) int { for start < stop { mid := (start + stop) / 2 if u[mid].Compare(u[total-mid]) <= 0 { start = mid + 1 } else { stop = mid } } return start }
[ "func", "symBinarySearch", "(", "u", "Comparators", ",", "start", ",", "stop", ",", "total", "int", ")", "int", "{", "for", "start", "<", "stop", "{", "mid", ":=", "(", "start", "+", "stop", ")", "/", "2", "\n", "if", "u", "[", "mid", "]", ".", ...
// symBinarySearch will perform a binary search between the provided // indices and find the index at which a rotation should occur.
[ "symBinarySearch", "will", "perform", "a", "binary", "search", "between", "the", "provided", "indices", "and", "find", "the", "index", "at", "which", "a", "rotation", "should", "occur", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L55-L66
train
Workiva/go-datastructures
sort/symmerge.go
symSwap
func symSwap(u Comparators, start1, start2, end int) { for i := 0; i < end; i++ { u[start1+i], u[start2+i] = u[start2+i], u[start1+i] } }
go
func symSwap(u Comparators, start1, start2, end int) { for i := 0; i < end; i++ { u[start1+i], u[start2+i] = u[start2+i], u[start1+i] } }
[ "func", "symSwap", "(", "u", "Comparators", ",", "start1", ",", "start2", ",", "end", "int", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "end", ";", "i", "++", "{", "u", "[", "start1", "+", "i", "]", ",", "u", "[", "start2", "+", "i", "...
// symSwap will perform a rotation or swap between the provided // indices. Again, there is duplication here with swap, but // we are buying performance.
[ "symSwap", "will", "perform", "a", "rotation", "or", "swap", "between", "the", "provided", "indices", ".", "Again", "there", "is", "duplication", "here", "with", "swap", "but", "we", "are", "buying", "performance", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L71-L75
train
Workiva/go-datastructures
sort/symmerge.go
symRotate
func symRotate(u Comparators, start1, start2, end int) { i := start2 - start1 if i == 0 { return } j := end - start2 if j == 0 { return } if i == j { symSwap(u, start1, start2, i) return } p := start1 + i for i != j { if i > j { symSwap(u, p-i, p, j) i -= j } else { symSwap(u, p-i, p+j-i, i) j -= i } } symSwap(u, p-i, p, i) }
go
func symRotate(u Comparators, start1, start2, end int) { i := start2 - start1 if i == 0 { return } j := end - start2 if j == 0 { return } if i == j { symSwap(u, start1, start2, i) return } p := start1 + i for i != j { if i > j { symSwap(u, p-i, p, j) i -= j } else { symSwap(u, p-i, p+j-i, i) j -= i } } symSwap(u, p-i, p, i) }
[ "func", "symRotate", "(", "u", "Comparators", ",", "start1", ",", "start2", ",", "end", "int", ")", "{", "i", ":=", "start2", "-", "start1", "\n", "if", "i", "==", "0", "{", "return", "\n", "}", "\n", "j", ":=", "end", "-", "start2", "\n", "if", ...
// symRotate determines the indices to use in a symSwap and // performs the swap.
[ "symRotate", "determines", "the", "indices", "to", "use", "in", "a", "symSwap", "and", "performs", "the", "swap", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L79-L106
train
Workiva/go-datastructures
sort/symmerge.go
symMerge
func symMerge(u Comparators, start1, start2, last int) { if start1 < start2 && start2 < last { mid := (start1 + last) / 2 n := mid + start2 var start int if start2 > mid { start = symBinarySearch(u, n-last, mid, n-1) } else { start = symBinarySearch(u, start1, start2, n-1) } end := n - start symRotate(u, start, start2, end) symMerge(u, start1, start, mid) symMerge(u, mid, end, last) } }
go
func symMerge(u Comparators, start1, start2, last int) { if start1 < start2 && start2 < last { mid := (start1 + last) / 2 n := mid + start2 var start int if start2 > mid { start = symBinarySearch(u, n-last, mid, n-1) } else { start = symBinarySearch(u, start1, start2, n-1) } end := n - start symRotate(u, start, start2, end) symMerge(u, start1, start, mid) symMerge(u, mid, end, last) } }
[ "func", "symMerge", "(", "u", "Comparators", ",", "start1", ",", "start2", ",", "last", "int", ")", "{", "if", "start1", "<", "start2", "&&", "start2", "<", "last", "{", "mid", ":=", "(", "start1", "+", "last", ")", "/", "2", "\n", "n", ":=", "mi...
// symMerge is the recursive and internal form of SymMerge.
[ "symMerge", "is", "the", "recursive", "and", "internal", "form", "of", "SymMerge", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/symmerge.go#L109-L125
train
Workiva/go-datastructures
slice/skip/skip.go
Int63
func (ls *lockedSource) Int63() (n int64) { ls.mu.Lock() n = ls.src.Int63() ls.mu.Unlock() return }
go
func (ls *lockedSource) Int63() (n int64) { ls.mu.Lock() n = ls.src.Int63() ls.mu.Unlock() return }
[ "func", "(", "ls", "*", "lockedSource", ")", "Int63", "(", ")", "(", "n", "int64", ")", "{", "ls", ".", "mu", ".", "Lock", "(", ")", "\n", "n", "=", "ls", ".", "src", ".", "Int63", "(", ")", "\n", "ls", ".", "mu", ".", "Unlock", "(", ")", ...
// Int63 implements the rand.Source interface.
[ "Int63", "implements", "the", "rand", ".", "Source", "interface", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L86-L91
train
Workiva/go-datastructures
slice/skip/skip.go
Seed
func (ls *lockedSource) Seed(seed int64) { ls.mu.Lock() ls.src.Seed(seed) ls.mu.Unlock() }
go
func (ls *lockedSource) Seed(seed int64) { ls.mu.Lock() ls.src.Seed(seed) ls.mu.Unlock() }
[ "func", "(", "ls", "*", "lockedSource", ")", "Seed", "(", "seed", "int64", ")", "{", "ls", ".", "mu", ".", "Lock", "(", ")", "\n", "ls", ".", "src", ".", "Seed", "(", "seed", ")", "\n", "ls", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Seed implements the rand.Source interface.
[ "Seed", "implements", "the", "rand", ".", "Source", "interface", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L94-L98
train
Workiva/go-datastructures
slice/skip/skip.go
init
func (sl *SkipList) init(ifc interface{}) { switch ifc.(type) { case uint8: sl.maxLevel = 8 case uint16: sl.maxLevel = 16 case uint32: sl.maxLevel = 32 case uint64, uint: sl.maxLevel = 64 } sl.cache = make(nodes, sl.maxLevel) sl.posCache = make(widths, sl.maxLevel) sl.head = newNode(nil, sl.maxLevel) }
go
func (sl *SkipList) init(ifc interface{}) { switch ifc.(type) { case uint8: sl.maxLevel = 8 case uint16: sl.maxLevel = 16 case uint32: sl.maxLevel = 32 case uint64, uint: sl.maxLevel = 64 } sl.cache = make(nodes, sl.maxLevel) sl.posCache = make(widths, sl.maxLevel) sl.head = newNode(nil, sl.maxLevel) }
[ "func", "(", "sl", "*", "SkipList", ")", "init", "(", "ifc", "interface", "{", "}", ")", "{", "switch", "ifc", ".", "(", "type", ")", "{", "case", "uint8", ":", "sl", ".", "maxLevel", "=", "8", "\n", "case", "uint16", ":", "sl", ".", "maxLevel", ...
// init will initialize this skiplist. The parameter is expected // to be of some uint type which will set this skiplist's maximum // level.
[ "init", "will", "initialize", "this", "skiplist", ".", "The", "parameter", "is", "expected", "to", "be", "of", "some", "uint", "type", "which", "will", "set", "this", "skiplist", "s", "maximum", "level", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L204-L218
train
Workiva/go-datastructures
slice/skip/skip.go
GetWithPosition
func (sl *SkipList) GetWithPosition(cmp common.Comparator) (common.Comparator, uint64) { n, pos := sl.search(cmp, nil, nil) if n == nil { return nil, 0 } return n.entry, pos - 1 }
go
func (sl *SkipList) GetWithPosition(cmp common.Comparator) (common.Comparator, uint64) { n, pos := sl.search(cmp, nil, nil) if n == nil { return nil, 0 } return n.entry, pos - 1 }
[ "func", "(", "sl", "*", "SkipList", ")", "GetWithPosition", "(", "cmp", "common", ".", "Comparator", ")", "(", "common", ".", "Comparator", ",", "uint64", ")", "{", "n", ",", "pos", ":=", "sl", ".", "search", "(", "cmp", ",", "nil", ",", "nil", ")"...
// GetWithPosition will retrieve the value with the provided key and // return the position of that value within the list. Returns nil, 0 // if an associated value could not be found.
[ "GetWithPosition", "will", "retrieve", "the", "value", "with", "the", "provided", "key", "and", "return", "the", "position", "of", "that", "value", "within", "the", "list", ".", "Returns", "nil", "0", "if", "an", "associated", "value", "could", "not", "be", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L306-L313
train
Workiva/go-datastructures
slice/skip/skip.go
ByPosition
func (sl *SkipList) ByPosition(position uint64) common.Comparator { n, _ := sl.searchByPosition(position+1, nil, nil) if n == nil { return nil } return n.entry }
go
func (sl *SkipList) ByPosition(position uint64) common.Comparator { n, _ := sl.searchByPosition(position+1, nil, nil) if n == nil { return nil } return n.entry }
[ "func", "(", "sl", "*", "SkipList", ")", "ByPosition", "(", "position", "uint64", ")", "common", ".", "Comparator", "{", "n", ",", "_", ":=", "sl", ".", "searchByPosition", "(", "position", "+", "1", ",", "nil", ",", "nil", ")", "\n", "if", "n", "=...
// ByPosition returns the Comparator at the given position.
[ "ByPosition", "returns", "the", "Comparator", "at", "the", "given", "position", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L316-L323
train
Workiva/go-datastructures
slice/skip/skip.go
InsertAtPosition
func (sl *SkipList) InsertAtPosition(position uint64, cmp common.Comparator) { sl.insertAtPosition(position, cmp) }
go
func (sl *SkipList) InsertAtPosition(position uint64, cmp common.Comparator) { sl.insertAtPosition(position, cmp) }
[ "func", "(", "sl", "*", "SkipList", ")", "InsertAtPosition", "(", "position", "uint64", ",", "cmp", "common", ".", "Comparator", ")", "{", "sl", ".", "insertAtPosition", "(", "position", ",", "cmp", ")", "\n", "}" ]
// InsertAtPosition will insert the provided Comparator at the provided position. // If position is greater than the length of the skiplist, the Comparator // is appended. This method bypasses order checks and checks for // duplicates so use with caution.
[ "InsertAtPosition", "will", "insert", "the", "provided", "Comparator", "at", "the", "provided", "position", ".", "If", "position", "is", "greater", "than", "the", "length", "of", "the", "skiplist", "the", "Comparator", "is", "appended", ".", "This", "method", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L354-L356
train
Workiva/go-datastructures
slice/skip/skip.go
ReplaceAtPosition
func (sl *SkipList) ReplaceAtPosition(position uint64, cmp common.Comparator) { sl.replaceAtPosition(position, cmp) }
go
func (sl *SkipList) ReplaceAtPosition(position uint64, cmp common.Comparator) { sl.replaceAtPosition(position, cmp) }
[ "func", "(", "sl", "*", "SkipList", ")", "ReplaceAtPosition", "(", "position", "uint64", ",", "cmp", "common", ".", "Comparator", ")", "{", "sl", ".", "replaceAtPosition", "(", "position", ",", "cmp", ")", "\n", "}" ]
// Replace at position will replace the Comparator at the provided position // with the provided Comparator. If the provided position does not exist, // this operation is a no-op.
[ "Replace", "at", "position", "will", "replace", "the", "Comparator", "at", "the", "provided", "position", "with", "the", "provided", "Comparator", ".", "If", "the", "provided", "position", "does", "not", "exist", "this", "operation", "is", "a", "no", "-", "o...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L370-L372
train
Workiva/go-datastructures
slice/skip/skip.go
Iter
func (sl *SkipList) Iter(cmp common.Comparator) Iterator { return sl.iter(cmp) }
go
func (sl *SkipList) Iter(cmp common.Comparator) Iterator { return sl.iter(cmp) }
[ "func", "(", "sl", "*", "SkipList", ")", "Iter", "(", "cmp", "common", ".", "Comparator", ")", "Iterator", "{", "return", "sl", ".", "iter", "(", "cmp", ")", "\n", "}" ]
// Iter will return an iterator that can be used to iterate // over all the values with a key equal to or greater than // the key provided.
[ "Iter", "will", "return", "an", "iterator", "that", "can", "be", "used", "to", "iterate", "over", "all", "the", "values", "with", "a", "key", "equal", "to", "or", "greater", "than", "the", "key", "provided", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L454-L456
train
Workiva/go-datastructures
slice/skip/skip.go
SplitAt
func (sl *SkipList) SplitAt(index uint64) (*SkipList, *SkipList) { index++ // 0-index offset if index >= sl.Len() { return sl, nil } return splitAt(sl, index) }
go
func (sl *SkipList) SplitAt(index uint64) (*SkipList, *SkipList) { index++ // 0-index offset if index >= sl.Len() { return sl, nil } return splitAt(sl, index) }
[ "func", "(", "sl", "*", "SkipList", ")", "SplitAt", "(", "index", "uint64", ")", "(", "*", "SkipList", ",", "*", "SkipList", ")", "{", "index", "++", "\n", "if", "index", ">=", "sl", ".", "Len", "(", ")", "{", "return", "sl", ",", "nil", "\n", ...
// SplitAt will split the current skiplist into two lists. The first // skiplist returned is the "left" list and the second is the "right." // The index defines the last item in the left list. If index is greater // then the length of this list, only the left skiplist is returned // and the right will be nil. This is a mutable operation and modifies // the content of this list.
[ "SplitAt", "will", "split", "the", "current", "skiplist", "into", "two", "lists", ".", "The", "first", "skiplist", "returned", "is", "the", "left", "list", "and", "the", "second", "is", "the", "right", ".", "The", "index", "defines", "the", "last", "item",...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/skip.go#L464-L470
train
Workiva/go-datastructures
sort/interface.go
Less
func (c Comparators) Less(i, j int) bool { return c[i].Compare(c[j]) < 0 }
go
func (c Comparators) Less(i, j int) bool { return c[i].Compare(c[j]) < 0 }
[ "func", "(", "c", "Comparators", ")", "Less", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "c", "[", "i", "]", ".", "Compare", "(", "c", "[", "j", "]", ")", "<", "0", "\n", "}" ]
// Less returns a bool indicating if the comparator at index i // is less than the comparator at index j.
[ "Less", "returns", "a", "bool", "indicating", "if", "the", "comparator", "at", "index", "i", "is", "less", "than", "the", "comparator", "at", "index", "j", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/interface.go#L8-L10
train
Workiva/go-datastructures
sort/interface.go
Swap
func (c Comparators) Swap(i, j int) { c[j], c[i] = c[i], c[j] }
go
func (c Comparators) Swap(i, j int) { c[j], c[i] = c[i], c[j] }
[ "func", "(", "c", "Comparators", ")", "Swap", "(", "i", ",", "j", "int", ")", "{", "c", "[", "j", "]", ",", "c", "[", "i", "]", "=", "c", "[", "i", "]", ",", "c", "[", "j", "]", "\n", "}" ]
// Swap swaps the values at positions i and j.
[ "Swap", "swaps", "the", "values", "at", "positions", "i", "and", "j", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/interface.go#L19-L21
train
Workiva/go-datastructures
slice/skip/node.go
newNode
func newNode(cmp common.Comparator, maxLevels uint8) *node { return &node{ entry: cmp, forward: make(nodes, maxLevels), widths: make(widths, maxLevels), } }
go
func newNode(cmp common.Comparator, maxLevels uint8) *node { return &node{ entry: cmp, forward: make(nodes, maxLevels), widths: make(widths, maxLevels), } }
[ "func", "newNode", "(", "cmp", "common", ".", "Comparator", ",", "maxLevels", "uint8", ")", "*", "node", "{", "return", "&", "node", "{", "entry", ":", "cmp", ",", "forward", ":", "make", "(", "nodes", ",", "maxLevels", ")", ",", "widths", ":", "make...
// newNode will allocate and return a new node with the entry // provided. maxLevels will determine the length of the forward // pointer list associated with this node.
[ "newNode", "will", "allocate", "and", "return", "a", "new", "node", "with", "the", "entry", "provided", ".", "maxLevels", "will", "determine", "the", "length", "of", "the", "forward", "pointer", "list", "associated", "with", "this", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/node.go#L44-L50
train
Workiva/go-datastructures
futures/futures.go
GetResult
func (f *Future) GetResult() (interface{}, error) { f.lock.Lock() if f.triggered { f.lock.Unlock() return f.item, f.err } f.lock.Unlock() f.wg.Wait() return f.item, f.err }
go
func (f *Future) GetResult() (interface{}, error) { f.lock.Lock() if f.triggered { f.lock.Unlock() return f.item, f.err } f.lock.Unlock() f.wg.Wait() return f.item, f.err }
[ "func", "(", "f", "*", "Future", ")", "GetResult", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "if", "f", ".", "triggered", "{", "f", ".", "lock", ".", "Unlock", "(", ")", "\n",...
// GetResult will immediately fetch the result if it exists // or wait on the result until it is ready.
[ "GetResult", "will", "immediately", "fetch", "the", "result", "if", "it", "exists", "or", "wait", "on", "the", "result", "until", "it", "is", "ready", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L52-L62
train
Workiva/go-datastructures
futures/futures.go
HasResult
func (f *Future) HasResult() bool { f.lock.Lock() hasResult := f.triggered f.lock.Unlock() return hasResult }
go
func (f *Future) HasResult() bool { f.lock.Lock() hasResult := f.triggered f.lock.Unlock() return hasResult }
[ "func", "(", "f", "*", "Future", ")", "HasResult", "(", ")", "bool", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "hasResult", ":=", "f", ".", "triggered", "\n", "f", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "hasResult", "\n",...
// HasResult will return true iff the result exists
[ "HasResult", "will", "return", "true", "iff", "the", "result", "exists" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L65-L70
train
Workiva/go-datastructures
futures/futures.go
New
func New(completer Completer, timeout time.Duration) *Future { f := &Future{} f.wg.Add(1) var wg sync.WaitGroup wg.Add(1) go listenForResult(f, completer, timeout, &wg) wg.Wait() return f }
go
func New(completer Completer, timeout time.Duration) *Future { f := &Future{} f.wg.Add(1) var wg sync.WaitGroup wg.Add(1) go listenForResult(f, completer, timeout, &wg) wg.Wait() return f }
[ "func", "New", "(", "completer", "Completer", ",", "timeout", "time", ".", "Duration", ")", "*", "Future", "{", "f", ":=", "&", "Future", "{", "}", "\n", "f", ".", "wg", ".", "Add", "(", "1", ")", "\n", "var", "wg", "sync", ".", "WaitGroup", "\n"...
// New is the constructor to generate a new future. Pass the completed // item to the toComplete channel and any listeners will get // notified. If timeout is hit before toComplete is called, // any listeners will get passed an error.
[ "New", "is", "the", "constructor", "to", "generate", "a", "new", "future", ".", "Pass", "the", "completed", "item", "to", "the", "toComplete", "channel", "and", "any", "listeners", "will", "get", "notified", ".", "If", "timeout", "is", "hit", "before", "to...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/futures.go#L97-L105
train
Workiva/go-datastructures
rangetree/ordered.go
addAt
func (nodes *orderedNodes) addAt(i int, node *node) *node { if i == len(*nodes) { *nodes = append(*nodes, node) return nil } if (*nodes)[i].value == node.value { overwritten := (*nodes)[i] // this is a duplicate, there can't be a duplicate // point in the last dimension (*nodes)[i] = node return overwritten } *nodes = append(*nodes, nil) copy((*nodes)[i+1:], (*nodes)[i:]) (*nodes)[i] = node return nil }
go
func (nodes *orderedNodes) addAt(i int, node *node) *node { if i == len(*nodes) { *nodes = append(*nodes, node) return nil } if (*nodes)[i].value == node.value { overwritten := (*nodes)[i] // this is a duplicate, there can't be a duplicate // point in the last dimension (*nodes)[i] = node return overwritten } *nodes = append(*nodes, nil) copy((*nodes)[i+1:], (*nodes)[i:]) (*nodes)[i] = node return nil }
[ "func", "(", "nodes", "*", "orderedNodes", ")", "addAt", "(", "i", "int", ",", "node", "*", "node", ")", "*", "node", "{", "if", "i", "==", "len", "(", "*", "nodes", ")", "{", "*", "nodes", "=", "append", "(", "*", "nodes", ",", "node", ")", ...
// addAt will add the provided node at the provided index. Returns // a node if one was overwritten.
[ "addAt", "will", "add", "the", "provided", "node", "at", "the", "provided", "index", ".", "Returns", "a", "node", "if", "one", "was", "overwritten", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/ordered.go#L34-L52
train
Workiva/go-datastructures
trie/yfast/yfast.go
getBucketKey
func (yfast *YFastTrie) getBucketKey(key uint64) uint64 { i := key/uint64(yfast.bits) + 1 return uint64(yfast.bits)*i - 1 }
go
func (yfast *YFastTrie) getBucketKey(key uint64) uint64 { i := key/uint64(yfast.bits) + 1 return uint64(yfast.bits)*i - 1 }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "getBucketKey", "(", "key", "uint64", ")", "uint64", "{", "i", ":=", "key", "/", "uint64", "(", "yfast", ".", "bits", ")", "+", "1", "\n", "return", "uint64", "(", "yfast", ".", "bits", ")", "*", "i", ...
// getBucketKey finds the largest possible value in this key's bucket. // This is the representative value for the entry in the x-fast trie.
[ "getBucketKey", "finds", "the", "largest", "possible", "value", "in", "this", "key", "s", "bucket", ".", "This", "is", "the", "representative", "value", "for", "the", "entry", "in", "the", "x", "-", "fast", "trie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L71-L74
train
Workiva/go-datastructures
trie/yfast/yfast.go
Insert
func (yfast *YFastTrie) Insert(entries ...Entry) Entries { overwritten := make(Entries, 0, len(entries)) for _, e := range entries { overwritten = append(overwritten, yfast.insert(e)) } return overwritten }
go
func (yfast *YFastTrie) Insert(entries ...Entry) Entries { overwritten := make(Entries, 0, len(entries)) for _, e := range entries { overwritten = append(overwritten, yfast.insert(e)) } return overwritten }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Insert", "(", "entries", "...", "Entry", ")", "Entries", "{", "overwritten", ":=", "make", "(", "Entries", ",", "0", ",", "len", "(", "entries", ")", ")", "\n", "for", "_", ",", "e", ":=", "range", "ent...
// Insert will insert the provided entries into the y-fast trie // and return a list of entries that were overwritten.
[ "Insert", "will", "insert", "the", "provided", "entries", "into", "the", "y", "-", "fast", "trie", "and", "return", "a", "list", "of", "entries", "that", "were", "overwritten", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L107-L114
train
Workiva/go-datastructures
trie/yfast/yfast.go
Delete
func (yfast *YFastTrie) Delete(keys ...uint64) Entries { entries := make(Entries, 0, len(keys)) for _, key := range keys { entries = append(entries, yfast.delete(key)) } return entries }
go
func (yfast *YFastTrie) Delete(keys ...uint64) Entries { entries := make(Entries, 0, len(keys)) for _, key := range keys { entries = append(entries, yfast.delete(key)) } return entries }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Delete", "(", "keys", "...", "uint64", ")", "Entries", "{", "entries", ":=", "make", "(", "Entries", ",", "0", ",", "len", "(", "keys", ")", ")", "\n", "for", "_", ",", "key", ":=", "range", "keys", "...
// Delete will delete the provided keys from the y-fast trie // and return a list of entries that were deleted.
[ "Delete", "will", "delete", "the", "provided", "keys", "from", "the", "y", "-", "fast", "trie", "and", "return", "a", "list", "of", "entries", "that", "were", "deleted", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L141-L148
train
Workiva/go-datastructures
trie/yfast/yfast.go
Get
func (yfast *YFastTrie) Get(key uint64) Entry { entry := yfast.get(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Get(key uint64) Entry { entry := yfast.get(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Get", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "get", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "entry", "\n", "}...
// Get will look for the provided key in the y-fast trie and return // the associated value if it is found. If it is not found, this // method returns nil.
[ "Get", "will", "look", "for", "the", "provided", "key", "in", "the", "y", "-", "fast", "trie", "and", "return", "the", "associated", "value", "if", "it", "is", "found", ".", "If", "it", "is", "not", "found", "this", "method", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L168-L175
train
Workiva/go-datastructures
trie/yfast/yfast.go
Successor
func (yfast *YFastTrie) Successor(key uint64) Entry { entry := yfast.successor(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Successor(key uint64) Entry { entry := yfast.successor(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Successor", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "successor", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "entry", ...
// Successor returns an Entry with a key equal to or immediately // greater than the provided key. If such an Entry does not exist // this returns nil.
[ "Successor", "returns", "an", "Entry", "with", "a", "key", "equal", "to", "or", "immediately", "greater", "than", "the", "provided", "key", ".", "If", "such", "an", "Entry", "does", "not", "exist", "this", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L199-L206
train
Workiva/go-datastructures
trie/yfast/yfast.go
Predecessor
func (yfast *YFastTrie) Predecessor(key uint64) Entry { entry := yfast.predecessor(key) if entry == nil { return nil } return entry }
go
func (yfast *YFastTrie) Predecessor(key uint64) Entry { entry := yfast.predecessor(key) if entry == nil { return nil } return entry }
[ "func", "(", "yfast", "*", "YFastTrie", ")", "Predecessor", "(", "key", "uint64", ")", "Entry", "{", "entry", ":=", "yfast", ".", "predecessor", "(", "key", ")", "\n", "if", "entry", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "entr...
// Predecessor returns an Entry with a key equal to or immediately // preceeding than the provided key. If such an Entry does not exist // this returns nil.
[ "Predecessor", "returns", "an", "Entry", "with", "a", "key", "equal", "to", "or", "immediately", "preceeding", "than", "the", "provided", "key", ".", "If", "such", "an", "Entry", "does", "not", "exist", "this", "returns", "nil", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/yfast.go#L242-L249
train
Workiva/go-datastructures
graph/simple.go
V
func (g *SimpleGraph) V() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.v }
go
func (g *SimpleGraph) V() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.v }
[ "func", "(", "g", "*", "SimpleGraph", ")", "V", "(", ")", "int", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "g", ".", "v", "\n", "}" ]
// V returns the number of vertices in the SimpleGraph
[ "V", "returns", "the", "number", "of", "vertices", "in", "the", "SimpleGraph" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L52-L57
train
Workiva/go-datastructures
graph/simple.go
E
func (g *SimpleGraph) E() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.e }
go
func (g *SimpleGraph) E() int { g.mutex.RLock() defer g.mutex.RUnlock() return g.e }
[ "func", "(", "g", "*", "SimpleGraph", ")", "E", "(", ")", "int", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "g", ".", "e", "\n", "}" ]
// E returns the number of edges in the SimpleGraph
[ "E", "returns", "the", "number", "of", "edges", "in", "the", "SimpleGraph" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L60-L65
train
Workiva/go-datastructures
graph/simple.go
AddEdge
func (g *SimpleGraph) AddEdge(v, w interface{}) error { g.mutex.Lock() defer g.mutex.Unlock() if v == w { return ErrSelfLoop } g.addVertex(v) g.addVertex(w) if _, ok := g.adjacencyList[v][w]; ok { return ErrParallelEdge } g.adjacencyList[v][w] = struct{}{} g.adjacencyList[w][v] = struct{}{} g.e++ return nil }
go
func (g *SimpleGraph) AddEdge(v, w interface{}) error { g.mutex.Lock() defer g.mutex.Unlock() if v == w { return ErrSelfLoop } g.addVertex(v) g.addVertex(w) if _, ok := g.adjacencyList[v][w]; ok { return ErrParallelEdge } g.adjacencyList[v][w] = struct{}{} g.adjacencyList[w][v] = struct{}{} g.e++ return nil }
[ "func", "(", "g", "*", "SimpleGraph", ")", "AddEdge", "(", "v", ",", "w", "interface", "{", "}", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "v", "==", "w...
// AddEdge will create an edge between vertices v and w
[ "AddEdge", "will", "create", "an", "edge", "between", "vertices", "v", "and", "w" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L68-L87
train
Workiva/go-datastructures
graph/simple.go
Adj
func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) { g.mutex.RLock() defer g.mutex.RUnlock() deg, err := g.Degree(v) if err != nil { return nil, ErrVertexNotFound } adj := make([]interface{}, deg) i := 0 for key := range g.adjacencyList[v] { adj[i] = key i++ } return adj, nil }
go
func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) { g.mutex.RLock() defer g.mutex.RUnlock() deg, err := g.Degree(v) if err != nil { return nil, ErrVertexNotFound } adj := make([]interface{}, deg) i := 0 for key := range g.adjacencyList[v] { adj[i] = key i++ } return adj, nil }
[ "func", "(", "g", "*", "SimpleGraph", ")", "Adj", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", ...
// Adj returns the list of all vertices connected to v
[ "Adj", "returns", "the", "list", "of", "all", "vertices", "connected", "to", "v" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L90-L106
train
Workiva/go-datastructures
graph/simple.go
Degree
func (g *SimpleGraph) Degree(v interface{}) (int, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, ok := g.adjacencyList[v] if !ok { return 0, ErrVertexNotFound } return len(val), nil }
go
func (g *SimpleGraph) Degree(v interface{}) (int, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, ok := g.adjacencyList[v] if !ok { return 0, ErrVertexNotFound } return len(val), nil }
[ "func", "(", "g", "*", "SimpleGraph", ")", "Degree", "(", "v", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "val", ...
// Degree returns the number of vertices connected to v
[ "Degree", "returns", "the", "number", "of", "vertices", "connected", "to", "v" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/graph/simple.go#L109-L118
train
Workiva/go-datastructures
btree/immutable/path.go
pop
func (p *path) pop() *pathBundle { if pb := p.tail; pb != nil { p.tail = pb.prev pb.prev = nil return pb } return nil }
go
func (p *path) pop() *pathBundle { if pb := p.tail; pb != nil { p.tail = pb.prev pb.prev = nil return pb } return nil }
[ "func", "(", "p", "*", "path", ")", "pop", "(", ")", "*", "pathBundle", "{", "if", "pb", ":=", "p", ".", "tail", ";", "pb", "!=", "nil", "{", "p", ".", "tail", "=", "pb", ".", "prev", "\n", "pb", ".", "prev", "=", "nil", "\n", "return", "pb...
// pop removes the last item from the path. Note that it also nils // out the returned pathBundle's prev field. Returns nil if no items // remain.
[ "pop", "removes", "the", "last", "item", "from", "the", "path", ".", "Note", "that", "it", "also", "nils", "out", "the", "returned", "pathBundle", "s", "prev", "field", ".", "Returns", "nil", "if", "no", "items", "remain", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/path.go#L53-L61
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
copyToGen
func (i *iNode) copyToGen(gen *generation, ctrie *Ctrie) *iNode { nin := &iNode{gen: gen} main := gcasRead(i, ctrie) atomic.StorePointer( (*unsafe.Pointer)(unsafe.Pointer(&nin.main)), unsafe.Pointer(main)) return nin }
go
func (i *iNode) copyToGen(gen *generation, ctrie *Ctrie) *iNode { nin := &iNode{gen: gen} main := gcasRead(i, ctrie) atomic.StorePointer( (*unsafe.Pointer)(unsafe.Pointer(&nin.main)), unsafe.Pointer(main)) return nin }
[ "func", "(", "i", "*", "iNode", ")", "copyToGen", "(", "gen", "*", "generation", ",", "ctrie", "*", "Ctrie", ")", "*", "iNode", "{", "nin", ":=", "&", "iNode", "{", "gen", ":", "gen", "}", "\n", "main", ":=", "gcasRead", "(", "i", ",", "ctrie", ...
// copyToGen returns a copy of this I-node copied to the given generation.
[ "copyToGen", "returns", "a", "copy", "of", "this", "I", "-", "node", "copied", "to", "the", "given", "generation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L80-L86
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
newMainNode
func newMainNode(x *sNode, xhc uint32, y *sNode, yhc uint32, lev uint, gen *generation) *mainNode { if lev < exp2 { xidx := (xhc >> lev) & 0x1f yidx := (yhc >> lev) & 0x1f bmp := uint32((1 << xidx) | (1 << yidx)) if xidx == yidx { // Recurse when indexes are equal. main := newMainNode(x, xhc, y, yhc, lev+w, gen) iNode := &iNode{main: main, gen: gen} return &mainNode{cNode: &cNode{bmp, []branch{iNode}, gen}} } if xidx < yidx { return &mainNode{cNode: &cNode{bmp, []branch{x, y}, gen}} } return &mainNode{cNode: &cNode{bmp, []branch{y, x}, gen}} } l := list.Empty.Add(x).Add(y) return &mainNode{lNode: &lNode{l}} }
go
func newMainNode(x *sNode, xhc uint32, y *sNode, yhc uint32, lev uint, gen *generation) *mainNode { if lev < exp2 { xidx := (xhc >> lev) & 0x1f yidx := (yhc >> lev) & 0x1f bmp := uint32((1 << xidx) | (1 << yidx)) if xidx == yidx { // Recurse when indexes are equal. main := newMainNode(x, xhc, y, yhc, lev+w, gen) iNode := &iNode{main: main, gen: gen} return &mainNode{cNode: &cNode{bmp, []branch{iNode}, gen}} } if xidx < yidx { return &mainNode{cNode: &cNode{bmp, []branch{x, y}, gen}} } return &mainNode{cNode: &cNode{bmp, []branch{y, x}, gen}} } l := list.Empty.Add(x).Add(y) return &mainNode{lNode: &lNode{l}} }
[ "func", "newMainNode", "(", "x", "*", "sNode", ",", "xhc", "uint32", ",", "y", "*", "sNode", ",", "yhc", "uint32", ",", "lev", "uint", ",", "gen", "*", "generation", ")", "*", "mainNode", "{", "if", "lev", "<", "exp2", "{", "xidx", ":=", "(", "xh...
// newMainNode is a recursive constructor which creates a new mainNode. This // mainNode will consist of cNodes as long as the hashcode chunks of the two // keys are equal at the given level. If the level exceeds 2^w, an lNode is // created.
[ "newMainNode", "is", "a", "recursive", "constructor", "which", "creates", "a", "new", "mainNode", ".", "This", "mainNode", "will", "consist", "of", "cNodes", "as", "long", "as", "the", "hashcode", "chunks", "of", "the", "two", "keys", "are", "equal", "at", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L116-L135
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
inserted
func (c *cNode) inserted(pos, flag uint32, br branch, gen *generation) *cNode { length := uint32(len(c.array)) bmp := c.bmp array := make([]branch, length+1) copy(array, c.array) array[pos] = br for i, x := pos, uint32(0); x < length-pos; i++ { array[i+1] = c.array[i] x++ } ncn := &cNode{bmp: bmp | flag, array: array, gen: gen} return ncn }
go
func (c *cNode) inserted(pos, flag uint32, br branch, gen *generation) *cNode { length := uint32(len(c.array)) bmp := c.bmp array := make([]branch, length+1) copy(array, c.array) array[pos] = br for i, x := pos, uint32(0); x < length-pos; i++ { array[i+1] = c.array[i] x++ } ncn := &cNode{bmp: bmp | flag, array: array, gen: gen} return ncn }
[ "func", "(", "c", "*", "cNode", ")", "inserted", "(", "pos", ",", "flag", "uint32", ",", "br", "branch", ",", "gen", "*", "generation", ")", "*", "cNode", "{", "length", ":=", "uint32", "(", "len", "(", "c", ".", "array", ")", ")", "\n", "bmp", ...
// inserted returns a copy of this cNode with the new entry at the given // position.
[ "inserted", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "new", "entry", "at", "the", "given", "position", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L139-L151
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
updated
func (c *cNode) updated(pos uint32, br branch, gen *generation) *cNode { array := make([]branch, len(c.array)) copy(array, c.array) array[pos] = br ncn := &cNode{bmp: c.bmp, array: array, gen: gen} return ncn }
go
func (c *cNode) updated(pos uint32, br branch, gen *generation) *cNode { array := make([]branch, len(c.array)) copy(array, c.array) array[pos] = br ncn := &cNode{bmp: c.bmp, array: array, gen: gen} return ncn }
[ "func", "(", "c", "*", "cNode", ")", "updated", "(", "pos", "uint32", ",", "br", "branch", ",", "gen", "*", "generation", ")", "*", "cNode", "{", "array", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "c", ".", "array", ")", ")", "\n"...
// updated returns a copy of this cNode with the entry at the given index // updated.
[ "updated", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "entry", "at", "the", "given", "index", "updated", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L155-L161
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
renewed
func (c *cNode) renewed(gen *generation, ctrie *Ctrie) *cNode { array := make([]branch, len(c.array)) for i, br := range c.array { switch t := br.(type) { case *iNode: array[i] = t.copyToGen(gen, ctrie) default: array[i] = br } } return &cNode{bmp: c.bmp, array: array, gen: gen} }
go
func (c *cNode) renewed(gen *generation, ctrie *Ctrie) *cNode { array := make([]branch, len(c.array)) for i, br := range c.array { switch t := br.(type) { case *iNode: array[i] = t.copyToGen(gen, ctrie) default: array[i] = br } } return &cNode{bmp: c.bmp, array: array, gen: gen} }
[ "func", "(", "c", "*", "cNode", ")", "renewed", "(", "gen", "*", "generation", ",", "ctrie", "*", "Ctrie", ")", "*", "cNode", "{", "array", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "c", ".", "array", ")", ")", "\n", "for", "i", ...
// renewed returns a copy of this cNode with the I-nodes below it copied to the // given generation.
[ "renewed", "returns", "a", "copy", "of", "this", "cNode", "with", "the", "I", "-", "nodes", "below", "it", "copied", "to", "the", "given", "generation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L182-L193
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
untombed
func (t *tNode) untombed() *sNode { return &sNode{&Entry{Key: t.Key, hash: t.hash, Value: t.Value}} }
go
func (t *tNode) untombed() *sNode { return &sNode{&Entry{Key: t.Key, hash: t.hash, Value: t.Value}} }
[ "func", "(", "t", "*", "tNode", ")", "untombed", "(", ")", "*", "sNode", "{", "return", "&", "sNode", "{", "&", "Entry", "{", "Key", ":", "t", ".", "Key", ",", "hash", ":", "t", ".", "hash", ",", "Value", ":", "t", ".", "Value", "}", "}", "...
// untombed returns the S-node contained by the T-node.
[ "untombed", "returns", "the", "S", "-", "node", "contained", "by", "the", "T", "-", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L202-L204
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
entry
func (l *lNode) entry() *sNode { head, _ := l.Head() return head.(*sNode) }
go
func (l *lNode) entry() *sNode { head, _ := l.Head() return head.(*sNode) }
[ "func", "(", "l", "*", "lNode", ")", "entry", "(", ")", "*", "sNode", "{", "head", ",", "_", ":=", "l", ".", "Head", "(", ")", "\n", "return", "head", ".", "(", "*", "sNode", ")", "\n", "}" ]
// entry returns the first S-node contained in the L-node.
[ "entry", "returns", "the", "first", "S", "-", "node", "contained", "in", "the", "L", "-", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L213-L216
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
lookup
func (l *lNode) lookup(e *Entry) (interface{}, bool) { found, ok := l.Find(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if !ok { return nil, false } return found.(*sNode).Value, true }
go
func (l *lNode) lookup(e *Entry) (interface{}, bool) { found, ok := l.Find(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if !ok { return nil, false } return found.(*sNode).Value, true }
[ "func", "(", "l", "*", "lNode", ")", "lookup", "(", "e", "*", "Entry", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "found", ",", "ok", ":=", "l", ".", "Find", "(", "func", "(", "sn", "interface", "{", "}", ")", "bool", "{", "retur...
// lookup returns the value at the given entry in the L-node or returns false // if it's not contained.
[ "lookup", "returns", "the", "value", "at", "the", "given", "entry", "in", "the", "L", "-", "node", "or", "returns", "false", "if", "it", "s", "not", "contained", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L220-L228
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
inserted
func (l *lNode) inserted(entry *Entry) *lNode { return &lNode{l.removed(entry).Add(&sNode{entry})} }
go
func (l *lNode) inserted(entry *Entry) *lNode { return &lNode{l.removed(entry).Add(&sNode{entry})} }
[ "func", "(", "l", "*", "lNode", ")", "inserted", "(", "entry", "*", "Entry", ")", "*", "lNode", "{", "return", "&", "lNode", "{", "l", ".", "removed", "(", "entry", ")", ".", "Add", "(", "&", "sNode", "{", "entry", "}", ")", "}", "\n", "}" ]
// inserted creates a new L-node with the added entry.
[ "inserted", "creates", "a", "new", "L", "-", "node", "with", "the", "added", "entry", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L231-L233
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
removed
func (l *lNode) removed(e *Entry) *lNode { idx := l.FindIndex(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if idx < 0 { return l } nl, _ := l.Remove(uint(idx)) return &lNode{nl} }
go
func (l *lNode) removed(e *Entry) *lNode { idx := l.FindIndex(func(sn interface{}) bool { return bytes.Equal(e.Key, sn.(*sNode).Key) }) if idx < 0 { return l } nl, _ := l.Remove(uint(idx)) return &lNode{nl} }
[ "func", "(", "l", "*", "lNode", ")", "removed", "(", "e", "*", "Entry", ")", "*", "lNode", "{", "idx", ":=", "l", ".", "FindIndex", "(", "func", "(", "sn", "interface", "{", "}", ")", "bool", "{", "return", "bytes", ".", "Equal", "(", "e", ".",...
// removed creates a new L-node with the entry removed.
[ "removed", "creates", "a", "new", "L", "-", "node", "with", "the", "entry", "removed", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L236-L245
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
New
func New(hashFactory HashFactory) *Ctrie { if hashFactory == nil { hashFactory = defaultHashFactory } root := &iNode{main: &mainNode{cNode: &cNode{}}} return newCtrie(root, hashFactory, false) }
go
func New(hashFactory HashFactory) *Ctrie { if hashFactory == nil { hashFactory = defaultHashFactory } root := &iNode{main: &mainNode{cNode: &cNode{}}} return newCtrie(root, hashFactory, false) }
[ "func", "New", "(", "hashFactory", "HashFactory", ")", "*", "Ctrie", "{", "if", "hashFactory", "==", "nil", "{", "hashFactory", "=", "defaultHashFactory", "\n", "}", "\n", "root", ":=", "&", "iNode", "{", "main", ":", "&", "mainNode", "{", "cNode", ":", ...
// New creates an empty Ctrie which uses the provided HashFactory for key // hashing. If nil is passed in, it will default to FNV-1a hashing.
[ "New", "creates", "an", "empty", "Ctrie", "which", "uses", "the", "provided", "HashFactory", "for", "key", "hashing", ".", "If", "nil", "is", "passed", "in", "it", "will", "default", "to", "FNV", "-", "1a", "hashing", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L269-L275
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Insert
func (c *Ctrie) Insert(key []byte, value interface{}) { c.assertReadWrite() c.insert(&Entry{ Key: key, Value: value, hash: c.hash(key), }) }
go
func (c *Ctrie) Insert(key []byte, value interface{}) { c.assertReadWrite() c.insert(&Entry{ Key: key, Value: value, hash: c.hash(key), }) }
[ "func", "(", "c", "*", "Ctrie", ")", "Insert", "(", "key", "[", "]", "byte", ",", "value", "interface", "{", "}", ")", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "c", ".", "insert", "(", "&", "Entry", "{", "Key", ":", "key", ",", "Value"...
// Insert adds the key-value pair to the Ctrie, replacing the existing value if // the key already exists.
[ "Insert", "adds", "the", "key", "-", "value", "pair", "to", "the", "Ctrie", "replacing", "the", "existing", "value", "if", "the", "key", "already", "exists", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L287-L294
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Lookup
func (c *Ctrie) Lookup(key []byte) (interface{}, bool) { return c.lookup(&Entry{Key: key, hash: c.hash(key)}) }
go
func (c *Ctrie) Lookup(key []byte) (interface{}, bool) { return c.lookup(&Entry{Key: key, hash: c.hash(key)}) }
[ "func", "(", "c", "*", "Ctrie", ")", "Lookup", "(", "key", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "return", "c", ".", "lookup", "(", "&", "Entry", "{", "Key", ":", "key", ",", "hash", ":", "c", ".", "hash", ...
// Lookup returns the value for the associated key or returns false if the key // doesn't exist.
[ "Lookup", "returns", "the", "value", "for", "the", "associated", "key", "or", "returns", "false", "if", "the", "key", "doesn", "t", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L298-L300
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Remove
func (c *Ctrie) Remove(key []byte) (interface{}, bool) { c.assertReadWrite() return c.remove(&Entry{Key: key, hash: c.hash(key)}) }
go
func (c *Ctrie) Remove(key []byte) (interface{}, bool) { c.assertReadWrite() return c.remove(&Entry{Key: key, hash: c.hash(key)}) }
[ "func", "(", "c", "*", "Ctrie", ")", "Remove", "(", "key", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "return", "c", ".", "remove", "(", "&", "Entry", "{", "Key", ":", ...
// Remove deletes the value for the associated key, returning true if it was // removed or false if the entry doesn't exist.
[ "Remove", "deletes", "the", "value", "for", "the", "associated", "key", "returning", "true", "if", "it", "was", "removed", "or", "false", "if", "the", "entry", "doesn", "t", "exist", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L304-L307
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
snapshot
func (c *Ctrie) snapshot(readOnly bool) *Ctrie { if readOnly && c.readOnly { return c } for { root := c.readRoot() main := gcasRead(root, c) if c.rdcssRoot(root, main, root.copyToGen(&generation{}, c)) { if readOnly { // For a read-only snapshot, we can share the old generation // root. return newCtrie(root, c.hashFactory, readOnly) } // For a read-write snapshot, we need to take a copy of the root // in the new generation. return newCtrie(c.readRoot().copyToGen(&generation{}, c), c.hashFactory, readOnly) } } }
go
func (c *Ctrie) snapshot(readOnly bool) *Ctrie { if readOnly && c.readOnly { return c } for { root := c.readRoot() main := gcasRead(root, c) if c.rdcssRoot(root, main, root.copyToGen(&generation{}, c)) { if readOnly { // For a read-only snapshot, we can share the old generation // root. return newCtrie(root, c.hashFactory, readOnly) } // For a read-write snapshot, we need to take a copy of the root // in the new generation. return newCtrie(c.readRoot().copyToGen(&generation{}, c), c.hashFactory, readOnly) } } }
[ "func", "(", "c", "*", "Ctrie", ")", "snapshot", "(", "readOnly", "bool", ")", "*", "Ctrie", "{", "if", "readOnly", "&&", "c", ".", "readOnly", "{", "return", "c", "\n", "}", "\n", "for", "{", "root", ":=", "c", ".", "readRoot", "(", ")", "\n", ...
// snapshot wraps up the CAS logic to make a snapshot or a read-only snapshot.
[ "snapshot", "wraps", "up", "the", "CAS", "logic", "to", "make", "a", "snapshot", "or", "a", "read", "-", "only", "snapshot", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L322-L340
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Clear
func (c *Ctrie) Clear() { for { root := c.readRoot() gen := &generation{} newRoot := &iNode{ main: &mainNode{cNode: &cNode{array: make([]branch, 0), gen: gen}}, gen: gen, } if c.rdcssRoot(root, gcasRead(root, c), newRoot) { return } } }
go
func (c *Ctrie) Clear() { for { root := c.readRoot() gen := &generation{} newRoot := &iNode{ main: &mainNode{cNode: &cNode{array: make([]branch, 0), gen: gen}}, gen: gen, } if c.rdcssRoot(root, gcasRead(root, c), newRoot) { return } } }
[ "func", "(", "c", "*", "Ctrie", ")", "Clear", "(", ")", "{", "for", "{", "root", ":=", "c", ".", "readRoot", "(", ")", "\n", "gen", ":=", "&", "generation", "{", "}", "\n", "newRoot", ":=", "&", "iNode", "{", "main", ":", "&", "mainNode", "{", ...
// Clear removes all keys from the Ctrie.
[ "Clear", "removes", "all", "keys", "from", "the", "Ctrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L343-L355
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Iterator
func (c *Ctrie) Iterator(cancel <-chan struct{}) <-chan *Entry { ch := make(chan *Entry) snapshot := c.ReadOnlySnapshot() go func() { snapshot.traverse(snapshot.readRoot(), ch, cancel) close(ch) }() return ch }
go
func (c *Ctrie) Iterator(cancel <-chan struct{}) <-chan *Entry { ch := make(chan *Entry) snapshot := c.ReadOnlySnapshot() go func() { snapshot.traverse(snapshot.readRoot(), ch, cancel) close(ch) }() return ch }
[ "func", "(", "c", "*", "Ctrie", ")", "Iterator", "(", "cancel", "<-", "chan", "struct", "{", "}", ")", "<-", "chan", "*", "Entry", "{", "ch", ":=", "make", "(", "chan", "*", "Entry", ")", "\n", "snapshot", ":=", "c", ".", "ReadOnlySnapshot", "(", ...
// Iterator returns a channel which yields the Entries of the Ctrie. If a // cancel channel is provided, closing it will terminate and close the iterator // channel. Note that if a cancel channel is not used and not every entry is // read from the iterator, a goroutine will leak.
[ "Iterator", "returns", "a", "channel", "which", "yields", "the", "Entries", "of", "the", "Ctrie", ".", "If", "a", "cancel", "channel", "is", "provided", "closing", "it", "will", "terminate", "and", "close", "the", "iterator", "channel", ".", "Note", "that", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L361-L369
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
Size
func (c *Ctrie) Size() uint { // TODO: The size operation can be optimized further by caching the size // information in main nodes of a read-only Ctrie – this reduces the // amortized complexity of the size operation to O(1) because the size // computation is amortized across the update operations that occurred // since the last snapshot. size := uint(0) for _ = range c.Iterator(nil) { size++ } return size }
go
func (c *Ctrie) Size() uint { // TODO: The size operation can be optimized further by caching the size // information in main nodes of a read-only Ctrie – this reduces the // amortized complexity of the size operation to O(1) because the size // computation is amortized across the update operations that occurred // since the last snapshot. size := uint(0) for _ = range c.Iterator(nil) { size++ } return size }
[ "func", "(", "c", "*", "Ctrie", ")", "Size", "(", ")", "uint", "{", "size", ":=", "uint", "(", "0", ")", "\n", "for", "_", "=", "range", "c", ".", "Iterator", "(", "nil", ")", "{", "size", "++", "\n", "}", "\n", "return", "size", "\n", "}" ]
// Size returns the number of keys in the Ctrie.
[ "Size", "returns", "the", "number", "of", "keys", "in", "the", "Ctrie", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L372-L383
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
iinsert
func (c *Ctrie) iinsert(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) bool { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the relevant bit is not in the bitmap, then a copy of the // cNode with the new entry is created. The linearization point is // a successful CAS. rn := cn if cn.gen != i.gen { rn = cn.renewed(i.gen, c) } ncn := &mainNode{cNode: rn.inserted(pos, flag, &sNode{entry}, i.gen)} return gcas(i, main, ncn, c) } // If the relevant bit is present in the bitmap, then its corresponding // branch is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, then iinsert is called recursively. in := branch.(*iNode) if startGen == in.gen { return c.iinsert(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.iinsert(i, entry, lev, parent, startGen) } return false case *sNode: sn := branch.(*sNode) if !bytes.Equal(sn.Key, entry.Key) { // If the branch is an S-node and its key is not equal to the // key being inserted, then the Ctrie has to be extended with // an additional level. The C-node is replaced with its updated // version, created using the updated function that adds a new // I-node at the respective position. The new Inode has its // main node pointing to a C-node with both keys. The // linearization point is a successful CAS. rn := cn if cn.gen != i.gen { rn = cn.renewed(i.gen, c) } nsn := &sNode{entry} nin := &iNode{main: newMainNode(sn, sn.hash, nsn, nsn.hash, lev+w, i.gen), gen: i.gen} ncn := &mainNode{cNode: rn.updated(pos, nin, i.gen)} return gcas(i, main, ncn, c) } // If the key in the S-node is equal to the key being inserted, // then the C-node is replaced with its updated version with a new // S-node. The linearization point is a successful CAS. ncn := &mainNode{cNode: cn.updated(pos, &sNode{entry}, i.gen)} return gcas(i, main, ncn, c) default: panic("Ctrie is in an invalid state") } case main.tNode != nil: clean(parent, lev-w, c) return false case main.lNode != nil: nln := &mainNode{lNode: main.lNode.inserted(entry)} return gcas(i, main, nln, c) default: panic("Ctrie is in an invalid state") } }
go
func (c *Ctrie) iinsert(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) bool { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the relevant bit is not in the bitmap, then a copy of the // cNode with the new entry is created. The linearization point is // a successful CAS. rn := cn if cn.gen != i.gen { rn = cn.renewed(i.gen, c) } ncn := &mainNode{cNode: rn.inserted(pos, flag, &sNode{entry}, i.gen)} return gcas(i, main, ncn, c) } // If the relevant bit is present in the bitmap, then its corresponding // branch is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, then iinsert is called recursively. in := branch.(*iNode) if startGen == in.gen { return c.iinsert(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.iinsert(i, entry, lev, parent, startGen) } return false case *sNode: sn := branch.(*sNode) if !bytes.Equal(sn.Key, entry.Key) { // If the branch is an S-node and its key is not equal to the // key being inserted, then the Ctrie has to be extended with // an additional level. The C-node is replaced with its updated // version, created using the updated function that adds a new // I-node at the respective position. The new Inode has its // main node pointing to a C-node with both keys. The // linearization point is a successful CAS. rn := cn if cn.gen != i.gen { rn = cn.renewed(i.gen, c) } nsn := &sNode{entry} nin := &iNode{main: newMainNode(sn, sn.hash, nsn, nsn.hash, lev+w, i.gen), gen: i.gen} ncn := &mainNode{cNode: rn.updated(pos, nin, i.gen)} return gcas(i, main, ncn, c) } // If the key in the S-node is equal to the key being inserted, // then the C-node is replaced with its updated version with a new // S-node. The linearization point is a successful CAS. ncn := &mainNode{cNode: cn.updated(pos, &sNode{entry}, i.gen)} return gcas(i, main, ncn, c) default: panic("Ctrie is in an invalid state") } case main.tNode != nil: clean(parent, lev-w, c) return false case main.lNode != nil: nln := &mainNode{lNode: main.lNode.inserted(entry)} return gcas(i, main, nln, c) default: panic("Ctrie is in an invalid state") } }
[ "func", "(", "c", "*", "Ctrie", ")", "iinsert", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "bool", "{", "main", ":=", "gcasRead", "(", "i", ",", "c...
// iinsert attempts to insert the entry into the Ctrie. If false is returned, // the operation should be retried.
[ "iinsert", "attempts", "to", "insert", "the", "entry", "into", "the", "Ctrie", ".", "If", "false", "is", "returned", "the", "operation", "should", "be", "retried", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L464-L532
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
ilookup
func (c *Ctrie) ilookup(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap does not contain the relevant bit, a key with the // required hashcode prefix is not present in the trie. return nil, false, true } // Otherwise, the relevant branch at index pos is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, the ilookup procedure is called // recursively at the next level. in := branch.(*iNode) if c.readOnly || startGen == in.gen { return c.ilookup(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.ilookup(i, entry, lev, parent, startGen) } return nil, false, false case *sNode: // If the branch is an S-node, then the key within the S-node is // compared with the key being searched – these two keys have the // same hashcode prefixes, but they need not be equal. If they are // equal, the corresponding value from the S-node is // returned and a NOTFOUND value otherwise. sn := branch.(*sNode) if bytes.Equal(sn.Key, entry.Key) { return sn.Value, true, true } return nil, false, true default: panic("Ctrie is in an invalid state") } case main.tNode != nil: return cleanReadOnly(main.tNode, lev, parent, c, entry) case main.lNode != nil: // Hash collisions are handled using L-nodes, which are essentially // persistent linked lists. val, ok := main.lNode.lookup(entry) return val, ok, true default: panic("Ctrie is in an invalid state") } }
go
func (c *Ctrie) ilookup(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap does not contain the relevant bit, a key with the // required hashcode prefix is not present in the trie. return nil, false, true } // Otherwise, the relevant branch at index pos is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, the ilookup procedure is called // recursively at the next level. in := branch.(*iNode) if c.readOnly || startGen == in.gen { return c.ilookup(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.ilookup(i, entry, lev, parent, startGen) } return nil, false, false case *sNode: // If the branch is an S-node, then the key within the S-node is // compared with the key being searched – these two keys have the // same hashcode prefixes, but they need not be equal. If they are // equal, the corresponding value from the S-node is // returned and a NOTFOUND value otherwise. sn := branch.(*sNode) if bytes.Equal(sn.Key, entry.Key) { return sn.Value, true, true } return nil, false, true default: panic("Ctrie is in an invalid state") } case main.tNode != nil: return cleanReadOnly(main.tNode, lev, parent, c, entry) case main.lNode != nil: // Hash collisions are handled using L-nodes, which are essentially // persistent linked lists. val, ok := main.lNode.lookup(entry) return val, ok, true default: panic("Ctrie is in an invalid state") } }
[ "func", "(", "c", "*", "Ctrie", ")", "ilookup", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "(", "interface", "{", "}", ",", "bool", ",", "bool", ")...
// ilookup attempts to fetch the entry from the Ctrie. The first two return // values are the entry value and whether or not the entry was contained in the // Ctrie. The last bool indicates if the operation succeeded. False means it // should be retried.
[ "ilookup", "attempts", "to", "fetch", "the", "entry", "from", "the", "Ctrie", ".", "The", "first", "two", "return", "values", "are", "the", "entry", "value", "and", "whether", "or", "not", "the", "entry", "was", "contained", "in", "the", "Ctrie", ".", "T...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L538-L588
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
iremove
func (c *Ctrie) iremove(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap does not contain the relevant bit, a key with the // required hashcode prefix is not present in the trie. return nil, false, true } // Otherwise, the relevant branch at index pos is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, the iremove procedure is called // recursively at the next level. in := branch.(*iNode) if startGen == in.gen { return c.iremove(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.iremove(i, entry, lev, parent, startGen) } return nil, false, false case *sNode: // If the branch is an S-node, its key is compared against the key // being removed. sn := branch.(*sNode) if !bytes.Equal(sn.Key, entry.Key) { // If the keys are not equal, the NOTFOUND value is returned. return nil, false, true } // If the keys are equal, a copy of the current node without the // S-node is created. The contraction of the copy is then created // using the toContracted procedure. A successful CAS will // substitute the old C-node with the copied C-node, thus removing // the S-node with the given key from the trie – this is the // linearization point ncn := cn.removed(pos, flag, i.gen) cntr := toContracted(ncn, lev) if gcas(i, main, cntr, c) { if parent != nil { main = gcasRead(i, c) if main.tNode != nil { cleanParent(parent, i, entry.hash, lev-w, c, startGen) } } return sn.Value, true, true } return nil, false, false default: panic("Ctrie is in an invalid state") } case main.tNode != nil: clean(parent, lev-w, c) return nil, false, false case main.lNode != nil: nln := &mainNode{lNode: main.lNode.removed(entry)} if nln.lNode.length() == 1 { nln = entomb(nln.lNode.entry()) } if gcas(i, main, nln, c) { val, ok := main.lNode.lookup(entry) return val, ok, true } return nil, false, true default: panic("Ctrie is in an invalid state") } }
go
func (c *Ctrie) iremove(i *iNode, entry *Entry, lev uint, parent *iNode, startGen *generation) (interface{}, bool, bool) { // Linearization point. main := gcasRead(i, c) switch { case main.cNode != nil: cn := main.cNode flag, pos := flagPos(entry.hash, lev, cn.bmp) if cn.bmp&flag == 0 { // If the bitmap does not contain the relevant bit, a key with the // required hashcode prefix is not present in the trie. return nil, false, true } // Otherwise, the relevant branch at index pos is read from the array. branch := cn.array[pos] switch branch.(type) { case *iNode: // If the branch is an I-node, the iremove procedure is called // recursively at the next level. in := branch.(*iNode) if startGen == in.gen { return c.iremove(in, entry, lev+w, i, startGen) } if gcas(i, main, &mainNode{cNode: cn.renewed(startGen, c)}, c) { return c.iremove(i, entry, lev, parent, startGen) } return nil, false, false case *sNode: // If the branch is an S-node, its key is compared against the key // being removed. sn := branch.(*sNode) if !bytes.Equal(sn.Key, entry.Key) { // If the keys are not equal, the NOTFOUND value is returned. return nil, false, true } // If the keys are equal, a copy of the current node without the // S-node is created. The contraction of the copy is then created // using the toContracted procedure. A successful CAS will // substitute the old C-node with the copied C-node, thus removing // the S-node with the given key from the trie – this is the // linearization point ncn := cn.removed(pos, flag, i.gen) cntr := toContracted(ncn, lev) if gcas(i, main, cntr, c) { if parent != nil { main = gcasRead(i, c) if main.tNode != nil { cleanParent(parent, i, entry.hash, lev-w, c, startGen) } } return sn.Value, true, true } return nil, false, false default: panic("Ctrie is in an invalid state") } case main.tNode != nil: clean(parent, lev-w, c) return nil, false, false case main.lNode != nil: nln := &mainNode{lNode: main.lNode.removed(entry)} if nln.lNode.length() == 1 { nln = entomb(nln.lNode.entry()) } if gcas(i, main, nln, c) { val, ok := main.lNode.lookup(entry) return val, ok, true } return nil, false, true default: panic("Ctrie is in an invalid state") } }
[ "func", "(", "c", "*", "Ctrie", ")", "iremove", "(", "i", "*", "iNode", ",", "entry", "*", "Entry", ",", "lev", "uint", ",", "parent", "*", "iNode", ",", "startGen", "*", "generation", ")", "(", "interface", "{", "}", ",", "bool", ",", "bool", ")...
// iremove attempts to remove the entry from the Ctrie. The first two return // values are the entry value and whether or not the entry was contained in the // Ctrie. The last bool indicates if the operation succeeded. False means it // should be retried.
[ "iremove", "attempts", "to", "remove", "the", "entry", "from", "the", "Ctrie", ".", "The", "first", "two", "return", "values", "are", "the", "entry", "value", "and", "whether", "or", "not", "the", "entry", "was", "contained", "in", "the", "Ctrie", ".", "...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L594-L665
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
toContracted
func toContracted(cn *cNode, lev uint) *mainNode { if lev > 0 && len(cn.array) == 1 { branch := cn.array[0] switch branch.(type) { case *sNode: return entomb(branch.(*sNode)) default: return &mainNode{cNode: cn} } } return &mainNode{cNode: cn} }
go
func toContracted(cn *cNode, lev uint) *mainNode { if lev > 0 && len(cn.array) == 1 { branch := cn.array[0] switch branch.(type) { case *sNode: return entomb(branch.(*sNode)) default: return &mainNode{cNode: cn} } } return &mainNode{cNode: cn} }
[ "func", "toContracted", "(", "cn", "*", "cNode", ",", "lev", "uint", ")", "*", "mainNode", "{", "if", "lev", ">", "0", "&&", "len", "(", "cn", ".", "array", ")", "==", "1", "{", "branch", ":=", "cn", ".", "array", "[", "0", "]", "\n", "switch",...
// toContracted ensures that every I-node except the root points to a C-node // with at least one branch. If a given C-Node has only a single S-node below // it and is not at the root level, a T-node which wraps the S-node is // returned.
[ "toContracted", "ensures", "that", "every", "I", "-", "node", "except", "the", "root", "points", "to", "a", "C", "-", "node", "with", "at", "least", "one", "branch", ".", "If", "a", "given", "C", "-", "Node", "has", "only", "a", "single", "S", "-", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L671-L682
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
toCompressed
func toCompressed(cn *cNode, lev uint) *mainNode { tmpArray := make([]branch, len(cn.array)) for i, sub := range cn.array { switch sub.(type) { case *iNode: inode := sub.(*iNode) mainPtr := (*unsafe.Pointer)(unsafe.Pointer(&inode.main)) main := (*mainNode)(atomic.LoadPointer(mainPtr)) tmpArray[i] = resurrect(inode, main) case *sNode: tmpArray[i] = sub default: panic("Ctrie is in an invalid state") } } return toContracted(&cNode{bmp: cn.bmp, array: tmpArray}, lev) }
go
func toCompressed(cn *cNode, lev uint) *mainNode { tmpArray := make([]branch, len(cn.array)) for i, sub := range cn.array { switch sub.(type) { case *iNode: inode := sub.(*iNode) mainPtr := (*unsafe.Pointer)(unsafe.Pointer(&inode.main)) main := (*mainNode)(atomic.LoadPointer(mainPtr)) tmpArray[i] = resurrect(inode, main) case *sNode: tmpArray[i] = sub default: panic("Ctrie is in an invalid state") } } return toContracted(&cNode{bmp: cn.bmp, array: tmpArray}, lev) }
[ "func", "toCompressed", "(", "cn", "*", "cNode", ",", "lev", "uint", ")", "*", "mainNode", "{", "tmpArray", ":=", "make", "(", "[", "]", "branch", ",", "len", "(", "cn", ".", "array", ")", ")", "\n", "for", "i", ",", "sub", ":=", "range", "cn", ...
// toCompressed compacts the C-node as a performance optimization.
[ "toCompressed", "compacts", "the", "C", "-", "node", "as", "a", "performance", "optimization", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L685-L702
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcas
func gcas(in *iNode, old, n *mainNode, ct *Ctrie) bool { prevPtr := (*unsafe.Pointer)(unsafe.Pointer(&n.prev)) atomic.StorePointer(prevPtr, unsafe.Pointer(old)) if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&in.main)), unsafe.Pointer(old), unsafe.Pointer(n)) { gcasComplete(in, n, ct) return atomic.LoadPointer(prevPtr) == nil } return false }
go
func gcas(in *iNode, old, n *mainNode, ct *Ctrie) bool { prevPtr := (*unsafe.Pointer)(unsafe.Pointer(&n.prev)) atomic.StorePointer(prevPtr, unsafe.Pointer(old)) if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&in.main)), unsafe.Pointer(old), unsafe.Pointer(n)) { gcasComplete(in, n, ct) return atomic.LoadPointer(prevPtr) == nil } return false }
[ "func", "gcas", "(", "in", "*", "iNode", ",", "old", ",", "n", "*", "mainNode", ",", "ct", "*", "Ctrie", ")", "bool", "{", "prevPtr", ":=", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer", "(", "&", "n", ".", "prev", ")",...
// gcas is a generation-compare-and-swap which has semantics similar to RDCSS, // but it does not create the intermediate object except in the case of // failures that occur due to the snapshot being taken. This ensures that the // write occurs only if the Ctrie root generation has remained the same in // addition to the I-node having the expected value.
[ "gcas", "is", "a", "generation", "-", "compare", "-", "and", "-", "swap", "which", "has", "semantics", "similar", "to", "RDCSS", "but", "it", "does", "not", "create", "the", "intermediate", "object", "except", "in", "the", "case", "of", "failures", "that",...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L776-L786
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcasRead
func gcasRead(in *iNode, ctrie *Ctrie) *mainNode { m := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&in.main)))) prev := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) if prev == nil { return m } return gcasComplete(in, m, ctrie) }
go
func gcasRead(in *iNode, ctrie *Ctrie) *mainNode { m := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&in.main)))) prev := (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) if prev == nil { return m } return gcasComplete(in, m, ctrie) }
[ "func", "gcasRead", "(", "in", "*", "iNode", ",", "ctrie", "*", "Ctrie", ")", "*", "mainNode", "{", "m", ":=", "(", "*", "mainNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer"...
// gcasRead performs a GCAS-linearizable read of the I-node's main node.
[ "gcasRead", "performs", "a", "GCAS", "-", "linearizable", "read", "of", "the", "I", "-", "node", "s", "main", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L789-L796
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
gcasComplete
func gcasComplete(i *iNode, m *mainNode, ctrie *Ctrie) *mainNode { for { if m == nil { return nil } prev := (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) root := ctrie.rdcssReadRoot(true) if prev == nil { return m } if prev.failed != nil { // Signals GCAS failure. Swap old value back into I-node. fn := prev.failed if atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&i.main)), unsafe.Pointer(m), unsafe.Pointer(fn)) { return fn } m = (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&i.main)))) continue } if root.gen == i.gen && !ctrie.readOnly { // Commit GCAS. if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)), unsafe.Pointer(prev), nil) { return m } continue } // Generations did not match. Store failed node on prev to signal // I-node's main node must be set back to the previous value. atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)), unsafe.Pointer(prev), unsafe.Pointer(&mainNode{failed: prev})) m = (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&i.main)))) return gcasComplete(i, m, ctrie) } }
go
func gcasComplete(i *iNode, m *mainNode, ctrie *Ctrie) *mainNode { for { if m == nil { return nil } prev := (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)))) root := ctrie.rdcssReadRoot(true) if prev == nil { return m } if prev.failed != nil { // Signals GCAS failure. Swap old value back into I-node. fn := prev.failed if atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&i.main)), unsafe.Pointer(m), unsafe.Pointer(fn)) { return fn } m = (*mainNode)(atomic.LoadPointer( (*unsafe.Pointer)(unsafe.Pointer(&i.main)))) continue } if root.gen == i.gen && !ctrie.readOnly { // Commit GCAS. if atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)), unsafe.Pointer(prev), nil) { return m } continue } // Generations did not match. Store failed node on prev to signal // I-node's main node must be set back to the previous value. atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&m.prev)), unsafe.Pointer(prev), unsafe.Pointer(&mainNode{failed: prev})) m = (*mainNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&i.main)))) return gcasComplete(i, m, ctrie) } }
[ "func", "gcasComplete", "(", "i", "*", "iNode", ",", "m", "*", "mainNode", ",", "ctrie", "*", "Ctrie", ")", "*", "mainNode", "{", "for", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "prev", ":=", "(", "*", "mainNode", ")", ...
// gcasComplete commits the GCAS operation.
[ "gcasComplete", "commits", "the", "GCAS", "operation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L799-L841
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssReadRoot
func (c *Ctrie) rdcssReadRoot(abort bool) *iNode { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss != nil { return c.rdcssComplete(abort) } return r }
go
func (c *Ctrie) rdcssReadRoot(abort bool) *iNode { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss != nil { return c.rdcssComplete(abort) } return r }
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssReadRoot", "(", "abort", "bool", ")", "*", "iNode", "{", "r", ":=", "(", "*", "iNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", ".", "Pointer", ...
// rdcssReadRoot performs a RDCSS-linearizable read of the Ctrie root with the // given priority.
[ "rdcssReadRoot", "performs", "a", "RDCSS", "-", "linearizable", "read", "of", "the", "Ctrie", "root", "with", "the", "given", "priority", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L862-L868
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssRoot
func (c *Ctrie) rdcssRoot(old *iNode, expected *mainNode, nv *iNode) bool { desc := &iNode{ rdcss: &rdcssDescriptor{ old: old, expected: expected, nv: nv, }, } if c.casRoot(old, desc) { c.rdcssComplete(false) return atomic.LoadInt32(&desc.rdcss.committed) == 1 } return false }
go
func (c *Ctrie) rdcssRoot(old *iNode, expected *mainNode, nv *iNode) bool { desc := &iNode{ rdcss: &rdcssDescriptor{ old: old, expected: expected, nv: nv, }, } if c.casRoot(old, desc) { c.rdcssComplete(false) return atomic.LoadInt32(&desc.rdcss.committed) == 1 } return false }
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssRoot", "(", "old", "*", "iNode", ",", "expected", "*", "mainNode", ",", "nv", "*", "iNode", ")", "bool", "{", "desc", ":=", "&", "iNode", "{", "rdcss", ":", "&", "rdcssDescriptor", "{", "old", ":", "old", ...
// rdcssRoot performs a RDCSS on the Ctrie root. This is used to create a // snapshot of the Ctrie by copying the root I-node and setting it to a new // generation.
[ "rdcssRoot", "performs", "a", "RDCSS", "on", "the", "Ctrie", "root", ".", "This", "is", "used", "to", "create", "a", "snapshot", "of", "the", "Ctrie", "by", "copying", "the", "root", "I", "-", "node", "and", "setting", "it", "to", "a", "new", "generati...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L873-L886
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
rdcssComplete
func (c *Ctrie) rdcssComplete(abort bool) *iNode { for { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss == nil { return r } var ( desc = r.rdcss ov = desc.old exp = desc.expected nv = desc.nv ) if abort { if c.casRoot(r, ov) { return ov } continue } oldeMain := gcasRead(ov, c) if oldeMain == exp { // Commit the RDCSS. if c.casRoot(r, nv) { atomic.StoreInt32(&desc.committed, 1) return nv } continue } if c.casRoot(r, ov) { return ov } continue } }
go
func (c *Ctrie) rdcssComplete(abort bool) *iNode { for { r := (*iNode)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&c.root)))) if r.rdcss == nil { return r } var ( desc = r.rdcss ov = desc.old exp = desc.expected nv = desc.nv ) if abort { if c.casRoot(r, ov) { return ov } continue } oldeMain := gcasRead(ov, c) if oldeMain == exp { // Commit the RDCSS. if c.casRoot(r, nv) { atomic.StoreInt32(&desc.committed, 1) return nv } continue } if c.casRoot(r, ov) { return ov } continue } }
[ "func", "(", "c", "*", "Ctrie", ")", "rdcssComplete", "(", "abort", "bool", ")", "*", "iNode", "{", "for", "{", "r", ":=", "(", "*", "iNode", ")", "(", "atomic", ".", "LoadPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "unsafe", "."...
// rdcssComplete commits the RDCSS operation.
[ "rdcssComplete", "commits", "the", "RDCSS", "operation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L889-L924
train
Workiva/go-datastructures
trie/ctrie/ctrie.go
casRoot
func (c *Ctrie) casRoot(ov, nv *iNode) bool { c.assertReadWrite() return atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&c.root)), unsafe.Pointer(ov), unsafe.Pointer(nv)) }
go
func (c *Ctrie) casRoot(ov, nv *iNode) bool { c.assertReadWrite() return atomic.CompareAndSwapPointer( (*unsafe.Pointer)(unsafe.Pointer(&c.root)), unsafe.Pointer(ov), unsafe.Pointer(nv)) }
[ "func", "(", "c", "*", "Ctrie", ")", "casRoot", "(", "ov", ",", "nv", "*", "iNode", ")", "bool", "{", "c", ".", "assertReadWrite", "(", ")", "\n", "return", "atomic", ".", "CompareAndSwapPointer", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", ...
// casRoot performs a CAS on the Ctrie root.
[ "casRoot", "performs", "a", "CAS", "on", "the", "Ctrie", "root", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/ctrie/ctrie.go#L927-L931
train
Workiva/go-datastructures
btree/immutable/node.go
copy
func (n *Node) copy() *Node { cpValues := make([]interface{}, len(n.ChildValues)) copy(cpValues, n.ChildValues) cpKeys := make(Keys, len(n.ChildKeys)) copy(cpKeys, n.ChildKeys) return &Node{ ID: newID(), IsLeaf: n.IsLeaf, ChildValues: cpValues, ChildKeys: cpKeys, } }
go
func (n *Node) copy() *Node { cpValues := make([]interface{}, len(n.ChildValues)) copy(cpValues, n.ChildValues) cpKeys := make(Keys, len(n.ChildKeys)) copy(cpKeys, n.ChildKeys) return &Node{ ID: newID(), IsLeaf: n.IsLeaf, ChildValues: cpValues, ChildKeys: cpKeys, } }
[ "func", "(", "n", "*", "Node", ")", "copy", "(", ")", "*", "Node", "{", "cpValues", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "n", ".", "ChildValues", ")", ")", "\n", "copy", "(", "cpValues", ",", "n", ".", "ChildValu...
// copy makes a deep copy of this node. Required before any mutation.
[ "copy", "makes", "a", "deep", "copy", "of", "this", "node", ".", "Required", "before", "any", "mutation", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L127-L139
train
Workiva/go-datastructures
btree/immutable/node.go
searchKey
func (n *Node) searchKey(comparator Comparator, value interface{}) (*Key, int) { i := n.search(comparator, value) if n.IsLeaf && i == len(n.ChildValues) { // not found return nil, i } if n.IsLeaf { // equal number of ids and values return n.ChildKeys[i], i } if i == len(n.ChildValues) { // we need to go to the farthest node to the write return n.ChildKeys[len(n.ChildKeys)-1], i } return n.ChildKeys[i], i }
go
func (n *Node) searchKey(comparator Comparator, value interface{}) (*Key, int) { i := n.search(comparator, value) if n.IsLeaf && i == len(n.ChildValues) { // not found return nil, i } if n.IsLeaf { // equal number of ids and values return n.ChildKeys[i], i } if i == len(n.ChildValues) { // we need to go to the farthest node to the write return n.ChildKeys[len(n.ChildKeys)-1], i } return n.ChildKeys[i], i }
[ "func", "(", "n", "*", "Node", ")", "searchKey", "(", "comparator", "Comparator", ",", "value", "interface", "{", "}", ")", "(", "*", "Key", ",", "int", ")", "{", "i", ":=", "n", ".", "search", "(", "comparator", ",", "value", ")", "\n", "if", "n...
// searchKey returns the key associated with the provided value. If the // provided value is greater than the highest value in this node and this // node is an internal node, this method returns the last ID and an index // equal to lenValues.
[ "searchKey", "returns", "the", "key", "associated", "with", "the", "provided", "value", ".", "If", "the", "provided", "value", "is", "greater", "than", "the", "highest", "value", "in", "this", "node", "and", "this", "node", "is", "an", "internal", "node", ...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L145-L161
train
Workiva/go-datastructures
btree/immutable/node.go
insert
func (n *Node) insert(comparator Comparator, key *Key) *Key { var overwrittenKey *Key i := n.search(comparator, key.Value) if i == len(n.ChildValues) { n.ChildValues = append(n.ChildValues, key.Value) } else { if n.ChildValues[i] == key.Value { overwrittenKey = n.ChildKeys[i] n.ChildKeys[i] = key return overwrittenKey } else { n.ChildValues = append(n.ChildValues, 0) copy(n.ChildValues[i+1:], n.ChildValues[i:]) n.ChildValues[i] = key.Value } } if n.IsLeaf && i == len(n.ChildKeys) { n.ChildKeys = append(n.ChildKeys, key) } else { n.ChildKeys = append(n.ChildKeys, nil) copy(n.ChildKeys[i+1:], n.ChildKeys[i:]) n.ChildKeys[i] = key } return overwrittenKey }
go
func (n *Node) insert(comparator Comparator, key *Key) *Key { var overwrittenKey *Key i := n.search(comparator, key.Value) if i == len(n.ChildValues) { n.ChildValues = append(n.ChildValues, key.Value) } else { if n.ChildValues[i] == key.Value { overwrittenKey = n.ChildKeys[i] n.ChildKeys[i] = key return overwrittenKey } else { n.ChildValues = append(n.ChildValues, 0) copy(n.ChildValues[i+1:], n.ChildValues[i:]) n.ChildValues[i] = key.Value } } if n.IsLeaf && i == len(n.ChildKeys) { n.ChildKeys = append(n.ChildKeys, key) } else { n.ChildKeys = append(n.ChildKeys, nil) copy(n.ChildKeys[i+1:], n.ChildKeys[i:]) n.ChildKeys[i] = key } return overwrittenKey }
[ "func", "(", "n", "*", "Node", ")", "insert", "(", "comparator", "Comparator", ",", "key", "*", "Key", ")", "*", "Key", "{", "var", "overwrittenKey", "*", "Key", "\n", "i", ":=", "n", ".", "search", "(", "comparator", ",", "key", ".", "Value", ")",...
// insert adds the provided key to this node and returns any ID that has // been overwritten. This method should only be called on leaf nodes.
[ "insert", "adds", "the", "provided", "key", "to", "this", "node", "and", "returns", "any", "ID", "that", "has", "been", "overwritten", ".", "This", "method", "should", "only", "be", "called", "on", "leaf", "nodes", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L165-L191
train
Workiva/go-datastructures
btree/immutable/node.go
delete
func (n *Node) delete(comparator Comparator, key *Key) *Key { i := n.search(comparator, key.Value) if i == len(n.ChildValues) { return nil } n.deleteValueAt(i) n.deleteKeyAt(i) return key }
go
func (n *Node) delete(comparator Comparator, key *Key) *Key { i := n.search(comparator, key.Value) if i == len(n.ChildValues) { return nil } n.deleteValueAt(i) n.deleteKeyAt(i) return key }
[ "func", "(", "n", "*", "Node", ")", "delete", "(", "comparator", "Comparator", ",", "key", "*", "Key", ")", "*", "Key", "{", "i", ":=", "n", ".", "search", "(", "comparator", ",", "key", ".", "Value", ")", "\n", "if", "i", "==", "len", "(", "n"...
// delete removes the provided key from the node and returns any key that // was deleted. Returns nil of the key could not be found.
[ "delete", "removes", "the", "provided", "key", "from", "the", "node", "and", "returns", "any", "key", "that", "was", "deleted", ".", "Returns", "nil", "of", "the", "key", "could", "not", "be", "found", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L195-L205
train
Workiva/go-datastructures
btree/immutable/node.go
replaceKeyAt
func (n *Node) replaceKeyAt(key *Key, i int) { n.ChildKeys[i] = key }
go
func (n *Node) replaceKeyAt(key *Key, i int) { n.ChildKeys[i] = key }
[ "func", "(", "n", "*", "Node", ")", "replaceKeyAt", "(", "key", "*", "Key", ",", "i", "int", ")", "{", "n", ".", "ChildKeys", "[", "i", "]", "=", "key", "\n", "}" ]
// replaceKeyAt replaces the key at index i with the provided id. This does // not do any bounds checking.
[ "replaceKeyAt", "replaces", "the", "key", "at", "index", "i", "with", "the", "provided", "id", ".", "This", "does", "not", "do", "any", "bounds", "checking", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L245-L247
train
Workiva/go-datastructures
btree/immutable/node.go
iter
func (n *Node) iter(comparator Comparator, start, stop interface{}) iterator { pointer := n.search(comparator, start) pointer-- return &sliceIterator{ stop: stop, n: n, pointer: pointer, comparator: comparator, } }
go
func (n *Node) iter(comparator Comparator, start, stop interface{}) iterator { pointer := n.search(comparator, start) pointer-- return &sliceIterator{ stop: stop, n: n, pointer: pointer, comparator: comparator, } }
[ "func", "(", "n", "*", "Node", ")", "iter", "(", "comparator", "Comparator", ",", "start", ",", "stop", "interface", "{", "}", ")", "iterator", "{", "pointer", ":=", "n", ".", "search", "(", "comparator", ",", "start", ")", "\n", "pointer", "--", "\n...
// iter returns an iterator that will iterate through the provided Morton // numbers as they exist in this node.
[ "iter", "returns", "an", "iterator", "that", "will", "iterate", "through", "the", "provided", "Morton", "numbers", "as", "they", "exist", "in", "this", "node", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L256-L265
train
Workiva/go-datastructures
btree/immutable/node.go
splitAt
func (n *Node) splitAt(i int) (interface{}, *Node) { if n.IsLeaf { return n.splitLeafAt(i) } return n.splitInternalAt(i) }
go
func (n *Node) splitAt(i int) (interface{}, *Node) { if n.IsLeaf { return n.splitLeafAt(i) } return n.splitInternalAt(i) }
[ "func", "(", "n", "*", "Node", ")", "splitAt", "(", "i", "int", ")", "(", "interface", "{", "}", ",", "*", "Node", ")", "{", "if", "n", ".", "IsLeaf", "{", "return", "n", ".", "splitLeafAt", "(", "i", ")", "\n", "}", "\n", "return", "n", ".",...
// splitAt breaks this node into two parts and conceptually // returns the left part
[ "splitAt", "breaks", "this", "node", "into", "two", "parts", "and", "conceptually", "returns", "the", "left", "part" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L352-L358
train
Workiva/go-datastructures
btree/immutable/node.go
nodeFromBytes
func nodeFromBytes(t *Tr, data []byte) (*Node, error) { n := &Node{} _, err := n.UnmarshalMsg(data) if err != nil { panic(err) return nil, err } return n, nil }
go
func nodeFromBytes(t *Tr, data []byte) (*Node, error) { n := &Node{} _, err := n.UnmarshalMsg(data) if err != nil { panic(err) return nil, err } return n, nil }
[ "func", "nodeFromBytes", "(", "t", "*", "Tr", ",", "data", "[", "]", "byte", ")", "(", "*", "Node", ",", "error", ")", "{", "n", ":=", "&", "Node", "{", "}", "\n", "_", ",", "err", ":=", "n", ".", "UnmarshalMsg", "(", "data", ")", "\n", "if",...
// nodeFromBytes returns a new node struct deserialized from the provided // bytes. An error is returned for any deserialization errors.
[ "nodeFromBytes", "returns", "a", "new", "node", "struct", "deserialized", "from", "the", "provided", "bytes", ".", "An", "error", "is", "returned", "for", "any", "deserialization", "errors", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/node.go#L420-L429
train
Workiva/go-datastructures
bitarray/encoding.go
Marshal
func Marshal(ba BitArray) ([]byte, error) { if eba, ok := ba.(*bitArray); ok { return eba.Serialize() } else if sba, ok := ba.(*sparseBitArray); ok { return sba.Serialize() } else { return nil, errors.New("not a valid BitArray") } }
go
func Marshal(ba BitArray) ([]byte, error) { if eba, ok := ba.(*bitArray); ok { return eba.Serialize() } else if sba, ok := ba.(*sparseBitArray); ok { return sba.Serialize() } else { return nil, errors.New("not a valid BitArray") } }
[ "func", "Marshal", "(", "ba", "BitArray", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "eba", ",", "ok", ":=", "ba", ".", "(", "*", "bitArray", ")", ";", "ok", "{", "return", "eba", ".", "Serialize", "(", ")", "\n", "}", "else", ...
// Marshal takes a dense or sparse bit array and serializes it to a // byte slice.
[ "Marshal", "takes", "a", "dense", "or", "sparse", "bit", "array", "and", "serializes", "it", "to", "a", "byte", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L28-L36
train
Workiva/go-datastructures
bitarray/encoding.go
Unmarshal
func Unmarshal(input []byte) (BitArray, error) { if len(input) == 0 { return nil, errors.New("no data in input") } if input[0] == 'B' { ret := newBitArray(0) err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else if input[0] == 'S' { ret := newSparseBitArray() err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else { return nil, errors.New("unrecognized encoding") } }
go
func Unmarshal(input []byte) (BitArray, error) { if len(input) == 0 { return nil, errors.New("no data in input") } if input[0] == 'B' { ret := newBitArray(0) err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else if input[0] == 'S' { ret := newSparseBitArray() err := ret.Deserialize(input) if err != nil { return nil, err } return ret, nil } else { return nil, errors.New("unrecognized encoding") } }
[ "func", "Unmarshal", "(", "input", "[", "]", "byte", ")", "(", "BitArray", ",", "error", ")", "{", "if", "len", "(", "input", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"no data in input\"", ")", "\n", "}", "\n", "if", ...
// Unmarshal takes a byte slice, of the same format produced by Marshal, // and returns a BitArray.
[ "Unmarshal", "takes", "a", "byte", "slice", "of", "the", "same", "format", "produced", "by", "Marshal", "and", "returns", "a", "BitArray", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L40-L61
train
Workiva/go-datastructures
bitarray/encoding.go
Serialize
func (ba *sparseBitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'S' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } blocksLen := uint64(len(ba.blocks)) indexLen := uint64(len(ba.indices)) err = binary.Write(w, binary.LittleEndian, blocksLen) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.blocks) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, indexLen) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.indices) if err != nil { return nil, err } return w.Bytes(), nil }
go
func (ba *sparseBitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'S' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } blocksLen := uint64(len(ba.blocks)) indexLen := uint64(len(ba.indices)) err = binary.Write(w, binary.LittleEndian, blocksLen) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.blocks) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, indexLen) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.indices) if err != nil { return nil, err } return w.Bytes(), nil }
[ "func", "(", "ba", "*", "sparseBitArray", ")", "Serialize", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "var", "identifier", "uint8", "=", "'S'", "\n", "err", ":=", "binary", ...
// Serialize converts the sparseBitArray to a byte slice
[ "Serialize", "converts", "the", "sparseBitArray", "to", "a", "byte", "slice" ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L64-L96
train
Workiva/go-datastructures
bitarray/encoding.go
Uint64FromBytes
func Uint64FromBytes(b []byte) (uint64, int) { if len(b) < 8 { return 0, -1 } val := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 return val, 8 }
go
func Uint64FromBytes(b []byte) (uint64, int) { if len(b) < 8 { return 0, -1 } val := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 return val, 8 }
[ "func", "Uint64FromBytes", "(", "b", "[", "]", "byte", ")", "(", "uint64", ",", "int", ")", "{", "if", "len", "(", "b", ")", "<", "8", "{", "return", "0", ",", "-", "1", "\n", "}", "\n", "val", ":=", "uint64", "(", "b", "[", "0", "]", ")", ...
// This function is a copy from the binary package, with some added error // checking to avoid panics. The function will return the value, and the number // of bytes read from the buffer. If the number of bytes is negative, then // not enough bytes were passed in and the return value will be zero.
[ "This", "function", "is", "a", "copy", "from", "the", "binary", "package", "with", "some", "added", "error", "checking", "to", "avoid", "panics", ".", "The", "function", "will", "return", "the", "value", "and", "the", "number", "of", "bytes", "read", "from...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L102-L110
train
Workiva/go-datastructures
bitarray/encoding.go
Deserialize
func (ret *sparseBitArray) Deserialize(incoming []byte) error { var intsize = uint64(s / 8) var curLoc = uint64(1) // Ignore the identifier byte var intsToRead uint64 var bytesRead int intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } curLoc += intsize var nextblock uint64 ret.blocks = make([]block, intsToRead) for i := uint64(0); i < intsToRead; i++ { nextblock, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } ret.blocks[i] = block(nextblock) curLoc += intsize } intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } curLoc += intsize var nextuint uint64 ret.indices = make(uintSlice, intsToRead) for i := uint64(0); i < intsToRead; i++ { nextuint, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } ret.indices[i] = nextuint curLoc += intsize } return nil }
go
func (ret *sparseBitArray) Deserialize(incoming []byte) error { var intsize = uint64(s / 8) var curLoc = uint64(1) // Ignore the identifier byte var intsToRead uint64 var bytesRead int intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } curLoc += intsize var nextblock uint64 ret.blocks = make([]block, intsToRead) for i := uint64(0); i < intsToRead; i++ { nextblock, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } ret.blocks[i] = block(nextblock) curLoc += intsize } intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } curLoc += intsize var nextuint uint64 ret.indices = make(uintSlice, intsToRead) for i := uint64(0); i < intsToRead; i++ { nextuint, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize]) if bytesRead < 0 { return errors.New("Invalid data for BitArray") } ret.indices[i] = nextuint curLoc += intsize } return nil }
[ "func", "(", "ret", "*", "sparseBitArray", ")", "Deserialize", "(", "incoming", "[", "]", "byte", ")", "error", "{", "var", "intsize", "=", "uint64", "(", "s", "/", "8", ")", "\n", "var", "curLoc", "=", "uint64", "(", "1", ")", "\n", "var", "intsTo...
// Deserialize takes the incoming byte slice, and populates the sparseBitArray // with data in the bytes. Note that this will overwrite any capacity // specified when creating the sparseBitArray. Also note that if an error // is returned, the sparseBitArray this is called on might be populated // with partial data.
[ "Deserialize", "takes", "the", "incoming", "byte", "slice", "and", "populates", "the", "sparseBitArray", "with", "data", "in", "the", "bytes", ".", "Note", "that", "this", "will", "overwrite", "any", "capacity", "specified", "when", "creating", "the", "sparseBit...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L117-L157
train
Workiva/go-datastructures
bitarray/encoding.go
Serialize
func (ba *bitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'B' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.lowest) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.highest) if err != nil { return nil, err } var encodedanyset uint8 if ba.anyset { encodedanyset = 1 } else { encodedanyset = 0 } err = binary.Write(w, binary.LittleEndian, encodedanyset) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.blocks) if err != nil { return nil, err } return w.Bytes(), nil }
go
func (ba *bitArray) Serialize() ([]byte, error) { w := new(bytes.Buffer) var identifier uint8 = 'B' err := binary.Write(w, binary.LittleEndian, identifier) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.lowest) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.highest) if err != nil { return nil, err } var encodedanyset uint8 if ba.anyset { encodedanyset = 1 } else { encodedanyset = 0 } err = binary.Write(w, binary.LittleEndian, encodedanyset) if err != nil { return nil, err } err = binary.Write(w, binary.LittleEndian, ba.blocks) if err != nil { return nil, err } return w.Bytes(), nil }
[ "func", "(", "ba", "*", "bitArray", ")", "Serialize", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "var", "identifier", "uint8", "=", "'B'", "\n", "err", ":=", "binary", ".", ...
// Serialize converts the bitArray to a byte slice.
[ "Serialize", "converts", "the", "bitArray", "to", "a", "byte", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L160-L194
train
Workiva/go-datastructures
bitarray/encoding.go
Deserialize
func (ret *bitArray) Deserialize(incoming []byte) error { r := bytes.NewReader(incoming[1:]) // Discard identifier err := binary.Read(r, binary.LittleEndian, &ret.lowest) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &ret.highest) if err != nil { return err } var encodedanyset uint8 err = binary.Read(r, binary.LittleEndian, &encodedanyset) if err != nil { return err } // anyset defaults to false so we don't need an else statement if encodedanyset == 1 { ret.anyset = true } var nextblock block err = binary.Read(r, binary.LittleEndian, &nextblock) for err == nil { ret.blocks = append(ret.blocks, nextblock) err = binary.Read(r, binary.LittleEndian, &nextblock) } if err != io.EOF { return err } return nil }
go
func (ret *bitArray) Deserialize(incoming []byte) error { r := bytes.NewReader(incoming[1:]) // Discard identifier err := binary.Read(r, binary.LittleEndian, &ret.lowest) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &ret.highest) if err != nil { return err } var encodedanyset uint8 err = binary.Read(r, binary.LittleEndian, &encodedanyset) if err != nil { return err } // anyset defaults to false so we don't need an else statement if encodedanyset == 1 { ret.anyset = true } var nextblock block err = binary.Read(r, binary.LittleEndian, &nextblock) for err == nil { ret.blocks = append(ret.blocks, nextblock) err = binary.Read(r, binary.LittleEndian, &nextblock) } if err != io.EOF { return err } return nil }
[ "func", "(", "ret", "*", "bitArray", ")", "Deserialize", "(", "incoming", "[", "]", "byte", ")", "error", "{", "r", ":=", "bytes", ".", "NewReader", "(", "incoming", "[", "1", ":", "]", ")", "\n", "err", ":=", "binary", ".", "Read", "(", "r", ","...
// Deserialize takes the incoming byte slice, and populates the bitArray // with data in the bytes. Note that this will overwrite any capacity // specified when creating the bitArray. Also note that if an error is returned, // the bitArray this is called on might be populated with partial data.
[ "Deserialize", "takes", "the", "incoming", "byte", "slice", "and", "populates", "the", "bitArray", "with", "data", "in", "the", "bytes", ".", "Note", "that", "this", "will", "overwrite", "any", "capacity", "specified", "when", "creating", "the", "bitArray", "....
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/encoding.go#L200-L234
train
Workiva/go-datastructures
btree/plus/btree.go
Iter
func (tree *btree) Iter(key Key) Iterator { if tree.root == nil { return nilIterator() } return tree.root.find(key) }
go
func (tree *btree) Iter(key Key) Iterator { if tree.root == nil { return nilIterator() } return tree.root.find(key) }
[ "func", "(", "tree", "*", "btree", ")", "Iter", "(", "key", "Key", ")", "Iterator", "{", "if", "tree", ".", "root", "==", "nil", "{", "return", "nilIterator", "(", ")", "\n", "}", "\n", "return", "tree", ".", "root", ".", "find", "(", "key", ")",...
// Iter returns an iterator that can be used to traverse the b-tree // starting from the specified key or its successor.
[ "Iter", "returns", "an", "iterator", "that", "can", "be", "used", "to", "traverse", "the", "b", "-", "tree", "starting", "from", "the", "specified", "key", "or", "its", "successor", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/plus/btree.go#L87-L93
train
Workiva/go-datastructures
btree/palm/tree.go
Get
func (ptree *ptree) Get(keys ...common.Comparator) common.Comparators { ga := newGetAction(keys) ptree.checkAndRun(ga) ga.completer.Wait() return ga.result }
go
func (ptree *ptree) Get(keys ...common.Comparator) common.Comparators { ga := newGetAction(keys) ptree.checkAndRun(ga) ga.completer.Wait() return ga.result }
[ "func", "(", "ptree", "*", "ptree", ")", "Get", "(", "keys", "...", "common", ".", "Comparator", ")", "common", ".", "Comparators", "{", "ga", ":=", "newGetAction", "(", "keys", ")", "\n", "ptree", ".", "checkAndRun", "(", "ga", ")", "\n", "ga", ".",...
// Get will retrieve a list of keys from the provided keys.
[ "Get", "will", "retrieve", "a", "list", "of", "keys", "from", "the", "provided", "keys", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/palm/tree.go#L503-L508
train
Workiva/go-datastructures
btree/palm/tree.go
Query
func (ptree *ptree) Query(start, stop common.Comparator) common.Comparators { cmps := make(common.Comparators, 0, 32) aa := newApplyAction(func(cmp common.Comparator) bool { cmps = append(cmps, cmp) return true }, start, stop) ptree.checkAndRun(aa) aa.completer.Wait() return cmps }
go
func (ptree *ptree) Query(start, stop common.Comparator) common.Comparators { cmps := make(common.Comparators, 0, 32) aa := newApplyAction(func(cmp common.Comparator) bool { cmps = append(cmps, cmp) return true }, start, stop) ptree.checkAndRun(aa) aa.completer.Wait() return cmps }
[ "func", "(", "ptree", "*", "ptree", ")", "Query", "(", "start", ",", "stop", "common", ".", "Comparator", ")", "common", ".", "Comparators", "{", "cmps", ":=", "make", "(", "common", ".", "Comparators", ",", "0", ",", "32", ")", "\n", "aa", ":=", "...
// Query will return a list of Comparators that fall within the // provided start and stop Comparators. Start is inclusive while // stop is exclusive, ie [start, stop).
[ "Query", "will", "return", "a", "list", "of", "Comparators", "that", "fall", "within", "the", "provided", "start", "and", "stop", "Comparators", ".", "Start", "is", "inclusive", "while", "stop", "is", "exclusive", "ie", "[", "start", "stop", ")", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/palm/tree.go#L518-L527
train
Workiva/go-datastructures
rtree/hilbert/hilbert.go
chunkRectangles
func chunkRectangles(slice rtree.Rectangles, numParts int64) []rtree.Rectangles { parts := make([]rtree.Rectangles, numParts) for i := int64(0); i < numParts; i++ { parts[i] = slice[i*int64(len(slice))/numParts : (i+1)*int64(len(slice))/numParts] } return parts }
go
func chunkRectangles(slice rtree.Rectangles, numParts int64) []rtree.Rectangles { parts := make([]rtree.Rectangles, numParts) for i := int64(0); i < numParts; i++ { parts[i] = slice[i*int64(len(slice))/numParts : (i+1)*int64(len(slice))/numParts] } return parts }
[ "func", "chunkRectangles", "(", "slice", "rtree", ".", "Rectangles", ",", "numParts", "int64", ")", "[", "]", "rtree", ".", "Rectangles", "{", "parts", ":=", "make", "(", "[", "]", "rtree", ".", "Rectangles", ",", "numParts", ")", "\n", "for", "i", ":=...
// chunkRectangles takes a slice of rtree.Rectangle values and chunks it into `numParts` subslices.
[ "chunkRectangles", "takes", "a", "slice", "of", "rtree", ".", "Rectangle", "values", "and", "chunks", "it", "into", "numParts", "subslices", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rtree/hilbert/hilbert.go#L73-L79
train
Workiva/go-datastructures
sort/sort.go
MultithreadedSortComparators
func MultithreadedSortComparators(comparators Comparators) Comparators { toBeSorted := make(Comparators, len(comparators)) copy(toBeSorted, comparators) var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) if numCPU%2 == 1 { // single core machine numCPU++ } chunks := chunk(toBeSorted, numCPU) wg.Add(len(chunks)) for i := 0; i < len(chunks); i++ { go func(i int) { sortBucket(chunks[i]) wg.Done() }(i) } wg.Wait() todo := make([]Comparators, len(chunks)/2) for { todo = todo[:len(chunks)/2] wg.Add(len(chunks) / 2) for i := 0; i < len(chunks); i += 2 { go func(i int) { todo[i/2] = SymMerge(chunks[i], chunks[i+1]) wg.Done() }(i) } wg.Wait() chunks = copyChunk(todo) if len(chunks) == 1 { break } } return chunks[0] }
go
func MultithreadedSortComparators(comparators Comparators) Comparators { toBeSorted := make(Comparators, len(comparators)) copy(toBeSorted, comparators) var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) if numCPU%2 == 1 { // single core machine numCPU++ } chunks := chunk(toBeSorted, numCPU) wg.Add(len(chunks)) for i := 0; i < len(chunks); i++ { go func(i int) { sortBucket(chunks[i]) wg.Done() }(i) } wg.Wait() todo := make([]Comparators, len(chunks)/2) for { todo = todo[:len(chunks)/2] wg.Add(len(chunks) / 2) for i := 0; i < len(chunks); i += 2 { go func(i int) { todo[i/2] = SymMerge(chunks[i], chunks[i+1]) wg.Done() }(i) } wg.Wait() chunks = copyChunk(todo) if len(chunks) == 1 { break } } return chunks[0] }
[ "func", "MultithreadedSortComparators", "(", "comparators", "Comparators", ")", "Comparators", "{", "toBeSorted", ":=", "make", "(", "Comparators", ",", "len", "(", "comparators", ")", ")", "\n", "copy", "(", "toBeSorted", ",", "comparators", ")", "\n", "var", ...
// MultithreadedSortComparators will take a list of comparators // and sort it using as many threads as are available. The list // is split into buckets for a bucket sort and then recursively // merged using SymMerge.
[ "MultithreadedSortComparators", "will", "take", "a", "list", "of", "comparators", "and", "sort", "it", "using", "as", "many", "threads", "as", "are", "available", ".", "The", "list", "is", "split", "into", "buckets", "for", "a", "bucket", "sort", "and", "the...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/sort/sort.go#L23-L64
train
Workiva/go-datastructures
rtree/hilbert/tree.go
Search
func (tree *tree) Search(rect rtree.Rectangle) rtree.Rectangles { ga := newGetAction(rect) tree.checkAndRun(ga) ga.completer.Wait() return ga.result }
go
func (tree *tree) Search(rect rtree.Rectangle) rtree.Rectangles { ga := newGetAction(rect) tree.checkAndRun(ga) ga.completer.Wait() return ga.result }
[ "func", "(", "tree", "*", "tree", ")", "Search", "(", "rect", "rtree", ".", "Rectangle", ")", "rtree", ".", "Rectangles", "{", "ga", ":=", "newGetAction", "(", "rect", ")", "\n", "tree", ".", "checkAndRun", "(", "ga", ")", "\n", "ga", ".", "completer...
// Search will return a list of rectangles that intersect the provided // rectangle.
[ "Search", "will", "return", "a", "list", "of", "rectangles", "that", "intersect", "the", "provided", "rectangle", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rtree/hilbert/tree.go#L403-L408
train
Workiva/go-datastructures
list/persistent.go
Length
func (l *list) Length() uint { curr := l length := uint(0) for { length += 1 tail, _ := curr.Tail() if tail.IsEmpty() { return length } curr = tail.(*list) } }
go
func (l *list) Length() uint { curr := l length := uint(0) for { length += 1 tail, _ := curr.Tail() if tail.IsEmpty() { return length } curr = tail.(*list) } }
[ "func", "(", "l", "*", "list", ")", "Length", "(", ")", "uint", "{", "curr", ":=", "l", "\n", "length", ":=", "uint", "(", "0", ")", "\n", "for", "{", "length", "+=", "1", "\n", "tail", ",", "_", ":=", "curr", ".", "Tail", "(", ")", "\n", "...
// Length returns the number of items in the list.
[ "Length", "returns", "the", "number", "of", "items", "in", "the", "list", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L169-L180
train
Workiva/go-datastructures
list/persistent.go
Get
func (l *list) Get(pos uint) (interface{}, bool) { if pos == 0 { return l.head, true } return l.tail.Get(pos - 1) }
go
func (l *list) Get(pos uint) (interface{}, bool) { if pos == 0 { return l.head, true } return l.tail.Get(pos - 1) }
[ "func", "(", "l", "*", "list", ")", "Get", "(", "pos", "uint", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "pos", "==", "0", "{", "return", "l", ".", "head", ",", "true", "\n", "}", "\n", "return", "l", ".", "tail", ".", "...
// Get returns the item at the given position or an error if the position is // invalid.
[ "Get", "returns", "the", "item", "at", "the", "given", "position", "or", "an", "error", "if", "the", "position", "is", "invalid", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L202-L207
train
Workiva/go-datastructures
list/persistent.go
Remove
func (l *list) Remove(pos uint) (PersistentList, error) { if pos == 0 { nl, _ := l.Tail() return nl, nil } nl, err := l.tail.Remove(pos - 1) if err != nil { return nil, err } return &list{l.head, nl}, nil }
go
func (l *list) Remove(pos uint) (PersistentList, error) { if pos == 0 { nl, _ := l.Tail() return nl, nil } nl, err := l.tail.Remove(pos - 1) if err != nil { return nil, err } return &list{l.head, nl}, nil }
[ "func", "(", "l", "*", "list", ")", "Remove", "(", "pos", "uint", ")", "(", "PersistentList", ",", "error", ")", "{", "if", "pos", "==", "0", "{", "nl", ",", "_", ":=", "l", ".", "Tail", "(", ")", "\n", "return", "nl", ",", "nil", "\n", "}", ...
// Remove will remove the item at the given position, returning the new list or // an error if the position is invalid.
[ "Remove", "will", "remove", "the", "item", "at", "the", "given", "position", "returning", "the", "new", "list", "or", "an", "error", "if", "the", "position", "is", "invalid", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L211-L222
train
Workiva/go-datastructures
list/persistent.go
Find
func (l *list) Find(pred func(interface{}) bool) (interface{}, bool) { if pred(l.head) { return l.head, true } return l.tail.Find(pred) }
go
func (l *list) Find(pred func(interface{}) bool) (interface{}, bool) { if pred(l.head) { return l.head, true } return l.tail.Find(pred) }
[ "func", "(", "l", "*", "list", ")", "Find", "(", "pred", "func", "(", "interface", "{", "}", ")", "bool", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "pred", "(", "l", ".", "head", ")", "{", "return", "l", ".", "head", ",", ...
// Find applies the predicate function to the list and returns the first item // which matches.
[ "Find", "applies", "the", "predicate", "function", "to", "the", "list", "and", "returns", "the", "first", "item", "which", "matches", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L226-L231
train
Workiva/go-datastructures
list/persistent.go
FindIndex
func (l *list) FindIndex(pred func(interface{}) bool) int { curr := l idx := 0 for { if pred(curr.head) { return idx } tail, _ := curr.Tail() if tail.IsEmpty() { return -1 } curr = tail.(*list) idx += 1 } }
go
func (l *list) FindIndex(pred func(interface{}) bool) int { curr := l idx := 0 for { if pred(curr.head) { return idx } tail, _ := curr.Tail() if tail.IsEmpty() { return -1 } curr = tail.(*list) idx += 1 } }
[ "func", "(", "l", "*", "list", ")", "FindIndex", "(", "pred", "func", "(", "interface", "{", "}", ")", "bool", ")", "int", "{", "curr", ":=", "l", "\n", "idx", ":=", "0", "\n", "for", "{", "if", "pred", "(", "curr", ".", "head", ")", "{", "re...
// FindIndex applies the predicate function to the list and returns the index // of the first item which matches or -1 if there is no match.
[ "FindIndex", "applies", "the", "predicate", "function", "to", "the", "list", "and", "returns", "the", "index", "of", "the", "first", "item", "which", "matches", "or", "-", "1", "if", "there", "is", "no", "match", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L235-L249
train
Workiva/go-datastructures
list/persistent.go
Map
func (l *list) Map(f func(interface{}) interface{}) []interface{} { return append(l.tail.Map(f), f(l.head)) }
go
func (l *list) Map(f func(interface{}) interface{}) []interface{} { return append(l.tail.Map(f), f(l.head)) }
[ "func", "(", "l", "*", "list", ")", "Map", "(", "f", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "[", "]", "interface", "{", "}", "{", "return", "append", "(", "l", ".", "tail", ".", "Map", "(", "f", ")", ",", "f", ...
// Map applies the function to each entry in the list and returns the resulting // slice.
[ "Map", "applies", "the", "function", "to", "each", "entry", "in", "the", "list", "and", "returns", "the", "resulting", "slice", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/list/persistent.go#L253-L255
train
Workiva/go-datastructures
numerics/hilbert/hilbert.go
Encode
func Encode(x, y int32) int64 { var rx, ry int32 var d int64 for s := int32(n / 2); s > 0; s /= 2 { rx = boolToInt(x&s > 0) ry = boolToInt(y&s > 0) d += int64(int64(s) * int64(s) * int64(((3 * rx) ^ ry))) rotate(s, rx, ry, &x, &y) } return d }
go
func Encode(x, y int32) int64 { var rx, ry int32 var d int64 for s := int32(n / 2); s > 0; s /= 2 { rx = boolToInt(x&s > 0) ry = boolToInt(y&s > 0) d += int64(int64(s) * int64(s) * int64(((3 * rx) ^ ry))) rotate(s, rx, ry, &x, &y) } return d }
[ "func", "Encode", "(", "x", ",", "y", "int32", ")", "int64", "{", "var", "rx", ",", "ry", "int32", "\n", "var", "d", "int64", "\n", "for", "s", ":=", "int32", "(", "n", "/", "2", ")", ";", "s", ">", "0", ";", "s", "/=", "2", "{", "rx", "=...
// Encode will encode the provided x and y coordinates into a Hilbert // distance.
[ "Encode", "will", "encode", "the", "provided", "x", "and", "y", "coordinates", "into", "a", "Hilbert", "distance", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/hilbert/hilbert.go#L62-L73
train
Workiva/go-datastructures
numerics/hilbert/hilbert.go
Decode
func Decode(h int64) (int32, int32) { var ry, rx int64 var x, y int32 t := h for s := int64(1); s < int64(n); s *= 2 { rx = 1 & (t / 2) ry = 1 & (t ^ rx) rotate(int32(s), int32(rx), int32(ry), &x, &y) x += int32(s * rx) y += int32(s * ry) t /= 4 } return x, y }
go
func Decode(h int64) (int32, int32) { var ry, rx int64 var x, y int32 t := h for s := int64(1); s < int64(n); s *= 2 { rx = 1 & (t / 2) ry = 1 & (t ^ rx) rotate(int32(s), int32(rx), int32(ry), &x, &y) x += int32(s * rx) y += int32(s * ry) t /= 4 } return x, y }
[ "func", "Decode", "(", "h", "int64", ")", "(", "int32", ",", "int32", ")", "{", "var", "ry", ",", "rx", "int64", "\n", "var", "x", ",", "y", "int32", "\n", "t", ":=", "h", "\n", "for", "s", ":=", "int64", "(", "1", ")", ";", "s", "<", "int6...
// Decode will decode the provided Hilbert distance into a corresponding // x and y value, respectively.
[ "Decode", "will", "decode", "the", "provided", "Hilbert", "distance", "into", "a", "corresponding", "x", "and", "y", "value", "respectively", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/hilbert/hilbert.go#L77-L92
train
Workiva/go-datastructures
trie/yfast/entries.go
insert
func (entries *Entries) insert(entry Entry) Entry { i := entries.search(entry.Key()) if i == len(*entries) { *entries = append(*entries, entry) return nil } if (*entries)[i].Key() == entry.Key() { oldEntry := (*entries)[i] (*entries)[i] = entry return oldEntry } (*entries) = append(*entries, nil) copy((*entries)[i+1:], (*entries)[i:]) (*entries)[i] = entry return nil }
go
func (entries *Entries) insert(entry Entry) Entry { i := entries.search(entry.Key()) if i == len(*entries) { *entries = append(*entries, entry) return nil } if (*entries)[i].Key() == entry.Key() { oldEntry := (*entries)[i] (*entries)[i] = entry return oldEntry } (*entries) = append(*entries, nil) copy((*entries)[i+1:], (*entries)[i:]) (*entries)[i] = entry return nil }
[ "func", "(", "entries", "*", "Entries", ")", "insert", "(", "entry", "Entry", ")", "Entry", "{", "i", ":=", "entries", ".", "search", "(", "entry", ".", "Key", "(", ")", ")", "\n", "if", "i", "==", "len", "(", "*", "entries", ")", "{", "*", "en...
// insert will insert the provided entry into this list of // entries. Returned is an entry if an entry already exists // for the provided key. If nothing is overwritten, Entry // will be nil.
[ "insert", "will", "insert", "the", "provided", "entry", "into", "this", "list", "of", "entries", ".", "Returned", "is", "an", "entry", "if", "an", "entry", "already", "exists", "for", "the", "provided", "key", ".", "If", "nothing", "is", "overwritten", "En...
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L53-L71
train
Workiva/go-datastructures
trie/yfast/entries.go
delete
func (entries *Entries) delete(key uint64) Entry { i := entries.search(key) if i == len(*entries) { // key not found return nil } if (*entries)[i].Key() != key { return nil } oldEntry := (*entries)[i] copy((*entries)[i:], (*entries)[i+1:]) (*entries)[len(*entries)-1] = nil // GC *entries = (*entries)[:len(*entries)-1] return oldEntry }
go
func (entries *Entries) delete(key uint64) Entry { i := entries.search(key) if i == len(*entries) { // key not found return nil } if (*entries)[i].Key() != key { return nil } oldEntry := (*entries)[i] copy((*entries)[i:], (*entries)[i+1:]) (*entries)[len(*entries)-1] = nil // GC *entries = (*entries)[:len(*entries)-1] return oldEntry }
[ "func", "(", "entries", "*", "Entries", ")", "delete", "(", "key", "uint64", ")", "Entry", "{", "i", ":=", "entries", ".", "search", "(", "key", ")", "\n", "if", "i", "==", "len", "(", "*", "entries", ")", "{", "return", "nil", "\n", "}", "\n", ...
// delete will remove the provided key from this list of entries. // Returned is a deleted Entry. This will be nil if the key // cannot be found.
[ "delete", "will", "remove", "the", "provided", "key", "from", "this", "list", "of", "entries", ".", "Returned", "is", "a", "deleted", "Entry", ".", "This", "will", "be", "nil", "if", "the", "key", "cannot", "be", "found", "." ]
f07cbe3f82ca2fd6e5ab94afce65fe43319f675f
https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/yfast/entries.go#L76-L91
train