repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
lightninglabs/neutrino | headerfs/store.go | FetchHeader | func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
height, err := f.heightFromHash(hash)
if err != nil {
return nil, err
}
return f.readHeader(height)
} | go | func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
height, err := f.heightFromHash(hash)
if err != nil {
return nil, err
}
return f.readHeader(height)
} | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"FetchHeader",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"// Lock store for read.",
"f",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defe... | // FetchHeader returns the filter header that corresponds to the passed block
// height. | [
"FetchHeader",
"returns",
"the",
"filter",
"header",
"that",
"corresponds",
"to",
"the",
"passed",
"block",
"height",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L698-L709 | train |
lightninglabs/neutrino | headerfs/store.go | FetchHeaderByHeight | func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
return f.readHeader(height)
} | go | func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
return f.readHeader(height)
} | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"FetchHeaderByHeight",
"(",
"height",
"uint32",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"// Lock store for read.",
"f",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",... | // FetchHeaderByHeight returns the filter header for a particular block height. | [
"FetchHeaderByHeight",
"returns",
"the",
"filter",
"header",
"for",
"a",
"particular",
"block",
"height",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L712-L718 | train |
lightninglabs/neutrino | headerfs/store.go | FetchHeaderAncestors | func (f *FilterHeaderStore) FetchHeaderAncestors(numHeaders uint32,
stopHash *chainhash.Hash) ([]chainhash.Hash, uint32, error) {
// First, we'll find the final header in the range, this will be the
// ending height of our scan.
endHeight, err := f.heightFromHash(stopHash)
if err != nil {
return nil, 0, err
}
... | go | func (f *FilterHeaderStore) FetchHeaderAncestors(numHeaders uint32,
stopHash *chainhash.Hash) ([]chainhash.Hash, uint32, error) {
// First, we'll find the final header in the range, this will be the
// ending height of our scan.
endHeight, err := f.heightFromHash(stopHash)
if err != nil {
return nil, 0, err
}
... | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"FetchHeaderAncestors",
"(",
"numHeaders",
"uint32",
",",
"stopHash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"uint32",
",",
"error",
")",
"{",
"// First, we'll find t... | // FetchHeaderAncestors fetches the numHeaders filter headers that are the
// ancestors of the target stop block hash. A total of numHeaders+1 headers will be
// returned, as we'll walk back numHeaders distance to collect each header,
// then return the final header specified by the stop hash. We'll also return
// the ... | [
"FetchHeaderAncestors",
"fetches",
"the",
"numHeaders",
"filter",
"headers",
"that",
"are",
"the",
"ancestors",
"of",
"the",
"target",
"stop",
"block",
"hash",
".",
"A",
"total",
"of",
"numHeaders",
"+",
"1",
"headers",
"will",
"be",
"returned",
"as",
"we",
... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L726-L743 | train |
lightninglabs/neutrino | headerfs/store.go | toIndexEntry | func (f *FilterHeader) toIndexEntry() headerEntry {
return headerEntry{
hash: f.HeaderHash,
height: f.Height,
}
} | go | func (f *FilterHeader) toIndexEntry() headerEntry {
return headerEntry{
hash: f.HeaderHash,
height: f.Height,
}
} | [
"func",
"(",
"f",
"*",
"FilterHeader",
")",
"toIndexEntry",
"(",
")",
"headerEntry",
"{",
"return",
"headerEntry",
"{",
"hash",
":",
"f",
".",
"HeaderHash",
",",
"height",
":",
"f",
".",
"Height",
",",
"}",
"\n",
"}"
] | // toIndexEntry converts the filter header into a index entry to be stored
// within the database. | [
"toIndexEntry",
"converts",
"the",
"filter",
"header",
"into",
"a",
"index",
"entry",
"to",
"be",
"stored",
"within",
"the",
"database",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L762-L767 | train |
lightninglabs/neutrino | headerfs/store.go | WriteHeaders | func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// If there are 0 headers to be written, return immediately. This
// prevents the newTip assignment from panicking because of an index
// of -1.
if len(hdrs) == 0 {
return nil
}
... | go | func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// If there are 0 headers to be written, return immediately. This
// prevents the newTip assignment from panicking because of an index
// of -1.
if len(hdrs) == 0 {
return nil
}
... | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"WriteHeaders",
"(",
"hdrs",
"...",
"FilterHeader",
")",
"error",
"{",
"// Lock store for write.",
"f",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
... | // WriteHeaders writes a batch of filter headers to persistent storage. The
// headers themselves are appended to the flat file, and then the index updated
// to reflect the new entires. | [
"WriteHeaders",
"writes",
"a",
"batch",
"of",
"filter",
"headers",
"to",
"persistent",
"storage",
".",
"The",
"headers",
"themselves",
"are",
"appended",
"to",
"the",
"flat",
"file",
"and",
"then",
"the",
"index",
"updated",
"to",
"reflect",
"the",
"new",
"e... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L772-L809 | train |
lightninglabs/neutrino | headerfs/store.go | ChainTip | func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
_, tipHeight, err := f.chainTip()
if err != nil {
return nil, 0, fmt.Errorf("unable to fetch chain tip: %v", err)
}
latestHeader, err := f.readHeader(tipHeight)
if err != nil... | go | func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
_, tipHeight, err := f.chainTip()
if err != nil {
return nil, 0, fmt.Errorf("unable to fetch chain tip: %v", err)
}
latestHeader, err := f.readHeader(tipHeight)
if err != nil... | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"ChainTip",
"(",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"uint32",
",",
"error",
")",
"{",
"// Lock store for read.",
"f",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mtx",
".",... | // ChainTip returns the latest filter header and height known to the
// FilterHeaderStore. | [
"ChainTip",
"returns",
"the",
"latest",
"filter",
"header",
"and",
"height",
"known",
"to",
"the",
"FilterHeaderStore",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L813-L829 | train |
lightninglabs/neutrino | headerfs/store.go | RollbackLastBlock | func (f *FilterHeaderStore) RollbackLastBlock(newTip *chainhash.Hash) (*waddrmgr.BlockStamp, error) {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// First, we'll obtain the latest height that the index knows of.
_, chainTipHeight, err := f.chainTip()
if err != nil {
return nil, err
}
// With ... | go | func (f *FilterHeaderStore) RollbackLastBlock(newTip *chainhash.Hash) (*waddrmgr.BlockStamp, error) {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// First, we'll obtain the latest height that the index knows of.
_, chainTipHeight, err := f.chainTip()
if err != nil {
return nil, err
}
// With ... | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"RollbackLastBlock",
"(",
"newTip",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"waddrmgr",
".",
"BlockStamp",
",",
"error",
")",
"{",
"// Lock store for write.",
"f",
".",
"mtx",
".",
"Lock",
"(",
")",
... | // RollbackLastBlock rollsback both the index, and on-disk header file by a
// _single_ filter header. This method is meant to be used in the case of
// re-org which disconnects the latest filter header from the end of the main
// chain. The information about the latest header tip after truncation is
// returned. | [
"RollbackLastBlock",
"rollsback",
"both",
"the",
"index",
"and",
"on",
"-",
"disk",
"header",
"file",
"by",
"a",
"_single_",
"filter",
"header",
".",
"This",
"method",
"is",
"meant",
"to",
"be",
"used",
"in",
"the",
"case",
"of",
"re",
"-",
"org",
"which... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/store.go#L836-L869 | train |
Workiva/go-datastructures | numerics/optimization/global.go | search | func (results *results) search(result *nmVertex) int {
return sort.Search(len(results.vertices), func(i int) bool {
return !results.vertices[i].less(results.config, result)
})
} | go | func (results *results) search(result *nmVertex) int {
return sort.Search(len(results.vertices), func(i int) bool {
return !results.vertices[i].less(results.config, result)
})
} | [
"func",
"(",
"results",
"*",
"results",
")",
"search",
"(",
"result",
"*",
"nmVertex",
")",
"int",
"{",
"return",
"sort",
".",
"Search",
"(",
"len",
"(",
"results",
".",
"vertices",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"!"... | // search will search this list of results based on order, order
// being defined in the NelderMeadConfiguration, that is a defined
// target will be treated | [
"search",
"will",
"search",
"this",
"list",
"of",
"results",
"based",
"on",
"order",
"order",
"being",
"defined",
"in",
"the",
"NelderMeadConfiguration",
"that",
"is",
"a",
"defined",
"target",
"will",
"be",
"treated"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/global.go#L79-L83 | train |
Workiva/go-datastructures | numerics/optimization/global.go | reSort | func (results *results) reSort(vertex *nmVertex) {
results.insert(vertex)
bestGuess := results.vertices[0]
sigma := calculateSigma(len(results.config.Vars), len(results.vertices))
results.pbs.calculateProbabilities(bestGuess, sigma)
results.pbs.sort()
} | go | func (results *results) reSort(vertex *nmVertex) {
results.insert(vertex)
bestGuess := results.vertices[0]
sigma := calculateSigma(len(results.config.Vars), len(results.vertices))
results.pbs.calculateProbabilities(bestGuess, sigma)
results.pbs.sort()
} | [
"func",
"(",
"results",
"*",
"results",
")",
"reSort",
"(",
"vertex",
"*",
"nmVertex",
")",
"{",
"results",
".",
"insert",
"(",
"vertex",
")",
"\n\n",
"bestGuess",
":=",
"results",
".",
"vertices",
"[",
"0",
"]",
"\n",
"sigma",
":=",
"calculateSigma",
... | // reSort will re-sort the list of possible guess vertices
// based upon the latest calculated result. It was also
// add this result to the list of results. | [
"reSort",
"will",
"re",
"-",
"sort",
"the",
"list",
"of",
"possible",
"guess",
"vertices",
"based",
"upon",
"the",
"latest",
"calculated",
"result",
".",
"It",
"was",
"also",
"add",
"this",
"result",
"to",
"the",
"list",
"of",
"results",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/global.go#L145-L152 | train |
Workiva/go-datastructures | rangetree/immutable.go | Add | func (irt *immutableRangeTree) Add(entries ...Entry) *immutableRangeTree {
if len(entries) == 0 {
return irt
}
cache := newCache(irt.dimensions)
top := make(orderedNodes, len(irt.top))
copy(top, irt.top)
added := uint64(0)
for _, entry := range entries {
irt.add(&top, cache, entry, &added)
}
tree := newI... | go | func (irt *immutableRangeTree) Add(entries ...Entry) *immutableRangeTree {
if len(entries) == 0 {
return irt
}
cache := newCache(irt.dimensions)
top := make(orderedNodes, len(irt.top))
copy(top, irt.top)
added := uint64(0)
for _, entry := range entries {
irt.add(&top, cache, entry, &added)
}
tree := newI... | [
"func",
"(",
"irt",
"*",
"immutableRangeTree",
")",
"Add",
"(",
"entries",
"...",
"Entry",
")",
"*",
"immutableRangeTree",
"{",
"if",
"len",
"(",
"entries",
")",
"==",
"0",
"{",
"return",
"irt",
"\n",
"}",
"\n\n",
"cache",
":=",
"newCache",
"(",
"irt",... | // Add will add the provided entries into the tree and return
// a new tree with those entries added. | [
"Add",
"will",
"add",
"the",
"provided",
"entries",
"into",
"the",
"tree",
"and",
"return",
"a",
"new",
"tree",
"with",
"those",
"entries",
"added",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/immutable.go#L78-L95 | train |
Workiva/go-datastructures | rangetree/immutable.go | InsertAtDimension | func (irt *immutableRangeTree) InsertAtDimension(dimension uint64,
index, number int64) (*immutableRangeTree, Entries, Entries) {
if dimension > irt.dimensions || number == 0 {
return irt, nil, nil
}
modified, deleted := make(Entries, 0, 100), make(Entries, 0, 100)
tree := newImmutableRangeTree(irt.dimensions... | go | func (irt *immutableRangeTree) InsertAtDimension(dimension uint64,
index, number int64) (*immutableRangeTree, Entries, Entries) {
if dimension > irt.dimensions || number == 0 {
return irt, nil, nil
}
modified, deleted := make(Entries, 0, 100), make(Entries, 0, 100)
tree := newImmutableRangeTree(irt.dimensions... | [
"func",
"(",
"irt",
"*",
"immutableRangeTree",
")",
"InsertAtDimension",
"(",
"dimension",
"uint64",
",",
"index",
",",
"number",
"int64",
")",
"(",
"*",
"immutableRangeTree",
",",
"Entries",
",",
"Entries",
")",
"{",
"if",
"dimension",
">",
"irt",
".",
"d... | // InsertAtDimension will increment items at and above the given index
// by the number provided. Provide a negative number to to decrement.
// Returned are two lists and the modified tree. The first list is a
// list of entries that were moved. The second is a list entries that
// were deleted. These lists are exc... | [
"InsertAtDimension",
"will",
"increment",
"items",
"at",
"and",
"above",
"the",
"given",
"index",
"by",
"the",
"number",
"provided",
".",
"Provide",
"a",
"negative",
"number",
"to",
"to",
"decrement",
".",
"Returned",
"are",
"two",
"lists",
"and",
"the",
"mo... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/immutable.go#L102-L120 | train |
Workiva/go-datastructures | threadsafe/err/error.go | Set | func (e *Error) Set(err error) {
e.lock.Lock()
defer e.lock.Unlock()
e.err = err
} | go | func (e *Error) Set(err error) {
e.lock.Lock()
defer e.lock.Unlock()
e.err = err
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Set",
"(",
"err",
"error",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"e",
".",
"err",
"=",
"err",
"\n",
"}"
] | // Set will set the error of this structure to the provided
// value. | [
"Set",
"will",
"set",
"the",
"error",
"of",
"this",
"structure",
"to",
"the",
"provided",
"value",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/threadsafe/err/error.go#L36-L41 | train |
Workiva/go-datastructures | threadsafe/err/error.go | Get | func (e *Error) Get() error {
e.lock.RLock()
defer e.lock.RUnlock()
return e.err
} | go | func (e *Error) Get() error {
e.lock.RLock()
defer e.lock.RUnlock()
return e.err
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Get",
"(",
")",
"error",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // Get will return any error associated with this structure. | [
"Get",
"will",
"return",
"any",
"error",
"associated",
"with",
"this",
"structure",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/threadsafe/err/error.go#L44-L49 | train |
Workiva/go-datastructures | rangetree/orderedtree.go | add | func (ot *orderedTree) add(entry Entry) *node {
var node *node
list := &ot.top
for i := uint64(1); i <= ot.dimensions; i++ {
if isLastDimension(ot.dimensions, i) {
overwritten := list.add(
newNode(entry.ValueAtDimension(i), entry, false),
)
if overwritten == nil {
ot.number++
}
return overw... | go | func (ot *orderedTree) add(entry Entry) *node {
var node *node
list := &ot.top
for i := uint64(1); i <= ot.dimensions; i++ {
if isLastDimension(ot.dimensions, i) {
overwritten := list.add(
newNode(entry.ValueAtDimension(i), entry, false),
)
if overwritten == nil {
ot.number++
}
return overw... | [
"func",
"(",
"ot",
"*",
"orderedTree",
")",
"add",
"(",
"entry",
"Entry",
")",
"*",
"node",
"{",
"var",
"node",
"*",
"node",
"\n",
"list",
":=",
"&",
"ot",
".",
"top",
"\n\n",
"for",
"i",
":=",
"uint64",
"(",
"1",
")",
";",
"i",
"<=",
"ot",
"... | // add will add the provided entry to the rangetree and return an
// entry if one was overwritten. | [
"add",
"will",
"add",
"the",
"provided",
"entry",
"to",
"the",
"rangetree",
"and",
"return",
"an",
"entry",
"if",
"one",
"was",
"overwritten",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/orderedtree.go#L44-L63 | train |
Workiva/go-datastructures | slice/int64.go | Search | func (s Int64Slice) Search(x int64) int {
return sort.Search(len(s), func(i int) bool {
return s[i] >= x
})
} | go | func (s Int64Slice) Search(x int64) int {
return sort.Search(len(s), func(i int) bool {
return s[i] >= x
})
} | [
"func",
"(",
"s",
"Int64Slice",
")",
"Search",
"(",
"x",
"int64",
")",
"int",
"{",
"return",
"sort",
".",
"Search",
"(",
"len",
"(",
"s",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
">=",
"x",
"\n",
"}",... | // Search will search this slice and return an index that corresponds
// to the lowest position of that value. You'll need to check
// separately if the value at that position is equal to x. The
// behavior of this method is undefinited if the slice is not sorted. | [
"Search",
"will",
"search",
"this",
"slice",
"and",
"return",
"an",
"index",
"that",
"corresponds",
"to",
"the",
"lowest",
"position",
"of",
"that",
"value",
".",
"You",
"ll",
"need",
"to",
"check",
"separately",
"if",
"the",
"value",
"at",
"that",
"positi... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/int64.go#L45-L49 | train |
Workiva/go-datastructures | slice/int64.go | Exists | func (s Int64Slice) Exists(x int64) bool {
i := s.Search(x)
if i == len(s) {
return false
}
return s[i] == x
} | go | func (s Int64Slice) Exists(x int64) bool {
i := s.Search(x)
if i == len(s) {
return false
}
return s[i] == x
} | [
"func",
"(",
"s",
"Int64Slice",
")",
"Exists",
"(",
"x",
"int64",
")",
"bool",
"{",
"i",
":=",
"s",
".",
"Search",
"(",
"x",
")",
"\n",
"if",
"i",
"==",
"len",
"(",
"s",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"s",
"[",
"i",... | // Exists returns a bool indicating if the provided value exists
// in this list. This has undefined behavior if the list is not
// sorted. | [
"Exists",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"value",
"exists",
"in",
"this",
"list",
".",
"This",
"has",
"undefined",
"behavior",
"if",
"the",
"list",
"is",
"not",
"sorted",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/int64.go#L65-L72 | train |
Workiva/go-datastructures | slice/int64.go | Insert | func (s Int64Slice) Insert(x int64) Int64Slice {
i := s.Search(x)
if i == len(s) {
return append(s, x)
}
if s[i] == x {
return s
}
s = append(s, 0)
copy(s[i+1:], s[i:])
s[i] = x
return s
} | go | func (s Int64Slice) Insert(x int64) Int64Slice {
i := s.Search(x)
if i == len(s) {
return append(s, x)
}
if s[i] == x {
return s
}
s = append(s, 0)
copy(s[i+1:], s[i:])
s[i] = x
return s
} | [
"func",
"(",
"s",
"Int64Slice",
")",
"Insert",
"(",
"x",
"int64",
")",
"Int64Slice",
"{",
"i",
":=",
"s",
".",
"Search",
"(",
"x",
")",
"\n",
"if",
"i",
"==",
"len",
"(",
"s",
")",
"{",
"return",
"append",
"(",
"s",
",",
"x",
")",
"\n",
"}",
... | // Insert will insert x into the sorted position in this list
// and return a list with the value added. If this slice has not
// been sorted Insert's behavior is undefined. | [
"Insert",
"will",
"insert",
"x",
"into",
"the",
"sorted",
"position",
"in",
"this",
"list",
"and",
"return",
"a",
"list",
"with",
"the",
"value",
"added",
".",
"If",
"this",
"slice",
"has",
"not",
"been",
"sorted",
"Insert",
"s",
"behavior",
"is",
"undef... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/int64.go#L77-L91 | train |
Workiva/go-datastructures | btree/immutable/config.go | DefaultConfig | func DefaultConfig(persister Persister, comparator Comparator) Config {
return Config{
NodeWidth: 10000,
Persister: persister,
Comparator: comparator,
}
} | go | func DefaultConfig(persister Persister, comparator Comparator) Config {
return Config{
NodeWidth: 10000,
Persister: persister,
Comparator: comparator,
}
} | [
"func",
"DefaultConfig",
"(",
"persister",
"Persister",
",",
"comparator",
"Comparator",
")",
"Config",
"{",
"return",
"Config",
"{",
"NodeWidth",
":",
"10000",
",",
"Persister",
":",
"persister",
",",
"Comparator",
":",
"comparator",
",",
"}",
"\n",
"}"
] | // DefaultConfig returns a configuration with the persister set. All other
// fields are set to smart defaults for persistence. | [
"DefaultConfig",
"returns",
"a",
"configuration",
"with",
"the",
"persister",
"set",
".",
"All",
"other",
"fields",
"are",
"set",
"to",
"smart",
"defaults",
"for",
"persistence",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/config.go#L37-L43 | train |
Workiva/go-datastructures | trie/xfast/iterator.go | exhaust | func (iter *Iterator) exhaust() Entries {
entries := make(Entries, 0, 100)
for it := iter; it.Next(); {
entries = append(entries, it.Value())
}
return entries
} | go | func (iter *Iterator) exhaust() Entries {
entries := make(Entries, 0, 100)
for it := iter; it.Next(); {
entries = append(entries, it.Value())
}
return entries
} | [
"func",
"(",
"iter",
"*",
"Iterator",
")",
"exhaust",
"(",
")",
"Entries",
"{",
"entries",
":=",
"make",
"(",
"Entries",
",",
"0",
",",
"100",
")",
"\n",
"for",
"it",
":=",
"iter",
";",
"it",
".",
"Next",
"(",
")",
";",
"{",
"entries",
"=",
"ap... | // exhaust is a helper function that will exhaust this iterator
// and return a list of entries. This is for internal use only. | [
"exhaust",
"is",
"a",
"helper",
"function",
"that",
"will",
"exhaust",
"this",
"iterator",
"and",
"return",
"a",
"list",
"of",
"entries",
".",
"This",
"is",
"for",
"internal",
"use",
"only",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/iterator.go#L53-L60 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | roundUp | func roundUp(v uint64) uint64 {
v--
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
v |= v >> 32
v++
return v
} | go | func roundUp(v uint64) uint64 {
v--
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
v |= v >> 32
v++
return v
} | [
"func",
"roundUp",
"(",
"v",
"uint64",
")",
"uint64",
"{",
"v",
"--",
"\n",
"v",
"|=",
"v",
">>",
"1",
"\n",
"v",
"|=",
"v",
">>",
"2",
"\n",
"v",
"|=",
"v",
">>",
"4",
"\n",
"v",
"|=",
"v",
">>",
"8",
"\n",
"v",
"|=",
"v",
">>",
"16",
... | // roundUp takes a uint64 greater than 0 and rounds it up to the next
// power of 2. | [
"roundUp",
"takes",
"a",
"uint64",
"greater",
"than",
"0",
"and",
"rounds",
"it",
"up",
"to",
"the",
"next",
"power",
"of",
"2",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L27-L37 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | rebuild | func (fi *FastIntegerHashMap) rebuild() {
packets := make(packets, roundUp(uint64(len(fi.packets))+1))
for _, packet := range fi.packets {
if packet == nil {
continue
}
packets.set(packet)
}
fi.packets = packets
} | go | func (fi *FastIntegerHashMap) rebuild() {
packets := make(packets, roundUp(uint64(len(fi.packets))+1))
for _, packet := range fi.packets {
if packet == nil {
continue
}
packets.set(packet)
}
fi.packets = packets
} | [
"func",
"(",
"fi",
"*",
"FastIntegerHashMap",
")",
"rebuild",
"(",
")",
"{",
"packets",
":=",
"make",
"(",
"packets",
",",
"roundUp",
"(",
"uint64",
"(",
"len",
"(",
"fi",
".",
"packets",
")",
")",
"+",
"1",
")",
")",
"\n",
"for",
"_",
",",
"pack... | // rebuild is an expensive operation which requires us to iterate
// over the current bucket and rehash the keys for insertion into
// the new bucket. The new bucket is twice as large as the old
// bucket by default. | [
"rebuild",
"is",
"an",
"expensive",
"operation",
"which",
"requires",
"us",
"to",
"iterate",
"over",
"the",
"current",
"bucket",
"and",
"rehash",
"the",
"keys",
"for",
"insertion",
"into",
"the",
"new",
"bucket",
".",
"The",
"new",
"bucket",
"is",
"twice",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L109-L119 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | Get | func (fi *FastIntegerHashMap) Get(key uint64) (uint64, bool) {
return fi.packets.get(key)
} | go | func (fi *FastIntegerHashMap) Get(key uint64) (uint64, bool) {
return fi.packets.get(key)
} | [
"func",
"(",
"fi",
"*",
"FastIntegerHashMap",
")",
"Get",
"(",
"key",
"uint64",
")",
"(",
"uint64",
",",
"bool",
")",
"{",
"return",
"fi",
".",
"packets",
".",
"get",
"(",
"key",
")",
"\n",
"}"
] | // Get returns an item from the map if it exists. Otherwise,
// returns false for the second argument. | [
"Get",
"returns",
"an",
"item",
"from",
"the",
"map",
"if",
"it",
"exists",
".",
"Otherwise",
"returns",
"false",
"for",
"the",
"second",
"argument",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L123-L125 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | Set | func (fi *FastIntegerHashMap) Set(key, value uint64) {
if float64(fi.count+1)/float64(len(fi.packets)) > ratio {
fi.rebuild()
}
fi.packets.set(&packet{key: key, value: value})
fi.count++
} | go | func (fi *FastIntegerHashMap) Set(key, value uint64) {
if float64(fi.count+1)/float64(len(fi.packets)) > ratio {
fi.rebuild()
}
fi.packets.set(&packet{key: key, value: value})
fi.count++
} | [
"func",
"(",
"fi",
"*",
"FastIntegerHashMap",
")",
"Set",
"(",
"key",
",",
"value",
"uint64",
")",
"{",
"if",
"float64",
"(",
"fi",
".",
"count",
"+",
"1",
")",
"/",
"float64",
"(",
"len",
"(",
"fi",
".",
"packets",
")",
")",
">",
"ratio",
"{",
... | // Set will set the provided key with the provided value. | [
"Set",
"will",
"set",
"the",
"provided",
"key",
"with",
"the",
"provided",
"value",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L128-L135 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | Exists | func (fi *FastIntegerHashMap) Exists(key uint64) bool {
return fi.packets.exists(key)
} | go | func (fi *FastIntegerHashMap) Exists(key uint64) bool {
return fi.packets.exists(key)
} | [
"func",
"(",
"fi",
"*",
"FastIntegerHashMap",
")",
"Exists",
"(",
"key",
"uint64",
")",
"bool",
"{",
"return",
"fi",
".",
"packets",
".",
"exists",
"(",
"key",
")",
"\n",
"}"
] | // Exists will return a bool indicating if the provided key
// exists in the map. | [
"Exists",
"will",
"return",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"key",
"exists",
"in",
"the",
"map",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L139-L141 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | Delete | func (fi *FastIntegerHashMap) Delete(key uint64) {
if fi.packets.delete(key) {
fi.count--
}
} | go | func (fi *FastIntegerHashMap) Delete(key uint64) {
if fi.packets.delete(key) {
fi.count--
}
} | [
"func",
"(",
"fi",
"*",
"FastIntegerHashMap",
")",
"Delete",
"(",
"key",
"uint64",
")",
"{",
"if",
"fi",
".",
"packets",
".",
"delete",
"(",
"key",
")",
"{",
"fi",
".",
"count",
"--",
"\n",
"}",
"\n",
"}"
] | // Delete will remove the provided key from the hashmap. If
// the key cannot be found, this is a no-op. | [
"Delete",
"will",
"remove",
"the",
"provided",
"key",
"from",
"the",
"hashmap",
".",
"If",
"the",
"key",
"cannot",
"be",
"found",
"this",
"is",
"a",
"no",
"-",
"op",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L145-L149 | train |
Workiva/go-datastructures | hashmap/fastinteger/hashmap.go | New | func New(hint uint64) *FastIntegerHashMap {
if hint == 0 {
hint = 16
}
hint = roundUp(hint)
return &FastIntegerHashMap{
count: 0,
packets: make(packets, hint),
}
} | go | func New(hint uint64) *FastIntegerHashMap {
if hint == 0 {
hint = 16
}
hint = roundUp(hint)
return &FastIntegerHashMap{
count: 0,
packets: make(packets, hint),
}
} | [
"func",
"New",
"(",
"hint",
"uint64",
")",
"*",
"FastIntegerHashMap",
"{",
"if",
"hint",
"==",
"0",
"{",
"hint",
"=",
"16",
"\n",
"}",
"\n\n",
"hint",
"=",
"roundUp",
"(",
"hint",
")",
"\n",
"return",
"&",
"FastIntegerHashMap",
"{",
"count",
":",
"0"... | // New returns a new FastIntegerHashMap with a bucket size specified
// by hint. | [
"New",
"returns",
"a",
"new",
"FastIntegerHashMap",
"with",
"a",
"bucket",
"size",
"specified",
"by",
"hint",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/hashmap/fastinteger/hashmap.go#L163-L173 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | Compare | func (se skipEntry) Compare(other common.Comparator) int {
otherSe := other.(skipEntry)
if se == otherSe {
return 0
}
if se > otherSe {
return 1
}
return -1
} | go | func (se skipEntry) Compare(other common.Comparator) int {
otherSe := other.(skipEntry)
if se == otherSe {
return 0
}
if se > otherSe {
return 1
}
return -1
} | [
"func",
"(",
"se",
"skipEntry",
")",
"Compare",
"(",
"other",
"common",
".",
"Comparator",
")",
"int",
"{",
"otherSe",
":=",
"other",
".",
"(",
"skipEntry",
")",
"\n",
"if",
"se",
"==",
"otherSe",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"if",
"se",
... | // Compare is required by the Comparator interface. | [
"Compare",
"is",
"required",
"by",
"the",
"Comparator",
"interface",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L51-L62 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | isLastDimension | func isLastDimension(dimension, lastDimension uint64) bool {
if dimension >= lastDimension { // useful in testing and denotes a serious problem
panic(`Dimension is greater than possible dimensions.`)
}
return dimension == lastDimension-1
} | go | func isLastDimension(dimension, lastDimension uint64) bool {
if dimension >= lastDimension { // useful in testing and denotes a serious problem
panic(`Dimension is greater than possible dimensions.`)
}
return dimension == lastDimension-1
} | [
"func",
"isLastDimension",
"(",
"dimension",
",",
"lastDimension",
"uint64",
")",
"bool",
"{",
"if",
"dimension",
">=",
"lastDimension",
"{",
"// useful in testing and denotes a serious problem",
"panic",
"(",
"`Dimension is greater than possible dimensions.`",
")",
"\n",
"... | // isLastDimension simply returns dimension == lastDimension-1.
// This panics if dimension >= lastDimension. | [
"isLastDimension",
"simply",
"returns",
"dimension",
"==",
"lastDimension",
"-",
"1",
".",
"This",
"panics",
"if",
"dimension",
">",
"=",
"lastDimension",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L70-L76 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | needsDeletion | func needsDeletion(value, index, number int64) bool {
if number > 0 {
return false
}
number = -number // get the magnitude
offset := value - index
return offset >= 0 && offset < number
} | go | func needsDeletion(value, index, number int64) bool {
if number > 0 {
return false
}
number = -number // get the magnitude
offset := value - index
return offset >= 0 && offset < number
} | [
"func",
"needsDeletion",
"(",
"value",
",",
"index",
",",
"number",
"int64",
")",
"bool",
"{",
"if",
"number",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"number",
"=",
"-",
"number",
"// get the magnitude",
"\n",
"offset",
":=",
"value",
"-",
... | // needsDeletion returns a bool indicating if the provided value
// needs to be deleted based on the provided index and number. | [
"needsDeletion",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"value",
"needs",
"to",
"be",
"deleted",
"based",
"on",
"the",
"provided",
"index",
"and",
"number",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L80-L89 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | Get | func (rt *skipListRT) Get(entries ...rangetree.Entry) rangetree.Entries {
results := make(rangetree.Entries, 0, len(entries))
for _, e := range entries {
results = append(results, rt.get(e))
}
return results
} | go | func (rt *skipListRT) Get(entries ...rangetree.Entry) rangetree.Entries {
results := make(rangetree.Entries, 0, len(entries))
for _, e := range entries {
results = append(results, rt.get(e))
}
return results
} | [
"func",
"(",
"rt",
"*",
"skipListRT",
")",
"Get",
"(",
"entries",
"...",
"rangetree",
".",
"Entry",
")",
"rangetree",
".",
"Entries",
"{",
"results",
":=",
"make",
"(",
"rangetree",
".",
"Entries",
",",
"0",
",",
"len",
"(",
"entries",
")",
")",
"\n"... | // Get will return any rangetree.Entries matching the provided entries.
// Similar in functionality to a key lookup, this returns nil for any
// entry that could not be found. | [
"Get",
"will",
"return",
"any",
"rangetree",
".",
"Entries",
"matching",
"the",
"provided",
"entries",
".",
"Similar",
"in",
"functionality",
"to",
"a",
"key",
"lookup",
"this",
"returns",
"nil",
"for",
"any",
"entry",
"that",
"could",
"not",
"be",
"found",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L235-L242 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | deleteRecursive | func (rt *skipListRT) deleteRecursive(sl *skip.SkipList, dimension uint64,
entry rangetree.Entry) rangetree.Entry {
value := entry.ValueAtDimension(dimension)
if isLastDimension(dimension, rt.dimensions) {
entries := sl.Delete(skipEntry(value))
if entries[0] == nil {
return nil
}
rt.number--
return en... | go | func (rt *skipListRT) deleteRecursive(sl *skip.SkipList, dimension uint64,
entry rangetree.Entry) rangetree.Entry {
value := entry.ValueAtDimension(dimension)
if isLastDimension(dimension, rt.dimensions) {
entries := sl.Delete(skipEntry(value))
if entries[0] == nil {
return nil
}
rt.number--
return en... | [
"func",
"(",
"rt",
"*",
"skipListRT",
")",
"deleteRecursive",
"(",
"sl",
"*",
"skip",
".",
"SkipList",
",",
"dimension",
"uint64",
",",
"entry",
"rangetree",
".",
"Entry",
")",
"rangetree",
".",
"Entry",
"{",
"value",
":=",
"entry",
".",
"ValueAtDimension"... | // deleteRecursive is used by the delete logic. The recursion depth
// only goes as far as the number of dimensions, so this shouldn't be an
// issue. | [
"deleteRecursive",
"is",
"used",
"by",
"the",
"delete",
"logic",
".",
"The",
"recursion",
"depth",
"only",
"goes",
"as",
"far",
"as",
"the",
"number",
"of",
"dimensions",
"so",
"this",
"shouldn",
"t",
"be",
"an",
"issue",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L252-L281 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | Apply | func (rt *skipListRT) Apply(interval rangetree.Interval, fn func(rangetree.Entry) bool) {
rt.apply(rt.top, 0, interval, fn)
} | go | func (rt *skipListRT) Apply(interval rangetree.Interval, fn func(rangetree.Entry) bool) {
rt.apply(rt.top, 0, interval, fn)
} | [
"func",
"(",
"rt",
"*",
"skipListRT",
")",
"Apply",
"(",
"interval",
"rangetree",
".",
"Interval",
",",
"fn",
"func",
"(",
"rangetree",
".",
"Entry",
")",
"bool",
")",
"{",
"rt",
".",
"apply",
"(",
"rt",
".",
"top",
",",
"0",
",",
"interval",
",",
... | // Apply will call the provided function with each entry that exists
// within the provided range, in order. Return false at any time to
// cancel iteration. Altering the entry in such a way that its location
// changes will result in undefined behavior. | [
"Apply",
"will",
"call",
"the",
"provided",
"function",
"with",
"each",
"entry",
"that",
"exists",
"within",
"the",
"provided",
"range",
"in",
"order",
".",
"Return",
"false",
"at",
"any",
"time",
"to",
"cancel",
"iteration",
".",
"Altering",
"the",
"entry",... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L332-L334 | train |
Workiva/go-datastructures | rangetree/skiplist/skiplist.go | Query | func (rt *skipListRT) Query(interval rangetree.Interval) rangetree.Entries {
entries := make(rangetree.Entries, 0, 100)
rt.apply(rt.top, 0, interval, func(e rangetree.Entry) bool {
entries = append(entries, e)
return true
})
return entries
} | go | func (rt *skipListRT) Query(interval rangetree.Interval) rangetree.Entries {
entries := make(rangetree.Entries, 0, 100)
rt.apply(rt.top, 0, interval, func(e rangetree.Entry) bool {
entries = append(entries, e)
return true
})
return entries
} | [
"func",
"(",
"rt",
"*",
"skipListRT",
")",
"Query",
"(",
"interval",
"rangetree",
".",
"Interval",
")",
"rangetree",
".",
"Entries",
"{",
"entries",
":=",
"make",
"(",
"rangetree",
".",
"Entries",
",",
"0",
",",
"100",
")",
"\n",
"rt",
".",
"apply",
... | // Query will return a list of entries that fall within
// the provided interval. | [
"Query",
"will",
"return",
"a",
"list",
"of",
"entries",
"that",
"fall",
"within",
"the",
"provided",
"interval",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/skiplist/skiplist.go#L338-L346 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Swap | func (u uintSlice) Swap(i, j int64) {
u[i], u[j] = u[j], u[i]
} | go | func (u uintSlice) Swap(i, j int64) {
u[i], u[j] = u[j], u[i]
} | [
"func",
"(",
"u",
"uintSlice",
")",
"Swap",
"(",
"i",
",",
"j",
"int64",
")",
"{",
"u",
"[",
"i",
"]",
",",
"u",
"[",
"j",
"]",
"=",
"u",
"[",
"j",
"]",
",",
"u",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps values in this slice at the positions given. | [
"Swap",
"swaps",
"values",
"in",
"this",
"slice",
"at",
"the",
"positions",
"given",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L32-L34 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Less | func (u uintSlice) Less(i, j int64) bool {
return u[i] < u[j]
} | go | func (u uintSlice) Less(i, j int64) bool {
return u[i] < u[j]
} | [
"func",
"(",
"u",
"uintSlice",
")",
"Less",
"(",
"i",
",",
"j",
"int64",
")",
"bool",
"{",
"return",
"u",
"[",
"i",
"]",
"<",
"u",
"[",
"j",
"]",
"\n",
"}"
] | // Less returns a bool indicating if the value at position i is
// less than position j. | [
"Less",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"value",
"at",
"position",
"i",
"is",
"less",
"than",
"position",
"j",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L38-L40 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | SetBit | func (sba *sparseBitArray) SetBit(k uint64) error {
index, position := getIndexAndRemainder(k)
i, inserted := sba.indices.insert(index)
if inserted {
sba.blocks.insert(i)
}
sba.blocks[i] = sba.blocks[i].insert(position)
return nil
} | go | func (sba *sparseBitArray) SetBit(k uint64) error {
index, position := getIndexAndRemainder(k)
i, inserted := sba.indices.insert(index)
if inserted {
sba.blocks.insert(i)
}
sba.blocks[i] = sba.blocks[i].insert(position)
return nil
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"SetBit",
"(",
"k",
"uint64",
")",
"error",
"{",
"index",
",",
"position",
":=",
"getIndexAndRemainder",
"(",
"k",
")",
"\n",
"i",
",",
"inserted",
":=",
"sba",
".",
"indices",
".",
"insert",
"(",
"index"... | // SetBit sets the bit at the given position. | [
"SetBit",
"sets",
"the",
"bit",
"at",
"the",
"given",
"position",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L108-L117 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | GetBit | func (sba *sparseBitArray) GetBit(k uint64) (bool, error) {
index, position := getIndexAndRemainder(k)
i := sba.indices.get(index)
if i == -1 {
return false, nil
}
return sba.blocks[i].get(position), nil
} | go | func (sba *sparseBitArray) GetBit(k uint64) (bool, error) {
index, position := getIndexAndRemainder(k)
i := sba.indices.get(index)
if i == -1 {
return false, nil
}
return sba.blocks[i].get(position), nil
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"GetBit",
"(",
"k",
"uint64",
")",
"(",
"bool",
",",
"error",
")",
"{",
"index",
",",
"position",
":=",
"getIndexAndRemainder",
"(",
"k",
")",
"\n",
"i",
":=",
"sba",
".",
"indices",
".",
"get",
"(",
... | // GetBit gets the bit at the given position. | [
"GetBit",
"gets",
"the",
"bit",
"at",
"the",
"given",
"position",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L120-L128 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | ToNums | func (sba *sparseBitArray) ToNums() []uint64 {
if len(sba.indices) == 0 {
return nil
}
diff := uint64(len(sba.indices)) * s
nums := make([]uint64, 0, diff/4)
for i, offset := range sba.indices {
sba.blocks[i].toNums(offset*s, &nums)
}
return nums
} | go | func (sba *sparseBitArray) ToNums() []uint64 {
if len(sba.indices) == 0 {
return nil
}
diff := uint64(len(sba.indices)) * s
nums := make([]uint64, 0, diff/4)
for i, offset := range sba.indices {
sba.blocks[i].toNums(offset*s, &nums)
}
return nums
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"ToNums",
"(",
")",
"[",
"]",
"uint64",
"{",
"if",
"len",
"(",
"sba",
".",
"indices",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"diff",
":=",
"uint64",
"(",
"len",
"(",
"sba",
".",
... | // ToNums converts this sparse bitarray to a list of numbers contained
// within it. | [
"ToNums",
"converts",
"this",
"sparse",
"bitarray",
"to",
"a",
"list",
"of",
"numbers",
"contained",
"within",
"it",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L132-L145 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | ClearBit | func (sba *sparseBitArray) ClearBit(k uint64) error {
index, position := getIndexAndRemainder(k)
i := sba.indices.get(index)
if i == -1 {
return nil
}
sba.blocks[i] = sba.blocks[i].remove(position)
if sba.blocks[i] == 0 {
sba.blocks.deleteAtIndex(i)
sba.indices.deleteAtIndex(i)
}
return nil
} | go | func (sba *sparseBitArray) ClearBit(k uint64) error {
index, position := getIndexAndRemainder(k)
i := sba.indices.get(index)
if i == -1 {
return nil
}
sba.blocks[i] = sba.blocks[i].remove(position)
if sba.blocks[i] == 0 {
sba.blocks.deleteAtIndex(i)
sba.indices.deleteAtIndex(i)
}
return nil
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"ClearBit",
"(",
"k",
"uint64",
")",
"error",
"{",
"index",
",",
"position",
":=",
"getIndexAndRemainder",
"(",
"k",
")",
"\n",
"i",
":=",
"sba",
".",
"indices",
".",
"get",
"(",
"index",
")",
"\n",
"if... | // ClearBit clears the bit at the given position. | [
"ClearBit",
"clears",
"the",
"bit",
"at",
"the",
"given",
"position",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L148-L162 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Reset | func (sba *sparseBitArray) Reset() {
sba.blocks = sba.blocks[:0]
sba.indices = sba.indices[:0]
} | go | func (sba *sparseBitArray) Reset() {
sba.blocks = sba.blocks[:0]
sba.indices = sba.indices[:0]
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"Reset",
"(",
")",
"{",
"sba",
".",
"blocks",
"=",
"sba",
".",
"blocks",
"[",
":",
"0",
"]",
"\n",
"sba",
".",
"indices",
"=",
"sba",
".",
"indices",
"[",
":",
"0",
"]",
"\n",
"}"
] | // Reset erases all values from this bitarray. | [
"Reset",
"erases",
"all",
"values",
"from",
"this",
"bitarray",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L165-L168 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Equals | func (sba *sparseBitArray) Equals(other BitArray) bool {
if other.Capacity() == 0 && sba.Capacity() > 0 {
return false
}
var selfIndex uint64
for iter := other.Blocks(); iter.Next(); {
otherIndex, otherBlock := iter.Value()
if len(sba.indices) == 0 {
if otherBlock > 0 {
return false
}
continue
... | go | func (sba *sparseBitArray) Equals(other BitArray) bool {
if other.Capacity() == 0 && sba.Capacity() > 0 {
return false
}
var selfIndex uint64
for iter := other.Blocks(); iter.Next(); {
otherIndex, otherBlock := iter.Value()
if len(sba.indices) == 0 {
if otherBlock > 0 {
return false
}
continue
... | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"Equals",
"(",
"other",
"BitArray",
")",
"bool",
"{",
"if",
"other",
".",
"Capacity",
"(",
")",
"==",
"0",
"&&",
"sba",
".",
"Capacity",
"(",
")",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
... | // Equals returns a bool indicating if the provided bit array
// equals this bitarray. | [
"Equals",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"bit",
"array",
"equals",
"this",
"bitarray",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L187-L226 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Or | func (sba *sparseBitArray) Or(other BitArray) BitArray {
if ba, ok := other.(*sparseBitArray); ok {
return orSparseWithSparseBitArray(sba, ba)
}
return orSparseWithDenseBitArray(sba, other.(*bitArray))
} | go | func (sba *sparseBitArray) Or(other BitArray) BitArray {
if ba, ok := other.(*sparseBitArray); ok {
return orSparseWithSparseBitArray(sba, ba)
}
return orSparseWithDenseBitArray(sba, other.(*bitArray))
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"Or",
"(",
"other",
"BitArray",
")",
"BitArray",
"{",
"if",
"ba",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"sparseBitArray",
")",
";",
"ok",
"{",
"return",
"orSparseWithSparseBitArray",
"(",
"sba",
",",
"... | // Or will perform a bitwise or operation with the provided bitarray and
// return a new result bitarray. | [
"Or",
"will",
"perform",
"a",
"bitwise",
"or",
"operation",
"with",
"the",
"provided",
"bitarray",
"and",
"return",
"a",
"new",
"result",
"bitarray",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L230-L236 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | And | func (sba *sparseBitArray) And(other BitArray) BitArray {
if ba, ok := other.(*sparseBitArray); ok {
return andSparseWithSparseBitArray(sba, ba)
}
return andSparseWithDenseBitArray(sba, other.(*bitArray))
} | go | func (sba *sparseBitArray) And(other BitArray) BitArray {
if ba, ok := other.(*sparseBitArray); ok {
return andSparseWithSparseBitArray(sba, ba)
}
return andSparseWithDenseBitArray(sba, other.(*bitArray))
} | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"And",
"(",
"other",
"BitArray",
")",
"BitArray",
"{",
"if",
"ba",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"sparseBitArray",
")",
";",
"ok",
"{",
"return",
"andSparseWithSparseBitArray",
"(",
"sba",
",",
... | // And will perform a bitwise and operation with the provided bitarray and
// return a new result bitarray. | [
"And",
"will",
"perform",
"a",
"bitwise",
"and",
"operation",
"with",
"the",
"provided",
"bitarray",
"and",
"return",
"a",
"new",
"result",
"bitarray",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L240-L246 | train |
Workiva/go-datastructures | bitarray/sparse_bitarray.go | Intersects | func (sba *sparseBitArray) Intersects(other BitArray) bool {
if other.Capacity() == 0 {
return true
}
var selfIndex int64
for iter := other.Blocks(); iter.Next(); {
otherI, otherBlock := iter.Value()
if len(sba.indices) == 0 {
if otherBlock > 0 {
return false
}
continue
}
// here we grab whe... | go | func (sba *sparseBitArray) Intersects(other BitArray) bool {
if other.Capacity() == 0 {
return true
}
var selfIndex int64
for iter := other.Blocks(); iter.Next(); {
otherI, otherBlock := iter.Value()
if len(sba.indices) == 0 {
if otherBlock > 0 {
return false
}
continue
}
// here we grab whe... | [
"func",
"(",
"sba",
"*",
"sparseBitArray",
")",
"Intersects",
"(",
"other",
"BitArray",
")",
"bool",
"{",
"if",
"other",
".",
"Capacity",
"(",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"var",
"selfIndex",
"int64",
"\n",
"for",
"iter",
... | // Intersects returns a bool indicating if the provided bit array
// intersects with this bitarray. | [
"Intersects",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"bit",
"array",
"intersects",
"with",
"this",
"bitarray",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/sparse_bitarray.go#L277-L310 | train |
Workiva/go-datastructures | augmentedtree/atree.go | compare | func compare(nodeLow, ivLow int64, nodeID, ivID uint64) int {
if ivLow > nodeLow {
return 1
}
if ivLow < nodeLow {
return 0
}
return intFromBool(ivID > nodeID)
} | go | func compare(nodeLow, ivLow int64, nodeID, ivID uint64) int {
if ivLow > nodeLow {
return 1
}
if ivLow < nodeLow {
return 0
}
return intFromBool(ivID > nodeID)
} | [
"func",
"compare",
"(",
"nodeLow",
",",
"ivLow",
"int64",
",",
"nodeID",
",",
"ivID",
"uint64",
")",
"int",
"{",
"if",
"ivLow",
">",
"nodeLow",
"{",
"return",
"1",
"\n",
"}",
"\n\n",
"if",
"ivLow",
"<",
"nodeLow",
"{",
"return",
"0",
"\n",
"}",
"\n... | // compare returns an int indicating which direction the node
// should go. | [
"compare",
"returns",
"an",
"int",
"indicating",
"which",
"direction",
"the",
"node",
"should",
"go",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/atree.go#L43-L53 | train |
Workiva/go-datastructures | augmentedtree/atree.go | add | func (tree *tree) add(iv Interval) {
if tree.root == nil {
tree.root = newNode(
iv, iv.LowAtDimension(1),
iv.HighAtDimension(1),
1,
)
tree.root.red = false
tree.number++
return
}
tree.resetDummy()
var (
dummy = tree.dummy
parent, grandParent *node
node = tree.r... | go | func (tree *tree) add(iv Interval) {
if tree.root == nil {
tree.root = newNode(
iv, iv.LowAtDimension(1),
iv.HighAtDimension(1),
1,
)
tree.root.red = false
tree.number++
return
}
tree.resetDummy()
var (
dummy = tree.dummy
parent, grandParent *node
node = tree.r... | [
"func",
"(",
"tree",
"*",
"tree",
")",
"add",
"(",
"iv",
"Interval",
")",
"{",
"if",
"tree",
".",
"root",
"==",
"nil",
"{",
"tree",
".",
"root",
"=",
"newNode",
"(",
"iv",
",",
"iv",
".",
"LowAtDimension",
"(",
"1",
")",
",",
"iv",
".",
"HighAt... | // add will add the provided interval to the tree. | [
"add",
"will",
"add",
"the",
"provided",
"interval",
"to",
"the",
"tree",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/atree.go#L148-L219 | train |
Workiva/go-datastructures | augmentedtree/atree.go | Add | func (tree *tree) Add(intervals ...Interval) {
for _, iv := range intervals {
tree.add(iv)
}
} | go | func (tree *tree) Add(intervals ...Interval) {
for _, iv := range intervals {
tree.add(iv)
}
} | [
"func",
"(",
"tree",
"*",
"tree",
")",
"Add",
"(",
"intervals",
"...",
"Interval",
")",
"{",
"for",
"_",
",",
"iv",
":=",
"range",
"intervals",
"{",
"tree",
".",
"add",
"(",
"iv",
")",
"\n",
"}",
"\n",
"}"
] | // Add will add the provided intervals to this tree. | [
"Add",
"will",
"add",
"the",
"provided",
"intervals",
"to",
"this",
"tree",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/atree.go#L222-L226 | train |
Workiva/go-datastructures | augmentedtree/atree.go | Delete | func (tree *tree) Delete(intervals ...Interval) {
for _, iv := range intervals {
tree.delete(iv)
}
if tree.root != nil {
tree.root.adjustRanges()
}
} | go | func (tree *tree) Delete(intervals ...Interval) {
for _, iv := range intervals {
tree.delete(iv)
}
if tree.root != nil {
tree.root.adjustRanges()
}
} | [
"func",
"(",
"tree",
"*",
"tree",
")",
"Delete",
"(",
"intervals",
"...",
"Interval",
")",
"{",
"for",
"_",
",",
"iv",
":=",
"range",
"intervals",
"{",
"tree",
".",
"delete",
"(",
"iv",
")",
"\n",
"}",
"\n",
"if",
"tree",
".",
"root",
"!=",
"nil"... | // Delete will remove the provided intervals from this tree. | [
"Delete",
"will",
"remove",
"the",
"provided",
"intervals",
"from",
"this",
"tree",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/atree.go#L310-L317 | train |
Workiva/go-datastructures | augmentedtree/atree.go | Query | func (tree *tree) Query(interval Interval) Intervals {
if tree.root == nil {
return nil
}
var (
Intervals = intervalsPool.Get().(Intervals)
ivLow = interval.LowAtDimension(1)
ivHigh = interval.HighAtDimension(1)
)
tree.root.query(ivLow, ivHigh, interval, tree.maxDimension, func(node *node) {
Int... | go | func (tree *tree) Query(interval Interval) Intervals {
if tree.root == nil {
return nil
}
var (
Intervals = intervalsPool.Get().(Intervals)
ivLow = interval.LowAtDimension(1)
ivHigh = interval.HighAtDimension(1)
)
tree.root.query(ivLow, ivHigh, interval, tree.maxDimension, func(node *node) {
Int... | [
"func",
"(",
"tree",
"*",
"tree",
")",
"Query",
"(",
"interval",
"Interval",
")",
"Intervals",
"{",
"if",
"tree",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"(",
"Intervals",
"=",
"intervalsPool",
".",
"Get",
"(",
")",
... | // Query will return a list of intervals that intersect the provided
// interval. The provided interval's ID method is ignored so the
// provided ID is irrelevant. | [
"Query",
"will",
"return",
"a",
"list",
"of",
"intervals",
"that",
"intersect",
"the",
"provided",
"interval",
".",
"The",
"provided",
"interval",
"s",
"ID",
"method",
"is",
"ignored",
"so",
"the",
"provided",
"ID",
"is",
"irrelevant",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/atree.go#L322-L338 | train |
Workiva/go-datastructures | fibheap/fibheap.go | Enqueue | func (heap *FloatingFibonacciHeap) Enqueue(priority float64) *Entry {
singleton := newEntry(priority)
// Merge singleton list with heap
heap.min = mergeLists(heap.min, singleton)
heap.size++
return singleton
} | go | func (heap *FloatingFibonacciHeap) Enqueue(priority float64) *Entry {
singleton := newEntry(priority)
// Merge singleton list with heap
heap.min = mergeLists(heap.min, singleton)
heap.size++
return singleton
} | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"Enqueue",
"(",
"priority",
"float64",
")",
"*",
"Entry",
"{",
"singleton",
":=",
"newEntry",
"(",
"priority",
")",
"\n\n",
"// Merge singleton list with heap",
"heap",
".",
"min",
"=",
"mergeLists",
"(",
... | // Enqueue adds and element to the heap | [
"Enqueue",
"adds",
"and",
"element",
"to",
"the",
"heap"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L118-L125 | train |
Workiva/go-datastructures | fibheap/fibheap.go | Min | func (heap *FloatingFibonacciHeap) Min() (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Trying to get minimum element of empty heap")
}
return heap.min, nil
} | go | func (heap *FloatingFibonacciHeap) Min() (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Trying to get minimum element of empty heap")
}
return heap.min, nil
} | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"Min",
"(",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"if",
"heap",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"nil",
",",
"EmptyHeapError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return"... | // Min returns the minimum element in the heap | [
"Min",
"returns",
"the",
"minimum",
"element",
"in",
"the",
"heap"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L128-L133 | train |
Workiva/go-datastructures | fibheap/fibheap.go | DequeueMin | func (heap *FloatingFibonacciHeap) DequeueMin() (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Cannot dequeue minimum of empty heap")
}
heap.size--
// Copy pointer. Will need it later.
min := heap.min
if min.next == min { // This is the only root node
heap.min = nil
} else { // There ar... | go | func (heap *FloatingFibonacciHeap) DequeueMin() (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Cannot dequeue minimum of empty heap")
}
heap.size--
// Copy pointer. Will need it later.
min := heap.min
if min.next == min { // This is the only root node
heap.min = nil
} else { // There ar... | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"DequeueMin",
"(",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"if",
"heap",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"nil",
",",
"EmptyHeapError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
... | // DequeueMin removes and returns the
// minimal element in the heap | [
"DequeueMin",
"removes",
"and",
"returns",
"the",
"minimal",
"element",
"in",
"the",
"heap"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L147-L247 | train |
Workiva/go-datastructures | fibheap/fibheap.go | DecreaseKey | func (heap *FloatingFibonacciHeap) DecreaseKey(node *Entry, newPriority float64) (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Cannot decrease key in an empty heap")
}
if node == nil {
return nil, NilError("Cannot decrease key: given node is nil")
}
if newPriority >= node.Priority {
re... | go | func (heap *FloatingFibonacciHeap) DecreaseKey(node *Entry, newPriority float64) (*Entry, error) {
if heap.IsEmpty() {
return nil, EmptyHeapError("Cannot decrease key in an empty heap")
}
if node == nil {
return nil, NilError("Cannot decrease key: given node is nil")
}
if newPriority >= node.Priority {
re... | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"DecreaseKey",
"(",
"node",
"*",
"Entry",
",",
"newPriority",
"float64",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"if",
"heap",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"nil",
",",
"EmptyHe... | // DecreaseKey decreases the key of the given element, sets it to the new
// given priority and returns the node if successfully set | [
"DecreaseKey",
"decreases",
"the",
"key",
"of",
"the",
"given",
"element",
"sets",
"it",
"to",
"the",
"new",
"given",
"priority",
"and",
"returns",
"the",
"node",
"if",
"successfully",
"set"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L251-L268 | train |
Workiva/go-datastructures | fibheap/fibheap.go | Delete | func (heap *FloatingFibonacciHeap) Delete(node *Entry) error {
if heap.IsEmpty() {
return EmptyHeapError("Cannot delete element from an empty heap")
}
if node == nil {
return NilError("Cannot delete node: given node is nil")
}
decreaseKeyUnchecked(heap, node, -math.MaxFloat64)
heap.DequeueMin()
return nil... | go | func (heap *FloatingFibonacciHeap) Delete(node *Entry) error {
if heap.IsEmpty() {
return EmptyHeapError("Cannot delete element from an empty heap")
}
if node == nil {
return NilError("Cannot delete node: given node is nil")
}
decreaseKeyUnchecked(heap, node, -math.MaxFloat64)
heap.DequeueMin()
return nil... | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"Delete",
"(",
"node",
"*",
"Entry",
")",
"error",
"{",
"if",
"heap",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"EmptyHeapError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"node",
"==",
"nil... | // Delete deletes the given element in the heap | [
"Delete",
"deletes",
"the",
"given",
"element",
"in",
"the",
"heap"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L271-L284 | train |
Workiva/go-datastructures | fibheap/fibheap.go | Merge | func (heap *FloatingFibonacciHeap) Merge(other *FloatingFibonacciHeap) (FloatingFibonacciHeap, error) {
if heap == nil || other == nil {
return FloatingFibonacciHeap{}, NilError("One of the heaps to merge is nil. Cannot merge")
}
resultSize := heap.size + other.size
resultMin := mergeLists(heap.min, other.min)... | go | func (heap *FloatingFibonacciHeap) Merge(other *FloatingFibonacciHeap) (FloatingFibonacciHeap, error) {
if heap == nil || other == nil {
return FloatingFibonacciHeap{}, NilError("One of the heaps to merge is nil. Cannot merge")
}
resultSize := heap.size + other.size
resultMin := mergeLists(heap.min, other.min)... | [
"func",
"(",
"heap",
"*",
"FloatingFibonacciHeap",
")",
"Merge",
"(",
"other",
"*",
"FloatingFibonacciHeap",
")",
"(",
"FloatingFibonacciHeap",
",",
"error",
")",
"{",
"if",
"heap",
"==",
"nil",
"||",
"other",
"==",
"nil",
"{",
"return",
"FloatingFibonacciHeap... | // Merge returns a new Fibonacci heap that contains
// all of the elements of the two heaps. Each of the input heaps is
// destructively modified by having all its elements removed. You can
// continue to use those heaps, but be aware that they will be empty
// after this call completes. | [
"Merge",
"returns",
"a",
"new",
"Fibonacci",
"heap",
"that",
"contains",
"all",
"of",
"the",
"elements",
"of",
"the",
"two",
"heaps",
".",
"Each",
"of",
"the",
"input",
"heaps",
"is",
"destructively",
"modified",
"by",
"having",
"all",
"its",
"elements",
"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/fibheap/fibheap.go#L291-L307 | train |
Workiva/go-datastructures | batcher/batcher.go | Put | func (b *basicBatcher) Put(item interface{}) error {
b.lock.Lock()
if b.disposed {
b.lock.Unlock()
return ErrDisposed
}
b.items = append(b.items, item)
if b.calculateBytes != nil {
b.availableBytes += b.calculateBytes(item)
}
if b.ready() {
// To guarantee ordering this MUST be in the lock, otherwise mu... | go | func (b *basicBatcher) Put(item interface{}) error {
b.lock.Lock()
if b.disposed {
b.lock.Unlock()
return ErrDisposed
}
b.items = append(b.items, item)
if b.calculateBytes != nil {
b.availableBytes += b.calculateBytes(item)
}
if b.ready() {
// To guarantee ordering this MUST be in the lock, otherwise mu... | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"Put",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"if",
"b",
".",
"disposed",
"{",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",... | // Put adds items to the batcher. | [
"Put",
"adds",
"items",
"to",
"the",
"batcher",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L121-L142 | train |
Workiva/go-datastructures | batcher/batcher.go | Get | func (b *basicBatcher) Get() ([]interface{}, error) {
// Don't check disposed yet so any items remaining in the queue
// will be returned properly.
var timeout <-chan time.Time
if b.maxTime > 0 {
timeout = time.After(b.maxTime)
}
select {
case items, ok := <-b.batchChan:
// If there's something on the batc... | go | func (b *basicBatcher) Get() ([]interface{}, error) {
// Don't check disposed yet so any items remaining in the queue
// will be returned properly.
var timeout <-chan time.Time
if b.maxTime > 0 {
timeout = time.After(b.maxTime)
}
select {
case items, ok := <-b.batchChan:
// If there's something on the batc... | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"Get",
"(",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// Don't check disposed yet so any items remaining in the queue",
"// will be returned properly.",
"var",
"timeout",
"<-",
"chan",
"time",
"... | // Get retrieves a batch from the batcher. This call will block until
// one of the conditions for a "complete" batch is reached. | [
"Get",
"retrieves",
"a",
"batch",
"from",
"the",
"batcher",
".",
"This",
"call",
"will",
"block",
"until",
"one",
"of",
"the",
"conditions",
"for",
"a",
"complete",
"batch",
"is",
"reached",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L146-L210 | train |
Workiva/go-datastructures | batcher/batcher.go | Flush | func (b *basicBatcher) Flush() error {
// This is the same pattern as a Put
b.lock.Lock()
if b.disposed {
b.lock.Unlock()
return ErrDisposed
}
b.flush()
b.lock.Unlock()
return nil
} | go | func (b *basicBatcher) Flush() error {
// This is the same pattern as a Put
b.lock.Lock()
if b.disposed {
b.lock.Unlock()
return ErrDisposed
}
b.flush()
b.lock.Unlock()
return nil
} | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"Flush",
"(",
")",
"error",
"{",
"// This is the same pattern as a Put",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"if",
"b",
".",
"disposed",
"{",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"ret... | // Flush forcibly completes the batch currently being built | [
"Flush",
"forcibly",
"completes",
"the",
"batch",
"currently",
"being",
"built"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L213-L223 | train |
Workiva/go-datastructures | batcher/batcher.go | Dispose | func (b *basicBatcher) Dispose() {
for {
if b.lock.TryLock() {
// We've got a lock
if b.disposed {
b.lock.Unlock()
return
}
b.disposed = true
b.items = nil
b.drainBatchChan()
close(b.batchChan)
b.lock.Unlock()
} else {
// Two cases here:
// 1) Something is blocked and holding... | go | func (b *basicBatcher) Dispose() {
for {
if b.lock.TryLock() {
// We've got a lock
if b.disposed {
b.lock.Unlock()
return
}
b.disposed = true
b.items = nil
b.drainBatchChan()
close(b.batchChan)
b.lock.Unlock()
} else {
// Two cases here:
// 1) Something is blocked and holding... | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"Dispose",
"(",
")",
"{",
"for",
"{",
"if",
"b",
".",
"lock",
".",
"TryLock",
"(",
")",
"{",
"// We've got a lock",
"if",
"b",
".",
"disposed",
"{",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"ret... | // Dispose will dispose of the batcher. Any calls to Put or Flush
// will return ErrDisposed, calls to Get will return an error iff
// there are no more ready batches. Any items not flushed and retrieved
// by a Get may or may not be retrievable after calling this. | [
"Dispose",
"will",
"dispose",
"of",
"the",
"batcher",
".",
"Any",
"calls",
"to",
"Put",
"or",
"Flush",
"will",
"return",
"ErrDisposed",
"calls",
"to",
"Get",
"will",
"return",
"an",
"error",
"iff",
"there",
"are",
"no",
"more",
"ready",
"batches",
".",
"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L229-L254 | train |
Workiva/go-datastructures | batcher/batcher.go | IsDisposed | func (b *basicBatcher) IsDisposed() bool {
b.lock.Lock()
disposed := b.disposed
b.lock.Unlock()
return disposed
} | go | func (b *basicBatcher) IsDisposed() bool {
b.lock.Lock()
disposed := b.disposed
b.lock.Unlock()
return disposed
} | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"IsDisposed",
"(",
")",
"bool",
"{",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"disposed",
":=",
"b",
".",
"disposed",
"\n",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"disposed",
"... | // IsDisposed will determine if the batcher is disposed | [
"IsDisposed",
"will",
"determine",
"if",
"the",
"batcher",
"is",
"disposed"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L257-L262 | train |
Workiva/go-datastructures | batcher/batcher.go | flush | func (b *basicBatcher) flush() {
b.batchChan <- b.items
b.items = make([]interface{}, 0, b.maxItems)
b.availableBytes = 0
} | go | func (b *basicBatcher) flush() {
b.batchChan <- b.items
b.items = make([]interface{}, 0, b.maxItems)
b.availableBytes = 0
} | [
"func",
"(",
"b",
"*",
"basicBatcher",
")",
"flush",
"(",
")",
"{",
"b",
".",
"batchChan",
"<-",
"b",
".",
"items",
"\n",
"b",
".",
"items",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"b",
".",
"maxItems",
")",
"\n",
"b... | // flush adds the batch currently being built to the queue of completed batches.
// flush is not threadsafe, so should be synchronized externally. | [
"flush",
"adds",
"the",
"batch",
"currently",
"being",
"built",
"to",
"the",
"queue",
"of",
"completed",
"batches",
".",
"flush",
"is",
"not",
"threadsafe",
"so",
"should",
"be",
"synchronized",
"externally",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/batcher/batcher.go#L266-L270 | train |
Workiva/go-datastructures | bitarray/iterator.go | Value | func (iter *sparseBitArrayIterator) Value() (uint64, block) {
return iter.sba.indices[iter.index], iter.sba.blocks[iter.index]
} | go | func (iter *sparseBitArrayIterator) Value() (uint64, block) {
return iter.sba.indices[iter.index], iter.sba.blocks[iter.index]
} | [
"func",
"(",
"iter",
"*",
"sparseBitArrayIterator",
")",
"Value",
"(",
")",
"(",
"uint64",
",",
"block",
")",
"{",
"return",
"iter",
".",
"sba",
".",
"indices",
"[",
"iter",
".",
"index",
"]",
",",
"iter",
".",
"sba",
".",
"blocks",
"[",
"iter",
".... | // Value returns the index and block at the given index. | [
"Value",
"returns",
"the",
"index",
"and",
"block",
"at",
"the",
"given",
"index",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/iterator.go#L32-L34 | train |
Workiva/go-datastructures | bitarray/iterator.go | Value | func (iter *bitArrayIterator) Value() (uint64, block) {
return uint64(iter.index), iter.ba.blocks[iter.index]
} | go | func (iter *bitArrayIterator) Value() (uint64, block) {
return uint64(iter.index), iter.ba.blocks[iter.index]
} | [
"func",
"(",
"iter",
"*",
"bitArrayIterator",
")",
"Value",
"(",
")",
"(",
"uint64",
",",
"block",
")",
"{",
"return",
"uint64",
"(",
"iter",
".",
"index",
")",
",",
"iter",
".",
"ba",
".",
"blocks",
"[",
"iter",
".",
"index",
"]",
"\n",
"}"
] | // Value returns an index and the block at this index. | [
"Value",
"returns",
"an",
"index",
"and",
"the",
"block",
"at",
"this",
"index",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/iterator.go#L57-L59 | train |
Workiva/go-datastructures | rangetree/entries.go | Dispose | func (entries *Entries) Dispose() {
for i := 0; i < len(*entries); i++ {
(*entries)[i] = nil
}
*entries = (*entries)[:0]
entriesPool.Put(*entries)
} | go | func (entries *Entries) Dispose() {
for i := 0; i < len(*entries); i++ {
(*entries)[i] = nil
}
*entries = (*entries)[:0]
entriesPool.Put(*entries)
} | [
"func",
"(",
"entries",
"*",
"Entries",
")",
"Dispose",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"*",
"entries",
")",
";",
"i",
"++",
"{",
"(",
"*",
"entries",
")",
"[",
"i",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"*",
... | // Dispose will free the resources consumed by this list and
// allow the list to be reused. | [
"Dispose",
"will",
"free",
"the",
"resources",
"consumed",
"by",
"this",
"list",
"and",
"allow",
"the",
"list",
"to",
"be",
"reused",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/rangetree/entries.go#L33-L40 | train |
Workiva/go-datastructures | tree/avl/node.go | copy | func (n *node) copy() *node {
return &node{
balance: n.balance,
children: [2]*node{n.children[0], n.children[1]},
entry: n.entry,
}
} | go | func (n *node) copy() *node {
return &node{
balance: n.balance,
children: [2]*node{n.children[0], n.children[1]},
entry: n.entry,
}
} | [
"func",
"(",
"n",
"*",
"node",
")",
"copy",
"(",
")",
"*",
"node",
"{",
"return",
"&",
"node",
"{",
"balance",
":",
"n",
".",
"balance",
",",
"children",
":",
"[",
"2",
"]",
"*",
"node",
"{",
"n",
".",
"children",
"[",
"0",
"]",
",",
"n",
"... | // copy returns a copy of this node with pointers to the original
// children. | [
"copy",
"returns",
"a",
"copy",
"of",
"this",
"node",
"with",
"pointers",
"to",
"the",
"original",
"children",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/tree/avl/node.go#L35-L41 | train |
Workiva/go-datastructures | tree/avl/avl.go | copy | func (immutable *Immutable) copy() *Immutable {
var root *node
if immutable.root != nil {
root = immutable.root.copy()
}
cp := &Immutable{
root: root,
number: immutable.number,
dummy: *newNode(nil),
}
return cp
} | go | func (immutable *Immutable) copy() *Immutable {
var root *node
if immutable.root != nil {
root = immutable.root.copy()
}
cp := &Immutable{
root: root,
number: immutable.number,
dummy: *newNode(nil),
}
return cp
} | [
"func",
"(",
"immutable",
"*",
"Immutable",
")",
"copy",
"(",
")",
"*",
"Immutable",
"{",
"var",
"root",
"*",
"node",
"\n",
"if",
"immutable",
".",
"root",
"!=",
"nil",
"{",
"root",
"=",
"immutable",
".",
"root",
".",
"copy",
"(",
")",
"\n",
"}",
... | // copy returns a copy of this immutable tree with a copy
// of the root and a new dummy helper for the insertion operation. | [
"copy",
"returns",
"a",
"copy",
"of",
"this",
"immutable",
"tree",
"with",
"a",
"copy",
"of",
"the",
"root",
"and",
"a",
"new",
"dummy",
"helper",
"for",
"the",
"insertion",
"operation",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/tree/avl/avl.go#L47-L58 | train |
Workiva/go-datastructures | tree/avl/avl.go | Get | func (immutable *Immutable) Get(entries ...Entry) Entries {
result := make(Entries, 0, len(entries))
for _, e := range entries {
result = append(result, immutable.get(e))
}
return result
} | go | func (immutable *Immutable) Get(entries ...Entry) Entries {
result := make(Entries, 0, len(entries))
for _, e := range entries {
result = append(result, immutable.get(e))
}
return result
} | [
"func",
"(",
"immutable",
"*",
"Immutable",
")",
"Get",
"(",
"entries",
"...",
"Entry",
")",
"Entries",
"{",
"result",
":=",
"make",
"(",
"Entries",
",",
"0",
",",
"len",
"(",
"entries",
")",
")",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"entries... | // Get will get the provided Entries from the tree. If no matching
// Entry is found, a nil is returned in its place. | [
"Get",
"will",
"get",
"the",
"provided",
"Entries",
"from",
"the",
"tree",
".",
"If",
"no",
"matching",
"Entry",
"is",
"found",
"a",
"nil",
"is",
"returned",
"in",
"its",
"place",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/tree/avl/avl.go#L90-L97 | train |
Workiva/go-datastructures | tree/avl/avl.go | Insert | func (immutable *Immutable) Insert(entries ...Entry) (*Immutable, Entries) {
if len(entries) == 0 {
return immutable, Entries{}
}
overwritten := make(Entries, 0, len(entries))
cp := immutable.copy()
for _, e := range entries {
overwritten = append(overwritten, cp.insert(e))
}
return cp, overwritten
} | go | func (immutable *Immutable) Insert(entries ...Entry) (*Immutable, Entries) {
if len(entries) == 0 {
return immutable, Entries{}
}
overwritten := make(Entries, 0, len(entries))
cp := immutable.copy()
for _, e := range entries {
overwritten = append(overwritten, cp.insert(e))
}
return cp, overwritten
} | [
"func",
"(",
"immutable",
"*",
"Immutable",
")",
"Insert",
"(",
"entries",
"...",
"Entry",
")",
"(",
"*",
"Immutable",
",",
"Entries",
")",
"{",
"if",
"len",
"(",
"entries",
")",
"==",
"0",
"{",
"return",
"immutable",
",",
"Entries",
"{",
"}",
"\n",
... | // Insert will add the provided entries into the tree and return the new
// state. Also returned is a list of Entries that were overwritten. If
// nothing was overwritten for an Entry, a nil is returned in its place. | [
"Insert",
"will",
"add",
"the",
"provided",
"entries",
"into",
"the",
"tree",
"and",
"return",
"the",
"new",
"state",
".",
"Also",
"returned",
"is",
"a",
"list",
"of",
"Entries",
"that",
"were",
"overwritten",
".",
"If",
"nothing",
"was",
"overwritten",
"f... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/tree/avl/avl.go#L190-L202 | train |
Workiva/go-datastructures | tree/avl/avl.go | Delete | func (immutable *Immutable) Delete(entries ...Entry) (*Immutable, Entries) {
if len(entries) == 0 {
return immutable, Entries{}
}
deleted := make(Entries, 0, len(entries))
cp := immutable.copy()
for _, e := range entries {
deleted = append(deleted, cp.delete(e))
}
return cp, deleted
} | go | func (immutable *Immutable) Delete(entries ...Entry) (*Immutable, Entries) {
if len(entries) == 0 {
return immutable, Entries{}
}
deleted := make(Entries, 0, len(entries))
cp := immutable.copy()
for _, e := range entries {
deleted = append(deleted, cp.delete(e))
}
return cp, deleted
} | [
"func",
"(",
"immutable",
"*",
"Immutable",
")",
"Delete",
"(",
"entries",
"...",
"Entry",
")",
"(",
"*",
"Immutable",
",",
"Entries",
")",
"{",
"if",
"len",
"(",
"entries",
")",
"==",
"0",
"{",
"return",
"immutable",
",",
"Entries",
"{",
"}",
"\n",
... | // Delete will remove the provided entries from this AVL tree and
// return a new tree and any entries removed. If an entry could not
// be found, nil is returned in its place. | [
"Delete",
"will",
"remove",
"the",
"provided",
"entries",
"from",
"this",
"AVL",
"tree",
"and",
"return",
"a",
"new",
"tree",
"and",
"any",
"entries",
"removed",
".",
"If",
"an",
"entry",
"could",
"not",
"be",
"found",
"nil",
"is",
"returned",
"in",
"its... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/tree/avl/avl.go#L314-L326 | train |
Workiva/go-datastructures | queue/ring.go | Put | func (rb *RingBuffer) Put(item interface{}) error {
_, err := rb.put(item, false)
return err
} | go | func (rb *RingBuffer) Put(item interface{}) error {
_, err := rb.put(item, false)
return err
} | [
"func",
"(",
"rb",
"*",
"RingBuffer",
")",
"Put",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"_",
",",
"err",
":=",
"rb",
".",
"put",
"(",
"item",
",",
"false",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Put adds the provided item to the queue. If the queue is full, this
// call will block until an item is added to the queue or Dispose is called
// on the queue. An error will be returned if the queue is disposed. | [
"Put",
"adds",
"the",
"provided",
"item",
"to",
"the",
"queue",
".",
"If",
"the",
"queue",
"is",
"full",
"this",
"call",
"will",
"block",
"until",
"an",
"item",
"is",
"added",
"to",
"the",
"queue",
"or",
"Dispose",
"is",
"called",
"on",
"the",
"queue",... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/ring.go#L75-L78 | train |
Workiva/go-datastructures | queue/ring.go | Offer | func (rb *RingBuffer) Offer(item interface{}) (bool, error) {
return rb.put(item, true)
} | go | func (rb *RingBuffer) Offer(item interface{}) (bool, error) {
return rb.put(item, true)
} | [
"func",
"(",
"rb",
"*",
"RingBuffer",
")",
"Offer",
"(",
"item",
"interface",
"{",
"}",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"rb",
".",
"put",
"(",
"item",
",",
"true",
")",
"\n",
"}"
] | // Offer adds the provided item to the queue if there is space. If the queue
// is full, this call will return false. An error will be returned if the
// queue is disposed. | [
"Offer",
"adds",
"the",
"provided",
"item",
"to",
"the",
"queue",
"if",
"there",
"is",
"space",
".",
"If",
"the",
"queue",
"is",
"full",
"this",
"call",
"will",
"return",
"false",
".",
"An",
"error",
"will",
"be",
"returned",
"if",
"the",
"queue",
"is"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/ring.go#L83-L85 | train |
Workiva/go-datastructures | queue/ring.go | Poll | func (rb *RingBuffer) Poll(timeout time.Duration) (interface{}, error) {
var (
n *node
pos = atomic.LoadUint64(&rb.dequeue)
start time.Time
)
if timeout > 0 {
start = time.Now()
}
L:
for {
if atomic.LoadUint64(&rb.disposed) == 1 {
return nil, ErrDisposed
}
n = rb.nodes[pos&rb.mask]
seq :=... | go | func (rb *RingBuffer) Poll(timeout time.Duration) (interface{}, error) {
var (
n *node
pos = atomic.LoadUint64(&rb.dequeue)
start time.Time
)
if timeout > 0 {
start = time.Now()
}
L:
for {
if atomic.LoadUint64(&rb.disposed) == 1 {
return nil, ErrDisposed
}
n = rb.nodes[pos&rb.mask]
seq :=... | [
"func",
"(",
"rb",
"*",
"RingBuffer",
")",
"Poll",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"(",
"n",
"*",
"node",
"\n",
"pos",
"=",
"atomic",
".",
"LoadUint64",
"(",
"&",
"rb",
".",... | // Poll will return the next item in the queue. This call will block
// if the queue is empty. This call will unblock when an item is added
// to the queue, Dispose is called on the queue, or the timeout is reached. An
// error will be returned if the queue is disposed or a timeout occurs. A
// non-positive timeout w... | [
"Poll",
"will",
"return",
"the",
"next",
"item",
"in",
"the",
"queue",
".",
"This",
"call",
"will",
"block",
"if",
"the",
"queue",
"is",
"empty",
".",
"This",
"call",
"will",
"unblock",
"when",
"an",
"item",
"is",
"added",
"to",
"the",
"queue",
"Dispos... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/ring.go#L134-L172 | train |
Workiva/go-datastructures | queue/ring.go | Len | func (rb *RingBuffer) Len() uint64 {
return atomic.LoadUint64(&rb.queue) - atomic.LoadUint64(&rb.dequeue)
} | go | func (rb *RingBuffer) Len() uint64 {
return atomic.LoadUint64(&rb.queue) - atomic.LoadUint64(&rb.dequeue)
} | [
"func",
"(",
"rb",
"*",
"RingBuffer",
")",
"Len",
"(",
")",
"uint64",
"{",
"return",
"atomic",
".",
"LoadUint64",
"(",
"&",
"rb",
".",
"queue",
")",
"-",
"atomic",
".",
"LoadUint64",
"(",
"&",
"rb",
".",
"dequeue",
")",
"\n",
"}"
] | // Len returns the number of items in the queue. | [
"Len",
"returns",
"the",
"number",
"of",
"items",
"in",
"the",
"queue",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/ring.go#L175-L177 | train |
Workiva/go-datastructures | queue/ring.go | NewRingBuffer | func NewRingBuffer(size uint64) *RingBuffer {
rb := &RingBuffer{}
rb.init(size)
return rb
} | go | func NewRingBuffer(size uint64) *RingBuffer {
rb := &RingBuffer{}
rb.init(size)
return rb
} | [
"func",
"NewRingBuffer",
"(",
"size",
"uint64",
")",
"*",
"RingBuffer",
"{",
"rb",
":=",
"&",
"RingBuffer",
"{",
"}",
"\n",
"rb",
".",
"init",
"(",
"size",
")",
"\n",
"return",
"rb",
"\n",
"}"
] | // NewRingBuffer will allocate, initialize, and return a ring buffer
// with the specified size. | [
"NewRingBuffer",
"will",
"allocate",
"initialize",
"and",
"return",
"a",
"ring",
"buffer",
"with",
"the",
"specified",
"size",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/ring.go#L199-L203 | train |
Workiva/go-datastructures | numerics/optimization/nelder_mead.go | generateRandomVerticesFromGuess | func generateRandomVerticesFromGuess(guess *nmVertex, num int) vertices {
// summed allows us to prevent duplicate guesses, checking
// all previous guesses for every guess created would be too
// time consuming so we take an indexed shortcut here. summed
// is a map of a sum of the vars to the vertices that have ... | go | func generateRandomVerticesFromGuess(guess *nmVertex, num int) vertices {
// summed allows us to prevent duplicate guesses, checking
// all previous guesses for every guess created would be too
// time consuming so we take an indexed shortcut here. summed
// is a map of a sum of the vars to the vertices that have ... | [
"func",
"generateRandomVerticesFromGuess",
"(",
"guess",
"*",
"nmVertex",
",",
"num",
"int",
")",
"vertices",
"{",
"// summed allows us to prevent duplicate guesses, checking",
"// all previous guesses for every guess created would be too",
"// time consuming so we take an indexed shortc... | // generateRandomVerticesFromGuess will generate num number of vertices
// with random | [
"generateRandomVerticesFromGuess",
"will",
"generate",
"num",
"number",
"of",
"vertices",
"with",
"random"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L29-L82 | train |
Workiva/go-datastructures | numerics/optimization/nelder_mead.go | findMidpoint | func findMidpoint(vertices ...*nmVertex) *nmVertex {
num := len(vertices) // this is what we divide by
vars := make([]float64, 0, num)
for i := 0; i < num; i++ {
sum := float64(0)
for _, v := range vertices {
sum += v.vars[i]
}
vars = append(vars, sum/float64(num))
}
return &nmVertex{
vars: vars,
}... | go | func findMidpoint(vertices ...*nmVertex) *nmVertex {
num := len(vertices) // this is what we divide by
vars := make([]float64, 0, num)
for i := 0; i < num; i++ {
sum := float64(0)
for _, v := range vertices {
sum += v.vars[i]
}
vars = append(vars, sum/float64(num))
}
return &nmVertex{
vars: vars,
}... | [
"func",
"findMidpoint",
"(",
"vertices",
"...",
"*",
"nmVertex",
")",
"*",
"nmVertex",
"{",
"num",
":=",
"len",
"(",
"vertices",
")",
"// this is what we divide by",
"\n",
"vars",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"0",
",",
"num",
")",
"\n\n",... | // findMidpoint will find the midpoint of the provided vertices
// and return a new vertex. | [
"findMidpoint",
"will",
"find",
"the",
"midpoint",
"of",
"the",
"provided",
"vertices",
"and",
"return",
"a",
"new",
"vertex",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L101-L116 | train |
Workiva/go-datastructures | numerics/optimization/nelder_mead.go | evaluate | func (vertices vertices) evaluate(config NelderMeadConfiguration) {
for _, v := range vertices {
v.evaluate(config)
}
vertices.sort(config)
} | go | func (vertices vertices) evaluate(config NelderMeadConfiguration) {
for _, v := range vertices {
v.evaluate(config)
}
vertices.sort(config)
} | [
"func",
"(",
"vertices",
"vertices",
")",
"evaluate",
"(",
"config",
"NelderMeadConfiguration",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"vertices",
"{",
"v",
".",
"evaluate",
"(",
"config",
")",
"\n",
"}",
"\n\n",
"vertices",
".",
"sort",
"(",
"... | // evaluate will call evaluate on all the verticies in this list
// and order them by distance to target. | [
"evaluate",
"will",
"call",
"evaluate",
"on",
"all",
"the",
"verticies",
"in",
"this",
"list",
"and",
"order",
"them",
"by",
"distance",
"to",
"target",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L135-L141 | train |
Workiva/go-datastructures | numerics/optimization/nelder_mead.go | Less | func (sorter sorter) Less(i, j int) bool {
return sorter.vertices[i].less(sorter.config, sorter.vertices[j])
} | go | func (sorter sorter) Less(i, j int) bool {
return sorter.vertices[i].less(sorter.config, sorter.vertices[j])
} | [
"func",
"(",
"sorter",
"sorter",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"sorter",
".",
"vertices",
"[",
"i",
"]",
".",
"less",
"(",
"sorter",
".",
"config",
",",
"sorter",
".",
"vertices",
"[",
"j",
"]",
")",
"\n",
... | // the following methods are required for sort.Interface. We
// use the standard libraries sort here as it uses an adaptive
// sort and we really don't expect there to be a ton of dimensions
// here so mulithreaded sort in this repo really isn't
// necessary. | [
"the",
"following",
"methods",
"are",
"required",
"for",
"sort",
".",
"Interface",
".",
"We",
"use",
"the",
"standard",
"libraries",
"sort",
"here",
"as",
"it",
"uses",
"an",
"adaptive",
"sort",
"and",
"we",
"really",
"don",
"t",
"expect",
"there",
"to",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/numerics/optimization/nelder_mead.go#L166-L168 | train |
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",
"// first we want to sum all the distances between the points",
"for",
"i",
",",
"otherPoint",
":=",
"r... | // 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 ... | 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 ... | [
"func",
"(",
"nm",
"*",
"nelderMead",
")",
"checkIteration",
"(",
"vertices",
"vertices",
")",
"bool",
"{",
"// this will never be true for += inf",
"if",
"math",
".",
"Abs",
"(",
"vertices",
"[",
"0",
"]",
".",
"result",
"-",
"nm",
".",
"config",
".",
"Ta... | // 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 =... | 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 =... | [
"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... | 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... | [
"func",
"symRotate",
"(",
"u",
"Comparators",
",",
"start1",
",",
"start2",
",",
"end",
"int",
")",
"{",
"i",
":=",
"start2",
"-",
"start1",
"\n",
"if",
"i",
"==",
"0",
"{",
"return",
"\n",
"}",
"\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
sym... | 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
sym... | [
"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",
"++",
"// 0-index offset",
"\n",
"if",
"index",
">=",
"sl",
".",
"Len",
"(",
")",
"{",
"return",
"sl",
"... | // 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 i... | [
"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 |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.