repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Workiva/go-datastructures | bitarray/util.go | maxInt64 | func maxInt64(ints ...int64) int64 {
maxInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] > maxInt {
maxInt = ints[i]
}
}
return maxInt
} | go | func maxInt64(ints ...int64) int64 {
maxInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] > maxInt {
maxInt = ints[i]
}
}
return maxInt
} | [
"func",
"maxInt64",
"(",
"ints",
"...",
"int64",
")",
"int64",
"{",
"maxInt",
":=",
"ints",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"ints",
")",
";",
"i",
"++",
"{",
"if",
"ints",
"[",
"i",
"]",
">",
"maxInt",
... | // maxInt64 returns the highest integer in the provided list of int64s | [
"maxInt64",
"returns",
"the",
"highest",
"integer",
"in",
"the",
"provided",
"list",
"of",
"int64s"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L20-L29 | train |
Workiva/go-datastructures | bitarray/util.go | maxUint64 | func maxUint64(ints ...uint64) uint64 {
maxInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] > maxInt {
maxInt = ints[i]
}
}
return maxInt
} | go | func maxUint64(ints ...uint64) uint64 {
maxInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] > maxInt {
maxInt = ints[i]
}
}
return maxInt
} | [
"func",
"maxUint64",
"(",
"ints",
"...",
"uint64",
")",
"uint64",
"{",
"maxInt",
":=",
"ints",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"ints",
")",
";",
"i",
"++",
"{",
"if",
"ints",
"[",
"i",
"]",
">",
"maxInt"... | // maxUint64 returns the highest integer in the provided list of uint64s | [
"maxUint64",
"returns",
"the",
"highest",
"integer",
"in",
"the",
"provided",
"list",
"of",
"uint64s"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L32-L41 | train |
Workiva/go-datastructures | bitarray/util.go | minUint64 | func minUint64(ints ...uint64) uint64 {
minInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] < minInt {
minInt = ints[i]
}
}
return minInt
} | go | func minUint64(ints ...uint64) uint64 {
minInt := ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] < minInt {
minInt = ints[i]
}
}
return minInt
} | [
"func",
"minUint64",
"(",
"ints",
"...",
"uint64",
")",
"uint64",
"{",
"minInt",
":=",
"ints",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"ints",
")",
";",
"i",
"++",
"{",
"if",
"ints",
"[",
"i",
"]",
"<",
"minInt"... | // minUint64 returns the lowest integer in the provided list of int32s | [
"minUint64",
"returns",
"the",
"lowest",
"integer",
"in",
"the",
"provided",
"list",
"of",
"int32s"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/util.go#L44-L53 | train |
Workiva/go-datastructures | bitarray/bitarray.go | ToNums | func (ba *bitArray) ToNums() []uint64 {
nums := make([]uint64, 0, ba.highest-ba.lowest/4)
for i, block := range ba.blocks {
block.toNums(uint64(i)*s, &nums)
}
return nums
} | go | func (ba *bitArray) ToNums() []uint64 {
nums := make([]uint64, 0, ba.highest-ba.lowest/4)
for i, block := range ba.blocks {
block.toNums(uint64(i)*s, &nums)
}
return nums
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"ToNums",
"(",
")",
"[",
"]",
"uint64",
"{",
"nums",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"ba",
".",
"highest",
"-",
"ba",
".",
"lowest",
"/",
"4",
")",
"\n",
"for",
"i",
",",
"block",... | // ToNums converts this bitarray to a list of numbers contained within it. | [
"ToNums",
"converts",
"this",
"bitarray",
"to",
"a",
"list",
"of",
"numbers",
"contained",
"within",
"it",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L75-L82 | train |
Workiva/go-datastructures | bitarray/bitarray.go | SetBit | func (ba *bitArray) SetBit(k uint64) error {
if k >= ba.Capacity() {
return OutOfRangeError(k)
}
if !ba.anyset {
ba.lowest = k
ba.highest = k
ba.anyset = true
} else {
if k < ba.lowest {
ba.lowest = k
} else if k > ba.highest {
ba.highest = k
}
}
i, pos := getIndexAndRemainder(k)
ba.blocks[... | go | func (ba *bitArray) SetBit(k uint64) error {
if k >= ba.Capacity() {
return OutOfRangeError(k)
}
if !ba.anyset {
ba.lowest = k
ba.highest = k
ba.anyset = true
} else {
if k < ba.lowest {
ba.lowest = k
} else if k > ba.highest {
ba.highest = k
}
}
i, pos := getIndexAndRemainder(k)
ba.blocks[... | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"SetBit",
"(",
"k",
"uint64",
")",
"error",
"{",
"if",
"k",
">=",
"ba",
".",
"Capacity",
"(",
")",
"{",
"return",
"OutOfRangeError",
"(",
"k",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ba",
".",
"anyset",
"{",
... | // SetBit sets a bit at the given index to true. | [
"SetBit",
"sets",
"a",
"bit",
"at",
"the",
"given",
"index",
"to",
"true",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L85-L105 | train |
Workiva/go-datastructures | bitarray/bitarray.go | GetBit | func (ba *bitArray) GetBit(k uint64) (bool, error) {
if k >= ba.Capacity() {
return false, OutOfRangeError(k)
}
i, pos := getIndexAndRemainder(k)
result := ba.blocks[i]&block(1<<pos) != 0
return result, nil
} | go | func (ba *bitArray) GetBit(k uint64) (bool, error) {
if k >= ba.Capacity() {
return false, OutOfRangeError(k)
}
i, pos := getIndexAndRemainder(k)
result := ba.blocks[i]&block(1<<pos) != 0
return result, nil
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"GetBit",
"(",
"k",
"uint64",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"k",
">=",
"ba",
".",
"Capacity",
"(",
")",
"{",
"return",
"false",
",",
"OutOfRangeError",
"(",
"k",
")",
"\n",
"}",
"\n\n",
... | // GetBit returns a bool indicating if the value at the given
// index has been set. | [
"GetBit",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"value",
"at",
"the",
"given",
"index",
"has",
"been",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L109-L117 | train |
Workiva/go-datastructures | bitarray/bitarray.go | ClearBit | func (ba *bitArray) ClearBit(k uint64) error {
if k >= ba.Capacity() {
return OutOfRangeError(k)
}
if !ba.anyset { // nothing is set, might as well bail
return nil
}
i, pos := getIndexAndRemainder(k)
ba.blocks[i] &^= block(1 << pos)
if k == ba.highest {
ba.setHighest()
} else if k == ba.lowest {
ba.s... | go | func (ba *bitArray) ClearBit(k uint64) error {
if k >= ba.Capacity() {
return OutOfRangeError(k)
}
if !ba.anyset { // nothing is set, might as well bail
return nil
}
i, pos := getIndexAndRemainder(k)
ba.blocks[i] &^= block(1 << pos)
if k == ba.highest {
ba.setHighest()
} else if k == ba.lowest {
ba.s... | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"ClearBit",
"(",
"k",
"uint64",
")",
"error",
"{",
"if",
"k",
">=",
"ba",
".",
"Capacity",
"(",
")",
"{",
"return",
"OutOfRangeError",
"(",
"k",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ba",
".",
"anyset",
"{",... | //ClearBit will unset a bit at the given index if it is set. | [
"ClearBit",
"will",
"unset",
"a",
"bit",
"at",
"the",
"given",
"index",
"if",
"it",
"is",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L120-L138 | train |
Workiva/go-datastructures | bitarray/bitarray.go | Or | func (ba *bitArray) Or(other BitArray) BitArray {
if dba, ok := other.(*bitArray); ok {
return orDenseWithDenseBitArray(ba, dba)
}
return orSparseWithDenseBitArray(other.(*sparseBitArray), ba)
} | go | func (ba *bitArray) Or(other BitArray) BitArray {
if dba, ok := other.(*bitArray); ok {
return orDenseWithDenseBitArray(ba, dba)
}
return orSparseWithDenseBitArray(other.(*sparseBitArray), ba)
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"Or",
"(",
"other",
"BitArray",
")",
"BitArray",
"{",
"if",
"dba",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"bitArray",
")",
";",
"ok",
"{",
"return",
"orDenseWithDenseBitArray",
"(",
"ba",
",",
"dba",
")",
... | // Or will bitwise or two bit arrays and return a new bit array
// representing the result. | [
"Or",
"will",
"bitwise",
"or",
"two",
"bit",
"arrays",
"and",
"return",
"a",
"new",
"bit",
"array",
"representing",
"the",
"result",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L142-L148 | train |
Workiva/go-datastructures | bitarray/bitarray.go | And | func (ba *bitArray) And(other BitArray) BitArray {
if dba, ok := other.(*bitArray); ok {
return andDenseWithDenseBitArray(ba, dba)
}
return andSparseWithDenseBitArray(other.(*sparseBitArray), ba)
} | go | func (ba *bitArray) And(other BitArray) BitArray {
if dba, ok := other.(*bitArray); ok {
return andDenseWithDenseBitArray(ba, dba)
}
return andSparseWithDenseBitArray(other.(*sparseBitArray), ba)
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"And",
"(",
"other",
"BitArray",
")",
"BitArray",
"{",
"if",
"dba",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"bitArray",
")",
";",
"ok",
"{",
"return",
"andDenseWithDenseBitArray",
"(",
"ba",
",",
"dba",
")",
... | // And will bitwise and two bit arrays and return a new bit array
// representing the result. | [
"And",
"will",
"bitwise",
"and",
"two",
"bit",
"arrays",
"and",
"return",
"a",
"new",
"bit",
"array",
"representing",
"the",
"result",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L152-L158 | train |
Workiva/go-datastructures | bitarray/bitarray.go | Reset | func (ba *bitArray) Reset() {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] &= block(0)
}
ba.anyset = false
} | go | func (ba *bitArray) Reset() {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] &= block(0)
}
ba.anyset = false
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"Reset",
"(",
")",
"{",
"for",
"i",
":=",
"uint64",
"(",
"0",
")",
";",
"i",
"<",
"uint64",
"(",
"len",
"(",
"ba",
".",
"blocks",
")",
")",
";",
"i",
"++",
"{",
"ba",
".",
"blocks",
"[",
"i",
"]",
... | // Reset clears out the bit array. | [
"Reset",
"clears",
"out",
"the",
"bit",
"array",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L171-L176 | train |
Workiva/go-datastructures | bitarray/bitarray.go | Equals | func (ba *bitArray) Equals(other BitArray) bool {
if other.Capacity() == 0 && ba.highest > 0 {
return false
}
if other.Capacity() == 0 && !ba.anyset {
return true
}
var selfIndex uint64
for iter := other.Blocks(); iter.Next(); {
toIndex, otherBlock := iter.Value()
if toIndex > selfIndex {
for i := se... | go | func (ba *bitArray) Equals(other BitArray) bool {
if other.Capacity() == 0 && ba.highest > 0 {
return false
}
if other.Capacity() == 0 && !ba.anyset {
return true
}
var selfIndex uint64
for iter := other.Blocks(); iter.Next(); {
toIndex, otherBlock := iter.Value()
if toIndex > selfIndex {
for i := se... | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"Equals",
"(",
"other",
"BitArray",
")",
"bool",
"{",
"if",
"other",
".",
"Capacity",
"(",
")",
"==",
"0",
"&&",
"ba",
".",
"highest",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"other",
".... | // Equals returns a bool indicating if these two bit arrays are equal. | [
"Equals",
"returns",
"a",
"bool",
"indicating",
"if",
"these",
"two",
"bit",
"arrays",
"are",
"equal",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L179-L212 | train |
Workiva/go-datastructures | bitarray/bitarray.go | Intersects | func (ba *bitArray) Intersects(other BitArray) bool {
if other.Capacity() > ba.Capacity() {
return false
}
if sba, ok := other.(*sparseBitArray); ok {
return ba.intersectsSparseBitArray(sba)
}
return ba.intersectsDenseBitArray(other.(*bitArray))
} | go | func (ba *bitArray) Intersects(other BitArray) bool {
if other.Capacity() > ba.Capacity() {
return false
}
if sba, ok := other.(*sparseBitArray); ok {
return ba.intersectsSparseBitArray(sba)
}
return ba.intersectsDenseBitArray(other.(*bitArray))
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"Intersects",
"(",
"other",
"BitArray",
")",
"bool",
"{",
"if",
"other",
".",
"Capacity",
"(",
")",
">",
"ba",
".",
"Capacity",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"sba",
",",
"ok",
... | // Intersects returns a bool indicating if the supplied bitarray intersects
// this bitarray. This will check for intersection up to the length of the supplied
// bitarray. If the supplied bitarray is longer than this bitarray, this
// function returns false. | [
"Intersects",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"supplied",
"bitarray",
"intersects",
"this",
"bitarray",
".",
"This",
"will",
"check",
"for",
"intersection",
"up",
"to",
"the",
"length",
"of",
"the",
"supplied",
"bitarray",
".",
"If",
"the",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L218-L228 | train |
Workiva/go-datastructures | bitarray/bitarray.go | complement | func (ba *bitArray) complement() {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] = ^ba.blocks[i]
}
ba.setLowest()
if ba.anyset {
ba.setHighest()
}
} | go | func (ba *bitArray) complement() {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] = ^ba.blocks[i]
}
ba.setLowest()
if ba.anyset {
ba.setHighest()
}
} | [
"func",
"(",
"ba",
"*",
"bitArray",
")",
"complement",
"(",
")",
"{",
"for",
"i",
":=",
"uint64",
"(",
"0",
")",
";",
"i",
"<",
"uint64",
"(",
"len",
"(",
"ba",
".",
"blocks",
")",
")",
";",
"i",
"++",
"{",
"ba",
".",
"blocks",
"[",
"i",
"]... | // complement flips all bits in this array. | [
"complement",
"flips",
"all",
"bits",
"in",
"this",
"array",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L240-L249 | train |
Workiva/go-datastructures | bitarray/bitarray.go | newBitArray | func newBitArray(size uint64, args ...bool) *bitArray {
i, r := getIndexAndRemainder(size)
if r > 0 {
i++
}
ba := &bitArray{
blocks: make([]block, i),
anyset: false,
}
if len(args) > 0 && args[0] == true {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] = maximumBlock
}
ba.low... | go | func newBitArray(size uint64, args ...bool) *bitArray {
i, r := getIndexAndRemainder(size)
if r > 0 {
i++
}
ba := &bitArray{
blocks: make([]block, i),
anyset: false,
}
if len(args) > 0 && args[0] == true {
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
ba.blocks[i] = maximumBlock
}
ba.low... | [
"func",
"newBitArray",
"(",
"size",
"uint64",
",",
"args",
"...",
"bool",
")",
"*",
"bitArray",
"{",
"i",
",",
"r",
":=",
"getIndexAndRemainder",
"(",
"size",
")",
"\n",
"if",
"r",
">",
"0",
"{",
"i",
"++",
"\n",
"}",
"\n\n",
"ba",
":=",
"&",
"bi... | // newBitArray returns a new dense BitArray at the specified size. This is a
// separate private constructor so unit tests don't have to constantly cast the
// BitArray interface to the concrete type. | [
"newBitArray",
"returns",
"a",
"new",
"dense",
"BitArray",
"at",
"the",
"specified",
"size",
".",
"This",
"is",
"a",
"separate",
"private",
"constructor",
"so",
"unit",
"tests",
"don",
"t",
"have",
"to",
"constantly",
"cast",
"the",
"BitArray",
"interface",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/bitarray/bitarray.go#L285-L307 | train |
Workiva/go-datastructures | btree/plus/iterator.go | exhaust | func (iter *iterator) exhaust() keys {
keys := make(keys, 0, 10)
for iter := iter; iter.Next(); {
keys = append(keys, iter.Value())
}
return keys
} | go | func (iter *iterator) exhaust() keys {
keys := make(keys, 0, 10)
for iter := iter; iter.Next(); {
keys = append(keys, iter.Value())
}
return keys
} | [
"func",
"(",
"iter",
"*",
"iterator",
")",
"exhaust",
"(",
")",
"keys",
"{",
"keys",
":=",
"make",
"(",
"keys",
",",
"0",
",",
"10",
")",
"\n",
"for",
"iter",
":=",
"iter",
";",
"iter",
".",
"Next",
"(",
")",
";",
"{",
"keys",
"=",
"append",
... | // exhaust is a test function that's not exported | [
"exhaust",
"is",
"a",
"test",
"function",
"that",
"s",
"not",
"exported"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/plus/iterator.go#L55-L62 | train |
Workiva/go-datastructures | cache/cache.go | setElementIfNotNil | func (c *cached) setElementIfNotNil(element *list.Element) {
if element != nil {
c.element = element
}
} | go | func (c *cached) setElementIfNotNil(element *list.Element) {
if element != nil {
c.element = element
}
} | [
"func",
"(",
"c",
"*",
"cached",
")",
"setElementIfNotNil",
"(",
"element",
"*",
"list",
".",
"Element",
")",
"{",
"if",
"element",
"!=",
"nil",
"{",
"c",
".",
"element",
"=",
"element",
"\n",
"}",
"\n",
"}"
] | // Sets the provided list element on the cached item if it is not nil | [
"Sets",
"the",
"provided",
"list",
"element",
"on",
"the",
"cached",
"item",
"if",
"it",
"is",
"not",
"nil"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L37-L41 | train |
Workiva/go-datastructures | cache/cache.go | EvictionPolicy | func EvictionPolicy(policy Policy) CacheOption {
return func(c *cache) {
switch policy {
case LeastRecentlyAdded:
c.recordAccess = c.noop
c.recordAdd = c.record
case LeastRecentlyUsed:
c.recordAccess = c.record
c.recordAdd = c.noop
}
}
} | go | func EvictionPolicy(policy Policy) CacheOption {
return func(c *cache) {
switch policy {
case LeastRecentlyAdded:
c.recordAccess = c.noop
c.recordAdd = c.record
case LeastRecentlyUsed:
c.recordAccess = c.record
c.recordAdd = c.noop
}
}
} | [
"func",
"EvictionPolicy",
"(",
"policy",
"Policy",
")",
"CacheOption",
"{",
"return",
"func",
"(",
"c",
"*",
"cache",
")",
"{",
"switch",
"policy",
"{",
"case",
"LeastRecentlyAdded",
":",
"c",
".",
"recordAccess",
"=",
"c",
".",
"noop",
"\n",
"c",
".",
... | // EvictionPolicy sets the eviction policy to be used to make room for new items.
// If not provided, default is LeastRecentlyUsed. | [
"EvictionPolicy",
"sets",
"the",
"eviction",
"policy",
"to",
"be",
"used",
"to",
"make",
"room",
"for",
"new",
"items",
".",
"If",
"not",
"provided",
"default",
"is",
"LeastRecentlyUsed",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L69-L80 | train |
Workiva/go-datastructures | cache/cache.go | New | func New(capacity uint64, options ...CacheOption) Cache {
c := &cache{
cap: capacity,
keyList: list.New(),
items: map[string]*cached{},
}
// Default LRU eviction policy
EvictionPolicy(LeastRecentlyUsed)(c)
for _, option := range options {
option(c)
}
return c
} | go | func New(capacity uint64, options ...CacheOption) Cache {
c := &cache{
cap: capacity,
keyList: list.New(),
items: map[string]*cached{},
}
// Default LRU eviction policy
EvictionPolicy(LeastRecentlyUsed)(c)
for _, option := range options {
option(c)
}
return c
} | [
"func",
"New",
"(",
"capacity",
"uint64",
",",
"options",
"...",
"CacheOption",
")",
"Cache",
"{",
"c",
":=",
"&",
"cache",
"{",
"cap",
":",
"capacity",
",",
"keyList",
":",
"list",
".",
"New",
"(",
")",
",",
"items",
":",
"map",
"[",
"string",
"]"... | // New returns a cache with the requested options configured.
// The cache consumes memory bounded by a fixed capacity,
// plus tracking overhead linear in the number of items. | [
"New",
"returns",
"a",
"cache",
"with",
"the",
"requested",
"options",
"configured",
".",
"The",
"cache",
"consumes",
"memory",
"bounded",
"by",
"a",
"fixed",
"capacity",
"plus",
"tracking",
"overhead",
"linear",
"in",
"the",
"number",
"of",
"items",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L85-L99 | train |
Workiva/go-datastructures | cache/cache.go | ensureCapacity | func (c *cache) ensureCapacity(toAdd uint64) {
mustRemove := int64(c.size+toAdd) - int64(c.cap)
for mustRemove > 0 {
key := c.keyList.Back().Value.(string)
mustRemove -= int64(c.items[key].item.Size())
c.remove(key)
}
} | go | func (c *cache) ensureCapacity(toAdd uint64) {
mustRemove := int64(c.size+toAdd) - int64(c.cap)
for mustRemove > 0 {
key := c.keyList.Back().Value.(string)
mustRemove -= int64(c.items[key].item.Size())
c.remove(key)
}
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"ensureCapacity",
"(",
"toAdd",
"uint64",
")",
"{",
"mustRemove",
":=",
"int64",
"(",
"c",
".",
"size",
"+",
"toAdd",
")",
"-",
"int64",
"(",
"c",
".",
"cap",
")",
"\n",
"for",
"mustRemove",
">",
"0",
"{",
"ke... | // Given the need to add some number of new bytes to the cache,
// evict items according to the eviction policy until there is room.
// The caller should hold the cache lock. | [
"Given",
"the",
"need",
"to",
"add",
"some",
"number",
"of",
"new",
"bytes",
"to",
"the",
"cache",
"evict",
"items",
"according",
"to",
"the",
"eviction",
"policy",
"until",
"there",
"is",
"room",
".",
"The",
"caller",
"should",
"hold",
"the",
"cache",
"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L156-L163 | train |
Workiva/go-datastructures | cache/cache.go | remove | func (c *cache) remove(key string) {
if cached, ok := c.items[key]; ok {
delete(c.items, key)
c.size -= cached.item.Size()
c.keyList.Remove(cached.element)
}
} | go | func (c *cache) remove(key string) {
if cached, ok := c.items[key]; ok {
delete(c.items, key)
c.size -= cached.item.Size()
c.keyList.Remove(cached.element)
}
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"remove",
"(",
"key",
"string",
")",
"{",
"if",
"cached",
",",
"ok",
":=",
"c",
".",
"items",
"[",
"key",
"]",
";",
"ok",
"{",
"delete",
"(",
"c",
".",
"items",
",",
"key",
")",
"\n",
"c",
".",
"size",
"... | // Remove the item associated with the given key.
// The caller should hold the cache lock. | [
"Remove",
"the",
"item",
"associated",
"with",
"the",
"given",
"key",
".",
"The",
"caller",
"should",
"hold",
"the",
"cache",
"lock",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L167-L173 | train |
Workiva/go-datastructures | cache/cache.go | record | func (c *cache) record(key string) *list.Element {
if item, ok := c.items[key]; ok {
c.keyList.MoveToFront(item.element)
return item.element
}
return c.keyList.PushFront(key)
} | go | func (c *cache) record(key string) *list.Element {
if item, ok := c.items[key]; ok {
c.keyList.MoveToFront(item.element)
return item.element
}
return c.keyList.PushFront(key)
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"record",
"(",
"key",
"string",
")",
"*",
"list",
".",
"Element",
"{",
"if",
"item",
",",
"ok",
":=",
"c",
".",
"items",
"[",
"key",
"]",
";",
"ok",
"{",
"c",
".",
"keyList",
".",
"MoveToFront",
"(",
"item",... | // A function to record the given key and mark it as last to be evicted | [
"A",
"function",
"to",
"record",
"the",
"given",
"key",
"and",
"mark",
"it",
"as",
"last",
"to",
"be",
"evicted"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/cache/cache.go#L179-L185 | train |
Workiva/go-datastructures | set/dict.go | Add | func (set *Set) Add(items ...interface{}) {
set.lock.Lock()
defer set.lock.Unlock()
set.flattened = nil
for _, item := range items {
set.items[item] = struct{}{}
}
} | go | func (set *Set) Add(items ...interface{}) {
set.lock.Lock()
defer set.lock.Unlock()
set.flattened = nil
for _, item := range items {
set.items[item] = struct{}{}
}
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Add",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"{",
"set",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"set",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"set",
".",
"flattened",
"=",
"nil"... | // Add will add the provided items to the set. | [
"Add",
"will",
"add",
"the",
"provided",
"items",
"to",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L42-L50 | train |
Workiva/go-datastructures | set/dict.go | Remove | func (set *Set) Remove(items ...interface{}) {
set.lock.Lock()
defer set.lock.Unlock()
set.flattened = nil
for _, item := range items {
delete(set.items, item)
}
} | go | func (set *Set) Remove(items ...interface{}) {
set.lock.Lock()
defer set.lock.Unlock()
set.flattened = nil
for _, item := range items {
delete(set.items, item)
}
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Remove",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"{",
"set",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"set",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"set",
".",
"flattened",
"=",
"n... | // Remove will remove the given items from the set. | [
"Remove",
"will",
"remove",
"the",
"given",
"items",
"from",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L53-L61 | train |
Workiva/go-datastructures | set/dict.go | Exists | func (set *Set) Exists(item interface{}) bool {
set.lock.RLock()
_, ok := set.items[item]
set.lock.RUnlock()
return ok
} | go | func (set *Set) Exists(item interface{}) bool {
set.lock.RLock()
_, ok := set.items[item]
set.lock.RUnlock()
return ok
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Exists",
"(",
"item",
"interface",
"{",
"}",
")",
"bool",
"{",
"set",
".",
"lock",
".",
"RLock",
"(",
")",
"\n\n",
"_",
",",
"ok",
":=",
"set",
".",
"items",
"[",
"item",
"]",
"\n\n",
"set",
".",
"lock",
... | // Exists returns a bool indicating if the given item exists in the set. | [
"Exists",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"given",
"item",
"exists",
"in",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L64-L72 | train |
Workiva/go-datastructures | set/dict.go | Flatten | func (set *Set) Flatten() []interface{} {
set.lock.Lock()
defer set.lock.Unlock()
if set.flattened != nil {
return set.flattened
}
set.flattened = make([]interface{}, 0, len(set.items))
for item := range set.items {
set.flattened = append(set.flattened, item)
}
return set.flattened
} | go | func (set *Set) Flatten() []interface{} {
set.lock.Lock()
defer set.lock.Unlock()
if set.flattened != nil {
return set.flattened
}
set.flattened = make([]interface{}, 0, len(set.items))
for item := range set.items {
set.flattened = append(set.flattened, item)
}
return set.flattened
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Flatten",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"set",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"set",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"set",
".",
"flattened",
"!=",
... | // Flatten will return a list of the items in the set. | [
"Flatten",
"will",
"return",
"a",
"list",
"of",
"the",
"items",
"in",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L75-L88 | train |
Workiva/go-datastructures | set/dict.go | Len | func (set *Set) Len() int64 {
set.lock.RLock()
size := int64(len(set.items))
set.lock.RUnlock()
return size
} | go | func (set *Set) Len() int64 {
set.lock.RLock()
size := int64(len(set.items))
set.lock.RUnlock()
return size
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Len",
"(",
")",
"int64",
"{",
"set",
".",
"lock",
".",
"RLock",
"(",
")",
"\n\n",
"size",
":=",
"int64",
"(",
"len",
"(",
"set",
".",
"items",
")",
")",
"\n\n",
"set",
".",
"lock",
".",
"RUnlock",
"(",
")... | // Len returns the number of items in the set. | [
"Len",
"returns",
"the",
"number",
"of",
"items",
"in",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L91-L99 | train |
Workiva/go-datastructures | set/dict.go | Clear | func (set *Set) Clear() {
set.lock.Lock()
set.items = map[interface{}]struct{}{}
set.lock.Unlock()
} | go | func (set *Set) Clear() {
set.lock.Lock()
set.items = map[interface{}]struct{}{}
set.lock.Unlock()
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Clear",
"(",
")",
"{",
"set",
".",
"lock",
".",
"Lock",
"(",
")",
"\n\n",
"set",
".",
"items",
"=",
"map",
"[",
"interface",
"{",
"}",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"set",
".",
"lock",
".",
... | // Clear will remove all items from the set. | [
"Clear",
"will",
"remove",
"all",
"items",
"from",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L102-L108 | train |
Workiva/go-datastructures | set/dict.go | All | func (set *Set) All(items ...interface{}) bool {
set.lock.RLock()
defer set.lock.RUnlock()
for _, item := range items {
if _, ok := set.items[item]; !ok {
return false
}
}
return true
} | go | func (set *Set) All(items ...interface{}) bool {
set.lock.RLock()
defer set.lock.RUnlock()
for _, item := range items {
if _, ok := set.items[item]; !ok {
return false
}
}
return true
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"All",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"set",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"set",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"item",
... | // All returns a bool indicating if all of the supplied items exist in the set. | [
"All",
"returns",
"a",
"bool",
"indicating",
"if",
"all",
"of",
"the",
"supplied",
"items",
"exist",
"in",
"the",
"set",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L111-L122 | train |
Workiva/go-datastructures | set/dict.go | Dispose | func (set *Set) Dispose() {
set.lock.Lock()
defer set.lock.Unlock()
for k := range set.items {
delete(set.items, k)
}
//this is so we don't hang onto any references
for i := 0; i < len(set.flattened); i++ {
set.flattened[i] = nil
}
set.flattened = set.flattened[:0]
pool.Put(set)
} | go | func (set *Set) Dispose() {
set.lock.Lock()
defer set.lock.Unlock()
for k := range set.items {
delete(set.items, k)
}
//this is so we don't hang onto any references
for i := 0; i < len(set.flattened); i++ {
set.flattened[i] = nil
}
set.flattened = set.flattened[:0]
pool.Put(set)
} | [
"func",
"(",
"set",
"*",
"Set",
")",
"Dispose",
"(",
")",
"{",
"set",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"set",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"k",
":=",
"range",
"set",
".",
"items",
"{",
"delete",
"(",
... | // Dispose will add this set back into the pool. | [
"Dispose",
"will",
"add",
"this",
"set",
"back",
"into",
"the",
"pool",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L125-L140 | train |
Workiva/go-datastructures | set/dict.go | New | func New(items ...interface{}) *Set {
set := pool.Get().(*Set)
for _, item := range items {
set.items[item] = struct{}{}
}
if len(items) > 0 {
set.flattened = nil
}
return set
} | go | func New(items ...interface{}) *Set {
set := pool.Get().(*Set)
for _, item := range items {
set.items[item] = struct{}{}
}
if len(items) > 0 {
set.flattened = nil
}
return set
} | [
"func",
"New",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"*",
"Set",
"{",
"set",
":=",
"pool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"Set",
")",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"items",
"{",
"set",
".",
"items",
"[",
"item... | // New is the constructor for sets. It will pull from a reuseable memory pool if it can.
// Takes a list of items to initialize the set with. | [
"New",
"is",
"the",
"constructor",
"for",
"sets",
".",
"It",
"will",
"pull",
"from",
"a",
"reuseable",
"memory",
"pool",
"if",
"it",
"can",
".",
"Takes",
"a",
"list",
"of",
"items",
"to",
"initialize",
"the",
"set",
"with",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/set/dict.go#L144-L155 | train |
Workiva/go-datastructures | augmentedtree/intervals.go | Dispose | func (ivs *Intervals) Dispose() {
for i := 0; i < len(*ivs); i++ {
(*ivs)[i] = nil
}
*ivs = (*ivs)[:0]
intervalsPool.Put(*ivs)
} | go | func (ivs *Intervals) Dispose() {
for i := 0; i < len(*ivs); i++ {
(*ivs)[i] = nil
}
*ivs = (*ivs)[:0]
intervalsPool.Put(*ivs)
} | [
"func",
"(",
"ivs",
"*",
"Intervals",
")",
"Dispose",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"*",
"ivs",
")",
";",
"i",
"++",
"{",
"(",
"*",
"ivs",
")",
"[",
"i",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"*",
"ivs",
... | // Dispose will free any consumed resources and allow this list to be
// re-allocated. | [
"Dispose",
"will",
"free",
"any",
"consumed",
"resources",
"and",
"allow",
"this",
"list",
"to",
"be",
"re",
"-",
"allocated",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/augmentedtree/intervals.go#L32-L39 | train |
Workiva/go-datastructures | slice/skip/iterator.go | Next | func (iter *iterator) Next() bool {
if iter.first {
iter.first = false
return iter.n != nil
}
if iter.n == nil {
return false
}
iter.n = iter.n.forward[0]
return iter.n != nil
} | go | func (iter *iterator) Next() bool {
if iter.first {
iter.first = false
return iter.n != nil
}
if iter.n == nil {
return false
}
iter.n = iter.n.forward[0]
return iter.n != nil
} | [
"func",
"(",
"iter",
"*",
"iterator",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"iter",
".",
"first",
"{",
"iter",
".",
"first",
"=",
"false",
"\n",
"return",
"iter",
".",
"n",
"!=",
"nil",
"\n",
"}",
"\n\n",
"if",
"iter",
".",
"n",
"==",
"nil"... | // Next returns a bool indicating if there are any further values
// in this iterator. | [
"Next",
"returns",
"a",
"bool",
"indicating",
"if",
"there",
"are",
"any",
"further",
"values",
"in",
"this",
"iterator",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L33-L45 | train |
Workiva/go-datastructures | slice/skip/iterator.go | Value | func (iter *iterator) Value() common.Comparator {
if iter.n == nil {
return nil
}
return iter.n.entry
} | go | func (iter *iterator) Value() common.Comparator {
if iter.n == nil {
return nil
}
return iter.n.entry
} | [
"func",
"(",
"iter",
"*",
"iterator",
")",
"Value",
"(",
")",
"common",
".",
"Comparator",
"{",
"if",
"iter",
".",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"iter",
".",
"n",
".",
"entry",
"\n",
"}"
] | // Value returns a Comparator representing the iterator's present
// position in the query. Returns nil if no values remain to iterate. | [
"Value",
"returns",
"a",
"Comparator",
"representing",
"the",
"iterator",
"s",
"present",
"position",
"in",
"the",
"query",
".",
"Returns",
"nil",
"if",
"no",
"values",
"remain",
"to",
"iterate",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L49-L55 | train |
Workiva/go-datastructures | slice/skip/iterator.go | exhaust | func (iter *iterator) exhaust() common.Comparators {
entries := make(common.Comparators, 0, 10)
for i := iter; i.Next(); {
entries = append(entries, i.Value())
}
return entries
} | go | func (iter *iterator) exhaust() common.Comparators {
entries := make(common.Comparators, 0, 10)
for i := iter; i.Next(); {
entries = append(entries, i.Value())
}
return entries
} | [
"func",
"(",
"iter",
"*",
"iterator",
")",
"exhaust",
"(",
")",
"common",
".",
"Comparators",
"{",
"entries",
":=",
"make",
"(",
"common",
".",
"Comparators",
",",
"0",
",",
"10",
")",
"\n",
"for",
"i",
":=",
"iter",
";",
"i",
".",
"Next",
"(",
"... | // exhaust is a helper method to exhaust this iterator and return
// all remaining entries. | [
"exhaust",
"is",
"a",
"helper",
"method",
"to",
"exhaust",
"this",
"iterator",
"and",
"return",
"all",
"remaining",
"entries",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/slice/skip/iterator.go#L59-L66 | train |
Workiva/go-datastructures | futures/selectable.go | WaitChan | func (f *Selectable) WaitChan() <-chan struct{} {
if atomic.LoadUint32(&f.filled) == 1 {
return closed
}
return f.wchan()
} | go | func (f *Selectable) WaitChan() <-chan struct{} {
if atomic.LoadUint32(&f.filled) == 1 {
return closed
}
return f.wchan()
} | [
"func",
"(",
"f",
"*",
"Selectable",
")",
"WaitChan",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"if",
"atomic",
".",
"LoadUint32",
"(",
"&",
"f",
".",
"filled",
")",
"==",
"1",
"{",
"return",
"closed",
"\n",
"}",
"\n",
"return",
"f",
".",
... | // WaitChan returns channel, which is closed when future is fullfilled. | [
"WaitChan",
"returns",
"channel",
"which",
"is",
"closed",
"when",
"future",
"is",
"fullfilled",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L60-L65 | train |
Workiva/go-datastructures | futures/selectable.go | GetResult | func (f *Selectable) GetResult() (interface{}, error) {
if atomic.LoadUint32(&f.filled) == 0 {
<-f.wchan()
}
return f.val, f.err
} | go | func (f *Selectable) GetResult() (interface{}, error) {
if atomic.LoadUint32(&f.filled) == 0 {
<-f.wchan()
}
return f.val, f.err
} | [
"func",
"(",
"f",
"*",
"Selectable",
")",
"GetResult",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"atomic",
".",
"LoadUint32",
"(",
"&",
"f",
".",
"filled",
")",
"==",
"0",
"{",
"<-",
"f",
".",
"wchan",
"(",
")",
"\n",
... | // GetResult waits for future to be fullfilled and returns value or error,
// whatever is set first | [
"GetResult",
"waits",
"for",
"future",
"to",
"be",
"fullfilled",
"and",
"returns",
"value",
"or",
"error",
"whatever",
"is",
"set",
"first"
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L69-L74 | train |
Workiva/go-datastructures | futures/selectable.go | Fill | func (f *Selectable) Fill(v interface{}, e error) error {
f.m.Lock()
if f.filled == 0 {
f.val = v
f.err = e
atomic.StoreUint32(&f.filled, 1)
w := f.wait
f.wait = closed
if w != nil {
close(w)
}
}
f.m.Unlock()
return f.err
} | go | func (f *Selectable) Fill(v interface{}, e error) error {
f.m.Lock()
if f.filled == 0 {
f.val = v
f.err = e
atomic.StoreUint32(&f.filled, 1)
w := f.wait
f.wait = closed
if w != nil {
close(w)
}
}
f.m.Unlock()
return f.err
} | [
"func",
"(",
"f",
"*",
"Selectable",
")",
"Fill",
"(",
"v",
"interface",
"{",
"}",
",",
"e",
"error",
")",
"error",
"{",
"f",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"if",
"f",
".",
"filled",
"==",
"0",
"{",
"f",
".",
"val",
"=",
"v",
"\n",
... | // Fill sets value for future, if it were not already fullfilled
// Returns error, if it were already set to future. | [
"Fill",
"sets",
"value",
"for",
"future",
"if",
"it",
"were",
"not",
"already",
"fullfilled",
"Returns",
"error",
"if",
"it",
"were",
"already",
"set",
"to",
"future",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/futures/selectable.go#L78-L92 | train |
Workiva/go-datastructures | queue/queue.go | Put | func (q *Queue) Put(items ...interface{}) error {
if len(items) == 0 {
return nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return ErrDisposed
}
q.items = append(q.items, items...)
for {
sema := q.waiters.get()
if sema == nil {
break
}
sema.response.Add(1)
select {
case sema.ready <... | go | func (q *Queue) Put(items ...interface{}) error {
if len(items) == 0 {
return nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return ErrDisposed
}
q.items = append(q.items, items...)
for {
sema := q.waiters.get()
if sema == nil {
break
}
sema.response.Add(1)
select {
case sema.ready <... | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Put",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"items",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n\n",
"i... | // Put will add the specified items to the queue. | [
"Put",
"will",
"add",
"the",
"specified",
"items",
"to",
"the",
"queue",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L170-L202 | train |
Workiva/go-datastructures | queue/queue.go | Poll | func (q *Queue) Poll(number int64, timeout time.Duration) ([]interface{}, error) {
if number < 1 {
// thanks again go
return []interface{}{}, nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return nil, ErrDisposed
}
var items []interface{}
if len(q.items) == 0 {
sema := newSema()
q.waiters.pu... | go | func (q *Queue) Poll(number int64, timeout time.Duration) ([]interface{}, error) {
if number < 1 {
// thanks again go
return []interface{}{}, nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return nil, ErrDisposed
}
var items []interface{}
if len(q.items) == 0 {
sema := newSema()
q.waiters.pu... | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Poll",
"(",
"number",
"int64",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"number",
"<",
"1",
"{",
"// thanks again go",
"return",
"[",
"]"... | // Poll retrieves items from the queue. If there are some items in the queue,
// Poll will return a number UP TO the number passed in as a parameter. If no
// items are in the queue, this method will pause until items are added to the
// queue or the provided timeout is reached. A non-positive timeout will block
// ... | [
"Poll",
"retrieves",
"items",
"from",
"the",
"queue",
".",
"If",
"there",
"are",
"some",
"items",
"in",
"the",
"queue",
"Poll",
"will",
"return",
"a",
"number",
"UP",
"TO",
"the",
"number",
"passed",
"in",
"as",
"a",
"parameter",
".",
"If",
"no",
"item... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L217-L270 | train |
Workiva/go-datastructures | queue/queue.go | Peek | func (q *Queue) Peek() (interface{}, error) {
q.lock.Lock()
defer q.lock.Unlock()
if q.disposed {
return nil, ErrDisposed
}
peekItem, ok := q.items.peek()
if !ok {
return nil, ErrEmptyQueue
}
return peekItem, nil
} | go | func (q *Queue) Peek() (interface{}, error) {
q.lock.Lock()
defer q.lock.Unlock()
if q.disposed {
return nil, ErrDisposed
}
peekItem, ok := q.items.peek()
if !ok {
return nil, ErrEmptyQueue
}
return peekItem, nil
} | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Peek",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"q",
".",
"disposed",
... | // Peek returns a the first item in the queue by value
// without modifying the queue. | [
"Peek",
"returns",
"a",
"the",
"first",
"item",
"in",
"the",
"queue",
"by",
"value",
"without",
"modifying",
"the",
"queue",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L274-L288 | train |
Workiva/go-datastructures | queue/queue.go | TakeUntil | func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, error) {
if checker == nil {
return nil, nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return nil, ErrDisposed
}
result := q.items.getUntil(checker)
q.lock.Unlock()
return result, nil
} | go | func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, error) {
if checker == nil {
return nil, nil
}
q.lock.Lock()
if q.disposed {
q.lock.Unlock()
return nil, ErrDisposed
}
result := q.items.getUntil(checker)
q.lock.Unlock()
return result, nil
} | [
"func",
"(",
"q",
"*",
"Queue",
")",
"TakeUntil",
"(",
"checker",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"bool",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"checker",
"==",
"nil",
"{",
"return",
"nil",
",",... | // TakeUntil takes a function and returns a list of items that
// match the checker until the checker returns false. This does not
// wait if there are no items in the queue. | [
"TakeUntil",
"takes",
"a",
"function",
"and",
"returns",
"a",
"list",
"of",
"items",
"that",
"match",
"the",
"checker",
"until",
"the",
"checker",
"returns",
"false",
".",
"This",
"does",
"not",
"wait",
"if",
"there",
"are",
"no",
"items",
"in",
"the",
"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L293-L308 | train |
Workiva/go-datastructures | queue/queue.go | Empty | func (q *Queue) Empty() bool {
q.lock.Lock()
defer q.lock.Unlock()
return len(q.items) == 0
} | go | func (q *Queue) Empty() bool {
q.lock.Lock()
defer q.lock.Unlock()
return len(q.items) == 0
} | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Empty",
"(",
")",
"bool",
"{",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"len",
"(",
"q",
".",
"items",
")",
"==",
"0",
"\n",
"... | // Empty returns a bool indicating if this bool is empty. | [
"Empty",
"returns",
"a",
"bool",
"indicating",
"if",
"this",
"bool",
"is",
"empty",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L311-L316 | train |
Workiva/go-datastructures | queue/queue.go | Len | func (q *Queue) Len() int64 {
q.lock.Lock()
defer q.lock.Unlock()
return int64(len(q.items))
} | go | func (q *Queue) Len() int64 {
q.lock.Lock()
defer q.lock.Unlock()
return int64(len(q.items))
} | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Len",
"(",
")",
"int64",
"{",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"int64",
"(",
"len",
"(",
"q",
".",
"items",
")",
")",
... | // Len returns the number of items in this queue. | [
"Len",
"returns",
"the",
"number",
"of",
"items",
"in",
"this",
"queue",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L319-L324 | train |
Workiva/go-datastructures | queue/queue.go | Disposed | func (q *Queue) Disposed() bool {
q.lock.Lock()
defer q.lock.Unlock()
return q.disposed
} | go | func (q *Queue) Disposed() bool {
q.lock.Lock()
defer q.lock.Unlock()
return q.disposed
} | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Disposed",
"(",
")",
"bool",
"{",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"q",
".",
"disposed",
"\n",
"}"
] | // Disposed returns a bool indicating if this queue
// has had disposed called on it. | [
"Disposed",
"returns",
"a",
"bool",
"indicating",
"if",
"this",
"queue",
"has",
"had",
"disposed",
"called",
"on",
"it",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L328-L333 | train |
Workiva/go-datastructures | queue/queue.go | Dispose | func (q *Queue) Dispose() []interface{} {
q.lock.Lock()
defer q.lock.Unlock()
q.disposed = true
for _, waiter := range q.waiters {
waiter.response.Add(1)
select {
case waiter.ready <- true:
// release Poll immediately
default:
// ignore if it's a timeout or in the get
}
}
disposedItems := q.item... | go | func (q *Queue) Dispose() []interface{} {
q.lock.Lock()
defer q.lock.Unlock()
q.disposed = true
for _, waiter := range q.waiters {
waiter.response.Add(1)
select {
case waiter.ready <- true:
// release Poll immediately
default:
// ignore if it's a timeout or in the get
}
}
disposedItems := q.item... | [
"func",
"(",
"q",
"*",
"Queue",
")",
"Dispose",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"q",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"q",
".",
"disposed",
"=",
"true",
"\n"... | // Dispose will dispose of this queue and returns
// the items disposed. Any subsequent calls to Get
// or Put will return an error. | [
"Dispose",
"will",
"dispose",
"of",
"this",
"queue",
"and",
"returns",
"the",
"items",
"disposed",
".",
"Any",
"subsequent",
"calls",
"to",
"Get",
"or",
"Put",
"will",
"return",
"an",
"error",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/queue/queue.go#L338-L359 | train |
Workiva/go-datastructures | trie/dtrie/dtrie.go | New | func New(hasher func(v interface{}) uint32) *Dtrie {
if hasher == nil {
hasher = defaultHasher
}
return &Dtrie{
root: emptyNode(0, 32),
hasher: hasher,
}
} | go | func New(hasher func(v interface{}) uint32) *Dtrie {
if hasher == nil {
hasher = defaultHasher
}
return &Dtrie{
root: emptyNode(0, 32),
hasher: hasher,
}
} | [
"func",
"New",
"(",
"hasher",
"func",
"(",
"v",
"interface",
"{",
"}",
")",
"uint32",
")",
"*",
"Dtrie",
"{",
"if",
"hasher",
"==",
"nil",
"{",
"hasher",
"=",
"defaultHasher",
"\n",
"}",
"\n",
"return",
"&",
"Dtrie",
"{",
"root",
":",
"emptyNode",
... | // New creates an empty DTrie with the given hashing function.
// If nil is passed in, the default hashing function will be used. | [
"New",
"creates",
"an",
"empty",
"DTrie",
"with",
"the",
"given",
"hashing",
"function",
".",
"If",
"nil",
"is",
"passed",
"in",
"the",
"default",
"hashing",
"function",
"will",
"be",
"used",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L62-L70 | train |
Workiva/go-datastructures | trie/dtrie/dtrie.go | Size | func (d *Dtrie) Size() (size int) {
for _ = range iterate(d.root, nil) {
size++
}
return size
} | go | func (d *Dtrie) Size() (size int) {
for _ = range iterate(d.root, nil) {
size++
}
return size
} | [
"func",
"(",
"d",
"*",
"Dtrie",
")",
"Size",
"(",
")",
"(",
"size",
"int",
")",
"{",
"for",
"_",
"=",
"range",
"iterate",
"(",
"d",
".",
"root",
",",
"nil",
")",
"{",
"size",
"++",
"\n",
"}",
"\n",
"return",
"size",
"\n",
"}"
] | // Size returns the number of entries in the Dtrie. | [
"Size",
"returns",
"the",
"number",
"of",
"entries",
"in",
"the",
"Dtrie",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L73-L78 | train |
Workiva/go-datastructures | trie/dtrie/dtrie.go | Get | func (d *Dtrie) Get(key interface{}) interface{} {
return get(d.root, d.hasher(key), key).Value()
} | go | func (d *Dtrie) Get(key interface{}) interface{} {
return get(d.root, d.hasher(key), key).Value()
} | [
"func",
"(",
"d",
"*",
"Dtrie",
")",
"Get",
"(",
"key",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"return",
"get",
"(",
"d",
".",
"root",
",",
"d",
".",
"hasher",
"(",
"key",
")",
",",
"key",
")",
".",
"Value",
"(",
")",
"\n",
... | // Get returns the value for the associated key or returns nil if the
// key does not exist. | [
"Get",
"returns",
"the",
"value",
"for",
"the",
"associated",
"key",
"or",
"returns",
"nil",
"if",
"the",
"key",
"does",
"not",
"exist",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L82-L84 | train |
Workiva/go-datastructures | trie/dtrie/dtrie.go | Insert | func (d *Dtrie) Insert(key, value interface{}) *Dtrie {
root := insert(d.root, &entry{d.hasher(key), key, value})
return &Dtrie{root, d.hasher}
} | go | func (d *Dtrie) Insert(key, value interface{}) *Dtrie {
root := insert(d.root, &entry{d.hasher(key), key, value})
return &Dtrie{root, d.hasher}
} | [
"func",
"(",
"d",
"*",
"Dtrie",
")",
"Insert",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"Dtrie",
"{",
"root",
":=",
"insert",
"(",
"d",
".",
"root",
",",
"&",
"entry",
"{",
"d",
".",
"hasher",
"(",
"key",
")",
",",
"key",
",... | // Insert adds a key value pair to the Dtrie, replacing the existing value if
// the key already exists and returns the resulting Dtrie. | [
"Insert",
"adds",
"a",
"key",
"value",
"pair",
"to",
"the",
"Dtrie",
"replacing",
"the",
"existing",
"value",
"if",
"the",
"key",
"already",
"exists",
"and",
"returns",
"the",
"resulting",
"Dtrie",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L88-L91 | train |
Workiva/go-datastructures | trie/dtrie/dtrie.go | Remove | func (d *Dtrie) Remove(key interface{}) *Dtrie {
root := remove(d.root, d.hasher(key), key)
return &Dtrie{root, d.hasher}
} | go | func (d *Dtrie) Remove(key interface{}) *Dtrie {
root := remove(d.root, d.hasher(key), key)
return &Dtrie{root, d.hasher}
} | [
"func",
"(",
"d",
"*",
"Dtrie",
")",
"Remove",
"(",
"key",
"interface",
"{",
"}",
")",
"*",
"Dtrie",
"{",
"root",
":=",
"remove",
"(",
"d",
".",
"root",
",",
"d",
".",
"hasher",
"(",
"key",
")",
",",
"key",
")",
"\n",
"return",
"&",
"Dtrie",
... | // Remove deletes the value for the associated key if it exists and returns
// the resulting Dtrie. | [
"Remove",
"deletes",
"the",
"value",
"for",
"the",
"associated",
"key",
"if",
"it",
"exists",
"and",
"returns",
"the",
"resulting",
"Dtrie",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/dtrie/dtrie.go#L95-L98 | train |
Workiva/go-datastructures | btree/immutable/query.go | filter | func (t *Tr) filter(start, stop interface{}, n *Node, fn func(key *Key) bool) bool {
for iter := n.iter(t.config.Comparator, start, stop); iter.next(); {
id, _ := iter.value()
if !fn(id) {
return false
}
}
return true
} | go | func (t *Tr) filter(start, stop interface{}, n *Node, fn func(key *Key) bool) bool {
for iter := n.iter(t.config.Comparator, start, stop); iter.next(); {
id, _ := iter.value()
if !fn(id) {
return false
}
}
return true
} | [
"func",
"(",
"t",
"*",
"Tr",
")",
"filter",
"(",
"start",
",",
"stop",
"interface",
"{",
"}",
",",
"n",
"*",
"Node",
",",
"fn",
"func",
"(",
"key",
"*",
"Key",
")",
"bool",
")",
"bool",
"{",
"for",
"iter",
":=",
"n",
".",
"iter",
"(",
"t",
... | // filter performs an after fetch filtering of the values in the provided node.
// Due to the nature of the UB-Tree, we may get results in the node that
// aren't in the provided range. The returned list of keys is not necessarily
// in the correct row-major order. | [
"filter",
"performs",
"an",
"after",
"fetch",
"filtering",
"of",
"the",
"values",
"in",
"the",
"provided",
"node",
".",
"Due",
"to",
"the",
"nature",
"of",
"the",
"UB",
"-",
"Tree",
"we",
"may",
"get",
"results",
"in",
"the",
"node",
"that",
"aren",
"t... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/query.go#L92-L101 | train |
Workiva/go-datastructures | btree/immutable/query.go | iterativeFind | func (t *Tr) iterativeFind(value interface{}, id ID) (*path, error) {
if len(id) == 0 { // can't find a matching node
return nil, nil
}
path := &path{}
var n *Node
var err error
var i int
var key *Key
for {
n, err = t.contextOrCachedNode(id, t.mutable)
if err != nil {
return nil, err
}
key, i = ... | go | func (t *Tr) iterativeFind(value interface{}, id ID) (*path, error) {
if len(id) == 0 { // can't find a matching node
return nil, nil
}
path := &path{}
var n *Node
var err error
var i int
var key *Key
for {
n, err = t.contextOrCachedNode(id, t.mutable)
if err != nil {
return nil, err
}
key, i = ... | [
"func",
"(",
"t",
"*",
"Tr",
")",
"iterativeFind",
"(",
"value",
"interface",
"{",
"}",
",",
"id",
"ID",
")",
"(",
"*",
"path",
",",
"error",
")",
"{",
"if",
"len",
"(",
"id",
")",
"==",
"0",
"{",
"// can't find a matching node",
"return",
"nil",
"... | // iterativeFind searches for the node with the provided value. This
// is an iterative function and returns an error if there was a problem
// with persistence. | [
"iterativeFind",
"searches",
"for",
"the",
"node",
"with",
"the",
"provided",
"value",
".",
"This",
"is",
"an",
"iterative",
"function",
"and",
"returns",
"an",
"error",
"if",
"there",
"was",
"a",
"problem",
"with",
"persistence",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/btree/immutable/query.go#L138-L166 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | isInternal | func isInternal(n *node) bool {
if n == nil {
return false
}
return n.entry == nil
} | go | func isInternal(n *node) bool {
if n == nil {
return false
}
return n.entry == nil
} | [
"func",
"isInternal",
"(",
"n",
"*",
"node",
")",
"bool",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"n",
".",
"entry",
"==",
"nil",
"\n",
"}"
] | // isInternal returns a bool indicating if the provided
// node is an internal node, that is, non-leaf node. | [
"isInternal",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"node",
"is",
"an",
"internal",
"node",
"that",
"is",
"non",
"-",
"leaf",
"node",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L51-L56 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | hasInternal | func hasInternal(n *node) bool {
return isInternal(n.children[0]) || isInternal(n.children[1])
} | go | func hasInternal(n *node) bool {
return isInternal(n.children[0]) || isInternal(n.children[1])
} | [
"func",
"hasInternal",
"(",
"n",
"*",
"node",
")",
"bool",
"{",
"return",
"isInternal",
"(",
"n",
".",
"children",
"[",
"0",
"]",
")",
"||",
"isInternal",
"(",
"n",
".",
"children",
"[",
"1",
"]",
")",
"\n",
"}"
] | // hasInternal returns a bool indicating if the provided
// node has a child that is an internal node. | [
"hasInternal",
"returns",
"a",
"bool",
"indicating",
"if",
"the",
"provided",
"node",
"has",
"a",
"child",
"that",
"is",
"an",
"internal",
"node",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L60-L62 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | newNode | func newNode(parent *node, entry Entry) *node {
return &node{
children: [2]*node{},
entry: entry,
parent: parent,
}
} | go | func newNode(parent *node, entry Entry) *node {
return &node{
children: [2]*node{},
entry: entry,
parent: parent,
}
} | [
"func",
"newNode",
"(",
"parent",
"*",
"node",
",",
"entry",
"Entry",
")",
"*",
"node",
"{",
"return",
"&",
"node",
"{",
"children",
":",
"[",
"2",
"]",
"*",
"node",
"{",
"}",
",",
"entry",
":",
"entry",
",",
"parent",
":",
"parent",
",",
"}",
... | // newNode will allocate and initialize a newNode with the provided
// parent and entry. Parent should never be nil, but entry may be
// if constructing an internal node. | [
"newNode",
"will",
"allocate",
"and",
"initialize",
"a",
"newNode",
"with",
"the",
"provided",
"parent",
"and",
"entry",
".",
"Parent",
"should",
"never",
"be",
"nil",
"but",
"entry",
"may",
"be",
"if",
"constructing",
"an",
"internal",
"node",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L131-L137 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | binarySearchHashMaps | func binarySearchHashMaps(layers []map[uint64]*node, key uint64) (int, *node) {
low, high := 0, len(layers)-1
diff := 64 - len(layers)
var mid int
var node *node
for low <= high {
mid = (low + high) / 2
n, ok := layers[mid][key&masks[diff+mid]]
if ok {
node = n
low = mid + 1
} else {
high = mid - ... | go | func binarySearchHashMaps(layers []map[uint64]*node, key uint64) (int, *node) {
low, high := 0, len(layers)-1
diff := 64 - len(layers)
var mid int
var node *node
for low <= high {
mid = (low + high) / 2
n, ok := layers[mid][key&masks[diff+mid]]
if ok {
node = n
low = mid + 1
} else {
high = mid - ... | [
"func",
"binarySearchHashMaps",
"(",
"layers",
"[",
"]",
"map",
"[",
"uint64",
"]",
"*",
"node",
",",
"key",
"uint64",
")",
"(",
"int",
",",
"*",
"node",
")",
"{",
"low",
",",
"high",
":=",
"0",
",",
"len",
"(",
"layers",
")",
"-",
"1",
"\n",
"... | // binarySearchHashMaps will perform a binary search of the provided
// maps to return a node that matches the longest prefix of the provided
// key. This will return nil if a match could not be found, which would
// also return layer 0. Layer information is useful when determining the
// distance from the provided n... | [
"binarySearchHashMaps",
"will",
"perform",
"a",
"binary",
"search",
"of",
"the",
"provided",
"maps",
"to",
"return",
"a",
"node",
"that",
"matches",
"the",
"longest",
"prefix",
"of",
"the",
"provided",
"key",
".",
"This",
"will",
"return",
"nil",
"if",
"a",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L144-L161 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | init | func (xft *XFastTrie) init(intType interface{}) {
bits := uint8(0)
switch intType.(type) {
case uint8:
bits = 8
case uint16:
bits = 16
case uint32:
bits = 32
case uint, uint64:
bits = 64
default:
// we'll panic with a bad value to the constructor.
panic(`Invalid universe size provided.`)
}
xft.lay... | go | func (xft *XFastTrie) init(intType interface{}) {
bits := uint8(0)
switch intType.(type) {
case uint8:
bits = 8
case uint16:
bits = 16
case uint32:
bits = 32
case uint, uint64:
bits = 64
default:
// we'll panic with a bad value to the constructor.
panic(`Invalid universe size provided.`)
}
xft.lay... | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"init",
"(",
"intType",
"interface",
"{",
"}",
")",
"{",
"bits",
":=",
"uint8",
"(",
"0",
")",
"\n",
"switch",
"intType",
".",
"(",
"type",
")",
"{",
"case",
"uint8",
":",
"bits",
"=",
"8",
"\n",
"case",... | // init will initialize the XFastTrie with the provided byte-size.
// I'd prefer generics here, but it is what it is. We expect uints
// here when ints would perform just as well, but the public methods
// on the XFastTrie all expect uint64, so we expect a uint in the
// constructor for consistency's sake. | [
"init",
"will",
"initialize",
"the",
"XFastTrie",
"with",
"the",
"provided",
"byte",
"-",
"size",
".",
"I",
"d",
"prefer",
"generics",
"here",
"but",
"it",
"is",
"what",
"it",
"is",
".",
"We",
"expect",
"uints",
"here",
"when",
"ints",
"would",
"perform"... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L216-L240 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | walkUpSuccessor | func (xft *XFastTrie) walkUpSuccessor(root, node, successor *node) {
n := successor.parent
for n != nil && n != root {
// we don't really want to overwrite existing internal nodes,
// or where the child is a leaf that is the successor
if !isInternal(n.children[0]) && n.children[0] != successor {
n.children[0... | go | func (xft *XFastTrie) walkUpSuccessor(root, node, successor *node) {
n := successor.parent
for n != nil && n != root {
// we don't really want to overwrite existing internal nodes,
// or where the child is a leaf that is the successor
if !isInternal(n.children[0]) && n.children[0] != successor {
n.children[0... | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"walkUpSuccessor",
"(",
"root",
",",
"node",
",",
"successor",
"*",
"node",
")",
"{",
"n",
":=",
"successor",
".",
"parent",
"\n",
"for",
"n",
"!=",
"nil",
"&&",
"n",
"!=",
"root",
"{",
"// we don't really wan... | // walkUpSuccessor will walk up the successor branch setting
// the predecessor where possible. This breaks when a common
// ancestor between successor and node is found, ie, the root. | [
"walkUpSuccessor",
"will",
"walk",
"up",
"the",
"successor",
"branch",
"setting",
"the",
"predecessor",
"where",
"possible",
".",
"This",
"breaks",
"when",
"a",
"common",
"ancestor",
"between",
"successor",
"and",
"node",
"is",
"found",
"ie",
"the",
"root",
".... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L383-L393 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | walkUpPredecessor | func (xft *XFastTrie) walkUpPredecessor(root, node, predecessor *node) {
n := predecessor.parent
for n != nil && n != root {
if !isInternal(n.children[1]) && n.children[1] != predecessor {
n.children[1] = node
}
n = n.parent
}
} | go | func (xft *XFastTrie) walkUpPredecessor(root, node, predecessor *node) {
n := predecessor.parent
for n != nil && n != root {
if !isInternal(n.children[1]) && n.children[1] != predecessor {
n.children[1] = node
}
n = n.parent
}
} | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"walkUpPredecessor",
"(",
"root",
",",
"node",
",",
"predecessor",
"*",
"node",
")",
"{",
"n",
":=",
"predecessor",
".",
"parent",
"\n",
"for",
"n",
"!=",
"nil",
"&&",
"n",
"!=",
"root",
"{",
"if",
"!",
"i... | // walkUpPredecessor will walk up the predecessor branch setting
// the successor where possible. This breaks when a common
// ancestor between predecessor and node is found, ie, the root. | [
"walkUpPredecessor",
"will",
"walk",
"up",
"the",
"predecessor",
"branch",
"setting",
"the",
"successor",
"where",
"possible",
".",
"This",
"breaks",
"when",
"a",
"common",
"ancestor",
"between",
"predecessor",
"and",
"node",
"is",
"found",
"ie",
"the",
"root",
... | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L398-L406 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | walkUpNode | func (xft *XFastTrie) walkUpNode(root, node, predecessor, successor *node) {
n := node.parent
for n != nil && n != root {
if !isInternal(n.children[1]) && n.children[1] != successor && n.children[1] != node {
n.children[1] = successor
}
if !isInternal(n.children[0]) && n.children[0] != predecessor && n.child... | go | func (xft *XFastTrie) walkUpNode(root, node, predecessor, successor *node) {
n := node.parent
for n != nil && n != root {
if !isInternal(n.children[1]) && n.children[1] != successor && n.children[1] != node {
n.children[1] = successor
}
if !isInternal(n.children[0]) && n.children[0] != predecessor && n.child... | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"walkUpNode",
"(",
"root",
",",
"node",
",",
"predecessor",
",",
"successor",
"*",
"node",
")",
"{",
"n",
":=",
"node",
".",
"parent",
"\n",
"for",
"n",
"!=",
"nil",
"&&",
"n",
"!=",
"root",
"{",
"if",
"... | // walkUpNode will walk up the newly created branch and set predecessor
// and successor where possible. If predecessor or successor are nil,
// this will set nil where possible. | [
"walkUpNode",
"will",
"walk",
"up",
"the",
"newly",
"created",
"branch",
"and",
"set",
"predecessor",
"and",
"successor",
"where",
"possible",
".",
"If",
"predecessor",
"or",
"successor",
"are",
"nil",
"this",
"will",
"set",
"nil",
"where",
"possible",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L411-L422 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | predecessor | func (xft *XFastTrie) predecessor(key uint64) *node {
if xft.root == nil || xft.max == nil { // no successor if no nodes
return nil
}
if key >= xft.max.entry.Key() {
return xft.max
}
if key < xft.min.entry.Key() {
return nil
}
n := xft.layers[xft.bits-1][key]
if n != nil {
return n
}
layer, n := b... | go | func (xft *XFastTrie) predecessor(key uint64) *node {
if xft.root == nil || xft.max == nil { // no successor if no nodes
return nil
}
if key >= xft.max.entry.Key() {
return xft.max
}
if key < xft.min.entry.Key() {
return nil
}
n := xft.layers[xft.bits-1][key]
if n != nil {
return n
}
layer, n := b... | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"predecessor",
"(",
"key",
"uint64",
")",
"*",
"node",
"{",
"if",
"xft",
".",
"root",
"==",
"nil",
"||",
"xft",
".",
"max",
"==",
"nil",
"{",
"// no successor if no nodes",
"return",
"nil",
"\n",
"}",
"\n\n",
... | // predecessor will find the node equal to or immediately less
// than the provided key. | [
"predecessor",
"will",
"find",
"the",
"node",
"equal",
"to",
"or",
"immediately",
"less",
"than",
"the",
"provided",
"key",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L510-L539 | train |
Workiva/go-datastructures | trie/xfast/xfast.go | Iter | func (xft *XFastTrie) Iter(key uint64) *Iterator {
return &Iterator{
n: xft.successor(key),
first: true,
}
} | go | func (xft *XFastTrie) Iter(key uint64) *Iterator {
return &Iterator{
n: xft.successor(key),
first: true,
}
} | [
"func",
"(",
"xft",
"*",
"XFastTrie",
")",
"Iter",
"(",
"key",
"uint64",
")",
"*",
"Iterator",
"{",
"return",
"&",
"Iterator",
"{",
"n",
":",
"xft",
".",
"successor",
"(",
"key",
")",
",",
"first",
":",
"true",
",",
"}",
"\n",
"}"
] | // Iter will return an iterator that will iterate over all values
// equal to or immediately greater than the provided key. Iterator
// will iterate successor relationships. | [
"Iter",
"will",
"return",
"an",
"iterator",
"that",
"will",
"iterate",
"over",
"all",
"values",
"equal",
"to",
"or",
"immediately",
"greater",
"than",
"the",
"provided",
"key",
".",
"Iterator",
"will",
"iterate",
"successor",
"relationships",
"."
] | f07cbe3f82ca2fd6e5ab94afce65fe43319f675f | https://github.com/Workiva/go-datastructures/blob/f07cbe3f82ca2fd6e5ab94afce65fe43319f675f/trie/xfast/xfast.go#L601-L606 | train |
tucnak/telebot | api.go | Raw | func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
url := fmt.Sprintf("%s/bot%s/%s", b.URL, b.Token, method)
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(payload); err != nil {
return []byte{}, wrapSystem(err)
}
resp, err := b.client.Post(url, "application/json", &buf)
if e... | go | func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
url := fmt.Sprintf("%s/bot%s/%s", b.URL, b.Token, method)
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(payload); err != nil {
return []byte{}, wrapSystem(err)
}
resp, err := b.client.Post(url, "application/json", &buf)
if e... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Raw",
"(",
"method",
"string",
",",
"payload",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"URL",
",",
"b",... | // Raw lets you call any method of Bot API manually. | [
"Raw",
"lets",
"you",
"call",
"any",
"method",
"of",
"Bot",
"API",
"manually",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/api.go#L21-L41 | train |
tucnak/telebot | message.go | IsForwarded | func (m *Message) IsForwarded() bool {
return m.OriginalSender != nil || m.OriginalChat != nil
} | go | func (m *Message) IsForwarded() bool {
return m.OriginalSender != nil || m.OriginalChat != nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"IsForwarded",
"(",
")",
"bool",
"{",
"return",
"m",
".",
"OriginalSender",
"!=",
"nil",
"||",
"m",
".",
"OriginalChat",
"!=",
"nil",
"\n",
"}"
] | // IsForwarded says whether message is forwarded copy of another
// message or not. | [
"IsForwarded",
"says",
"whether",
"message",
"is",
"forwarded",
"copy",
"of",
"another",
"message",
"or",
"not",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L223-L225 | train |
tucnak/telebot | message.go | FromGroup | func (m *Message) FromGroup() bool {
return m.Chat.Type == ChatGroup || m.Chat.Type == ChatSuperGroup
} | go | func (m *Message) FromGroup() bool {
return m.Chat.Type == ChatGroup || m.Chat.Type == ChatSuperGroup
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"FromGroup",
"(",
")",
"bool",
"{",
"return",
"m",
".",
"Chat",
".",
"Type",
"==",
"ChatGroup",
"||",
"m",
".",
"Chat",
".",
"Type",
"==",
"ChatSuperGroup",
"\n",
"}"
] | // FromGroup returns true, if message came from a group OR
// a super group. | [
"FromGroup",
"returns",
"true",
"if",
"message",
"came",
"from",
"a",
"group",
"OR",
"a",
"super",
"group",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L239-L241 | train |
tucnak/telebot | message.go | IsService | func (m *Message) IsService() bool {
fact := false
fact = fact || m.UserJoined != nil
fact = fact || len(m.UsersJoined) > 0
fact = fact || m.UserLeft != nil
fact = fact || m.NewGroupTitle != ""
fact = fact || m.NewGroupPhoto != nil
fact = fact || m.GroupPhotoDeleted
fact = fact || m.GroupCreated || m.SuperGrou... | go | func (m *Message) IsService() bool {
fact := false
fact = fact || m.UserJoined != nil
fact = fact || len(m.UsersJoined) > 0
fact = fact || m.UserLeft != nil
fact = fact || m.NewGroupTitle != ""
fact = fact || m.NewGroupPhoto != nil
fact = fact || m.GroupPhotoDeleted
fact = fact || m.GroupCreated || m.SuperGrou... | [
"func",
"(",
"m",
"*",
"Message",
")",
"IsService",
"(",
")",
"bool",
"{",
"fact",
":=",
"false",
"\n\n",
"fact",
"=",
"fact",
"||",
"m",
".",
"UserJoined",
"!=",
"nil",
"\n",
"fact",
"=",
"fact",
"||",
"len",
"(",
"m",
".",
"UsersJoined",
")",
"... | // IsService returns true, if message is a service message,
// returns false otherwise.
//
// Service messages are automatically sent messages, which
// typically occur on some global action. For instance, when
// anyone leaves the chat or chat title changes. | [
"IsService",
"returns",
"true",
"if",
"message",
"is",
"a",
"service",
"message",
"returns",
"false",
"otherwise",
".",
"Service",
"messages",
"are",
"automatically",
"sent",
"messages",
"which",
"typically",
"occur",
"on",
"some",
"global",
"action",
".",
"For"... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/message.go#L254-L267 | train |
tucnak/telebot | media.go | UnmarshalJSON | func (p *Photo) UnmarshalJSON(jsonStr []byte) error {
var hq photoSize
if jsonStr[0] == '{' {
if err := json.Unmarshal(jsonStr, &hq); err != nil {
return err
}
} else {
var sizes []photoSize
if err := json.Unmarshal(jsonStr, &sizes); err != nil {
return err
}
hq = sizes[len(sizes)-1]
}
p.File... | go | func (p *Photo) UnmarshalJSON(jsonStr []byte) error {
var hq photoSize
if jsonStr[0] == '{' {
if err := json.Unmarshal(jsonStr, &hq); err != nil {
return err
}
} else {
var sizes []photoSize
if err := json.Unmarshal(jsonStr, &sizes); err != nil {
return err
}
hq = sizes[len(sizes)-1]
}
p.File... | [
"func",
"(",
"p",
"*",
"Photo",
")",
"UnmarshalJSON",
"(",
"jsonStr",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"hq",
"photoSize",
"\n\n",
"if",
"jsonStr",
"[",
"0",
"]",
"==",
"'{'",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"jsonSt... | // UnmarshalJSON is custom unmarshaller required to abstract
// away the hassle of treating different thumbnail sizes.
// Instead, Telebot chooses the hi-res one and just sticks to
// it.
//
// I really do find it a beautiful solution. | [
"UnmarshalJSON",
"is",
"custom",
"unmarshaller",
"required",
"to",
"abstract",
"away",
"the",
"hassle",
"of",
"treating",
"different",
"thumbnail",
"sizes",
".",
"Instead",
"Telebot",
"chooses",
"the",
"hi",
"-",
"res",
"one",
"and",
"just",
"sticks",
"to",
"i... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/media.go#L50-L72 | train |
tucnak/telebot | webhook.go | ServeHTTP | func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var update Update
err := json.NewDecoder(r.Body).Decode(&update)
if err != nil {
h.bot.debug(fmt.Errorf("cannot decode update: %v", err))
return
}
h.dest <- update
} | go | func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var update Update
err := json.NewDecoder(r.Body).Decode(&update)
if err != nil {
h.bot.debug(fmt.Errorf("cannot decode update: %v", err))
return
}
h.dest <- update
} | [
"func",
"(",
"h",
"*",
"Webhook",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"update",
"Update",
"\n",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
... | // The handler simply reads the update from the body of the requests
// and writes them to the update channel. | [
"The",
"handler",
"simply",
"reads",
"the",
"update",
"from",
"the",
"body",
"of",
"the",
"requests",
"and",
"writes",
"them",
"to",
"the",
"update",
"channel",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/webhook.go#L142-L150 | train |
tucnak/telebot | admin.go | AdminRights | func AdminRights() Rights {
return Rights{
true, true, true, true, true, // 1-5
true, true, true, true, true, // 6-10
true, true, true} // 11-13
} | go | func AdminRights() Rights {
return Rights{
true, true, true, true, true, // 1-5
true, true, true, true, true, // 6-10
true, true, true} // 11-13
} | [
"func",
"AdminRights",
"(",
")",
"Rights",
"{",
"return",
"Rights",
"{",
"true",
",",
"true",
",",
"true",
",",
"true",
",",
"true",
",",
"// 1-5",
"true",
",",
"true",
",",
"true",
",",
"true",
",",
"true",
",",
"// 6-10",
"true",
",",
"true",
","... | // AdminRights could be used to promote user to admin. | [
"AdminRights",
"could",
"be",
"used",
"to",
"promote",
"user",
"to",
"admin",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L45-L50 | train |
tucnak/telebot | admin.go | Ban | func (b *Bot) Ban(chat *Chat, member *ChatMember) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(member.RestrictedUntil, 10),
}
respJSON, err := b.Raw("kickChatMember", params)
if err != nil {
return err
}
retur... | go | func (b *Bot) Ban(chat *Chat, member *ChatMember) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(member.RestrictedUntil, 10),
}
respJSON, err := b.Raw("kickChatMember", params)
if err != nil {
return err
}
retur... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Ban",
"(",
"chat",
"*",
"Chat",
",",
"member",
"*",
"ChatMember",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"chat",
".",
"Recipient",
"(",
")",
",",
"\"",
"... | // Ban will ban user from chat until `member.RestrictedUntil`. | [
"Ban",
"will",
"ban",
"user",
"from",
"chat",
"until",
"member",
".",
"RestrictedUntil",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L58-L71 | train |
tucnak/telebot | admin.go | Unban | func (b *Bot) Unban(chat *Chat, user *User) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"user_id": user.Recipient(),
}
respJSON, err := b.Raw("unbanChatMember", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | go | func (b *Bot) Unban(chat *Chat, user *User) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"user_id": user.Recipient(),
}
respJSON, err := b.Raw("unbanChatMember", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Unban",
"(",
"chat",
"*",
"Chat",
",",
"user",
"*",
"User",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"chat",
".",
"Recipient",
"(",
")",
",",
"\"",
"\"",
... | // Unban will unban user from chat, who would have thought eh? | [
"Unban",
"will",
"unban",
"user",
"from",
"chat",
"who",
"would",
"have",
"thought",
"eh?"
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L74-L86 | train |
tucnak/telebot | admin.go | AdminsOf | func (b *Bot) AdminsOf(chat *Chat) ([]ChatMember, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
}
respJSON, err := b.Raw("getChatAdministrators", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Result []ChatMember
Description string `json:"descrip... | go | func (b *Bot) AdminsOf(chat *Chat) ([]ChatMember, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
}
respJSON, err := b.Raw("getChatAdministrators", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Result []ChatMember
Description string `json:"descrip... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"AdminsOf",
"(",
"chat",
"*",
"Chat",
")",
"(",
"[",
"]",
"ChatMember",
",",
"error",
")",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"chat",
".",
"Recipient",
"(",
")",
",... | // AdminsOf return a member list of chat admins.
//
// On success, returns an Array of ChatMember objects that
// contains information about all chat administrators except other bots.
// If the chat is a group or a supergroup and
// no administrators were appointed, only the creator will be returned. | [
"AdminsOf",
"return",
"a",
"member",
"list",
"of",
"chat",
"admins",
".",
"On",
"success",
"returns",
"an",
"Array",
"of",
"ChatMember",
"objects",
"that",
"contains",
"information",
"about",
"all",
"chat",
"administrators",
"except",
"other",
"bots",
".",
"If... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/admin.go#L150-L176 | train |
tucnak/telebot | poller.go | NewMiddlewarePoller | func NewMiddlewarePoller(original Poller, filter func(*Update) bool) *MiddlewarePoller {
return &MiddlewarePoller{
Poller: original,
Filter: filter,
}
} | go | func NewMiddlewarePoller(original Poller, filter func(*Update) bool) *MiddlewarePoller {
return &MiddlewarePoller{
Poller: original,
Filter: filter,
}
} | [
"func",
"NewMiddlewarePoller",
"(",
"original",
"Poller",
",",
"filter",
"func",
"(",
"*",
"Update",
")",
"bool",
")",
"*",
"MiddlewarePoller",
"{",
"return",
"&",
"MiddlewarePoller",
"{",
"Poller",
":",
"original",
",",
"Filter",
":",
"filter",
",",
"}",
... | // NewMiddlewarePoller wait for it... constructs a new middleware poller. | [
"NewMiddlewarePoller",
"wait",
"for",
"it",
"...",
"constructs",
"a",
"new",
"middleware",
"poller",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L41-L46 | train |
tucnak/telebot | poller.go | Poll | func (p *MiddlewarePoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
cap := 1
if p.Capacity > 1 {
cap = p.Capacity
}
middle := make(chan Update, cap)
stopPoller := make(chan struct{})
go p.Poller.Poll(b, middle, stopPoller)
for {
select {
// call to stop
case <-stop:
stopPoller <- struct... | go | func (p *MiddlewarePoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
cap := 1
if p.Capacity > 1 {
cap = p.Capacity
}
middle := make(chan Update, cap)
stopPoller := make(chan struct{})
go p.Poller.Poll(b, middle, stopPoller)
for {
select {
// call to stop
case <-stop:
stopPoller <- struct... | [
"func",
"(",
"p",
"*",
"MiddlewarePoller",
")",
"Poll",
"(",
"b",
"*",
"Bot",
",",
"dest",
"chan",
"Update",
",",
"stop",
"chan",
"struct",
"{",
"}",
")",
"{",
"cap",
":=",
"1",
"\n",
"if",
"p",
".",
"Capacity",
">",
"1",
"{",
"cap",
"=",
"p",
... | // Poll sieves updates through middleware filter. | [
"Poll",
"sieves",
"updates",
"through",
"middleware",
"filter",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L49-L77 | train |
tucnak/telebot | poller.go | Poll | func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
go func(stop chan struct{}) {
<-stop
close(stop)
}(stop)
for {
updates, err := b.getUpdates(p.LastUpdateID+1, p.Timeout)
if err != nil {
b.debug(ErrCouldNotUpdate)
continue
}
for _, update := range updates {
p.LastUpdat... | go | func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
go func(stop chan struct{}) {
<-stop
close(stop)
}(stop)
for {
updates, err := b.getUpdates(p.LastUpdateID+1, p.Timeout)
if err != nil {
b.debug(ErrCouldNotUpdate)
continue
}
for _, update := range updates {
p.LastUpdat... | [
"func",
"(",
"p",
"*",
"LongPoller",
")",
"Poll",
"(",
"b",
"*",
"Bot",
",",
"dest",
"chan",
"Update",
",",
"stop",
"chan",
"struct",
"{",
"}",
")",
"{",
"go",
"func",
"(",
"stop",
"chan",
"struct",
"{",
"}",
")",
"{",
"<-",
"stop",
"\n",
"clos... | // Poll does long polling. | [
"Poll",
"does",
"long",
"polling",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/poller.go#L87-L106 | train |
tucnak/telebot | inline.go | MarshalJSON | func (results Results) MarshalJSON() ([]byte, error) {
for _, result := range results {
if result.ResultID() == "" {
result.SetResultID(fmt.Sprintf("%d", &result))
}
if err := inferIQR(result); err != nil {
return nil, err
}
}
return json.Marshal([]Result(results))
} | go | func (results Results) MarshalJSON() ([]byte, error) {
for _, result := range results {
if result.ResultID() == "" {
result.SetResultID(fmt.Sprintf("%d", &result))
}
if err := inferIQR(result); err != nil {
return nil, err
}
}
return json.Marshal([]Result(results))
} | [
"func",
"(",
"results",
"Results",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"for",
"_",
",",
"result",
":=",
"range",
"results",
"{",
"if",
"result",
".",
"ResultID",
"(",
")",
"==",
"\"",
"\"",
"{",
"result",
... | // MarshalJSON makes sure IQRs have proper IDs and Type variables set. | [
"MarshalJSON",
"makes",
"sure",
"IQRs",
"have",
"proper",
"IDs",
"and",
"Type",
"variables",
"set",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/inline.go#L75-L87 | train |
tucnak/telebot | filters.go | Add | func (c *Chain) Add(filter interface{}) {
switch filter.(type) {
case Filter:
break
case FilterFunc:
break
case func(*Update) bool:
break
default:
panic("telebot: unsupported filter type")
}
c.Filters = append(c.Filters, filter)
} | go | func (c *Chain) Add(filter interface{}) {
switch filter.(type) {
case Filter:
break
case FilterFunc:
break
case func(*Update) bool:
break
default:
panic("telebot: unsupported filter type")
}
c.Filters = append(c.Filters, filter)
} | [
"func",
"(",
"c",
"*",
"Chain",
")",
"Add",
"(",
"filter",
"interface",
"{",
"}",
")",
"{",
"switch",
"filter",
".",
"(",
"type",
")",
"{",
"case",
"Filter",
":",
"break",
"\n",
"case",
"FilterFunc",
":",
"break",
"\n",
"case",
"func",
"(",
"*",
... | // Add accepts either Filter interface or FilterFunc | [
"Add",
"accepts",
"either",
"Filter",
"interface",
"or",
"FilterFunc"
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/filters.go#L53-L66 | train |
tucnak/telebot | bot.go | NewBot | func NewBot(pref Settings) (*Bot, error) {
if pref.Updates == 0 {
pref.Updates = 100
}
client := pref.Client
if client == nil {
client = http.DefaultClient
}
if pref.URL == "" {
pref.URL = DefaultApiURL
}
bot := &Bot{
Token: pref.Token,
URL: pref.URL,
Updates: make(chan Update, pref.Updates... | go | func NewBot(pref Settings) (*Bot, error) {
if pref.Updates == 0 {
pref.Updates = 100
}
client := pref.Client
if client == nil {
client = http.DefaultClient
}
if pref.URL == "" {
pref.URL = DefaultApiURL
}
bot := &Bot{
Token: pref.Token,
URL: pref.URL,
Updates: make(chan Update, pref.Updates... | [
"func",
"NewBot",
"(",
"pref",
"Settings",
")",
"(",
"*",
"Bot",
",",
"error",
")",
"{",
"if",
"pref",
".",
"Updates",
"==",
"0",
"{",
"pref",
".",
"Updates",
"=",
"100",
"\n",
"}",
"\n\n",
"client",
":=",
"pref",
".",
"Client",
"\n",
"if",
"clie... | // NewBot does try to build a Bot with token `token`, which
// is a secret API key assigned to particular bot. | [
"NewBot",
"does",
"try",
"to",
"build",
"a",
"Bot",
"with",
"token",
"token",
"which",
"is",
"a",
"secret",
"API",
"key",
"assigned",
"to",
"particular",
"bot",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L18-L51 | train |
tucnak/telebot | bot.go | EditCaption | func (b *Bot) EditCaption(originalMsg Editable, caption string) (*Message, error) {
messageID, chatID := originalMsg.MessageSig()
params := map[string]string{"caption": caption}
// if inline message
if chatID == 0 {
params["inline_message_id"] = messageID
} else {
params["chat_id"] = strconv.FormatInt(chatID... | go | func (b *Bot) EditCaption(originalMsg Editable, caption string) (*Message, error) {
messageID, chatID := originalMsg.MessageSig()
params := map[string]string{"caption": caption}
// if inline message
if chatID == 0 {
params["inline_message_id"] = messageID
} else {
params["chat_id"] = strconv.FormatInt(chatID... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"EditCaption",
"(",
"originalMsg",
"Editable",
",",
"caption",
"string",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"messageID",
",",
"chatID",
":=",
"originalMsg",
".",
"MessageSig",
"(",
")",
"\n\n",
"params",
... | // EditCaption used to edit already sent photo caption with known recepient and message id.
//
// On success, returns edited message object | [
"EditCaption",
"used",
"to",
"edit",
"already",
"sent",
"photo",
"caption",
"with",
"known",
"recepient",
"and",
"message",
"id",
".",
"On",
"success",
"returns",
"edited",
"message",
"object"
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L718-L737 | train |
tucnak/telebot | bot.go | Notify | func (b *Bot) Notify(recipient Recipient, action ChatAction) error {
params := map[string]string{
"chat_id": recipient.Recipient(),
"action": string(action),
}
respJSON, err := b.Raw("sendChatAction", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | go | func (b *Bot) Notify(recipient Recipient, action ChatAction) error {
params := map[string]string{
"chat_id": recipient.Recipient(),
"action": string(action),
}
respJSON, err := b.Raw("sendChatAction", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Notify",
"(",
"recipient",
"Recipient",
",",
"action",
"ChatAction",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"recipient",
".",
"Recipient",
"(",
")",
",",
"\"",... | // Notify updates the chat action for recipient.
//
// Chat action is a status message that recipient would see where
// you typically see "Harry is typing" status message. The only
// difference is that bots' chat actions live only for 5 seconds
// and die just once the client recieves a message from the bot.
//
// Cu... | [
"Notify",
"updates",
"the",
"chat",
"action",
"for",
"recipient",
".",
"Chat",
"action",
"is",
"a",
"status",
"message",
"that",
"recipient",
"would",
"see",
"where",
"you",
"typically",
"see",
"Harry",
"is",
"typing",
"status",
"message",
".",
"The",
"only"... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L900-L912 | train |
tucnak/telebot | bot.go | Accept | func (b *Bot) Accept(query *PreCheckoutQuery, errorMessage ...string) error {
params := map[string]string{
"pre_checkout_query_id": query.ID,
}
if len(errorMessage) == 0 {
params["ok"] = "True"
} else {
params["ok"] = "False"
params["error_message"] = errorMessage[0]
}
respJSON, err := b.Raw("answerPreC... | go | func (b *Bot) Accept(query *PreCheckoutQuery, errorMessage ...string) error {
params := map[string]string{
"pre_checkout_query_id": query.ID,
}
if len(errorMessage) == 0 {
params["ok"] = "True"
} else {
params["ok"] = "False"
params["error_message"] = errorMessage[0]
}
respJSON, err := b.Raw("answerPreC... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Accept",
"(",
"query",
"*",
"PreCheckoutQuery",
",",
"errorMessage",
"...",
"string",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"query",
".",
"ID",
",",
"}",
"\... | // Accept finalizes the deal. | [
"Accept",
"finalizes",
"the",
"deal",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L915-L933 | train |
tucnak/telebot | bot.go | Answer | func (b *Bot) Answer(query *Query, response *QueryResponse) error {
response.QueryID = query.ID
for _, result := range response.Results {
result.Process()
}
respJSON, err := b.Raw("answerInlineQuery", response)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | go | func (b *Bot) Answer(query *Query, response *QueryResponse) error {
response.QueryID = query.ID
for _, result := range response.Results {
result.Process()
}
respJSON, err := b.Raw("answerInlineQuery", response)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Answer",
"(",
"query",
"*",
"Query",
",",
"response",
"*",
"QueryResponse",
")",
"error",
"{",
"response",
".",
"QueryID",
"=",
"query",
".",
"ID",
"\n\n",
"for",
"_",
",",
"result",
":=",
"range",
"response",
".",... | // Answer sends a response for a given inline query. A query can only
// be responded to once, subsequent attempts to respond to the same query
// will result in an error. | [
"Answer",
"sends",
"a",
"response",
"for",
"a",
"given",
"inline",
"query",
".",
"A",
"query",
"can",
"only",
"be",
"responded",
"to",
"once",
"subsequent",
"attempts",
"to",
"respond",
"to",
"the",
"same",
"query",
"will",
"result",
"in",
"an",
"error",
... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L938-L951 | train |
tucnak/telebot | bot.go | FileByID | func (b *Bot) FileByID(fileID string) (File, error) {
params := map[string]string{
"file_id": fileID,
}
respJSON, err := b.Raw("getFile", params)
if err != nil {
return File{}, err
}
var resp struct {
Ok bool
Description string
Result File
}
err = json.Unmarshal(respJSON, &resp)
if e... | go | func (b *Bot) FileByID(fileID string) (File, error) {
params := map[string]string{
"file_id": fileID,
}
respJSON, err := b.Raw("getFile", params)
if err != nil {
return File{}, err
}
var resp struct {
Ok bool
Description string
Result File
}
err = json.Unmarshal(respJSON, &resp)
if e... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"FileByID",
"(",
"fileID",
"string",
")",
"(",
"File",
",",
"error",
")",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"fileID",
",",
"}",
"\n\n",
"respJSON",
",",
"err",
":=",... | // FileByID returns full file object including File.FilePath, allowing you to
// download the file from the server.
//
// Usually, Telegram-provided File objects miss FilePath so you might need to
// perform an additional request to fetch them. | [
"FileByID",
"returns",
"full",
"file",
"object",
"including",
"File",
".",
"FilePath",
"allowing",
"you",
"to",
"download",
"the",
"file",
"from",
"the",
"server",
".",
"Usually",
"Telegram",
"-",
"provided",
"File",
"objects",
"miss",
"FilePath",
"so",
"you",... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L984-L1011 | train |
tucnak/telebot | bot.go | Download | func (b *Bot) Download(file *File, localFilename string) error {
reader, err := b.GetFile(file)
if err != nil {
return wrapSystem(err)
}
defer reader.Close()
out, err := os.Create(localFilename)
if err != nil {
return wrapSystem(err)
}
defer out.Close()
_, err = io.Copy(out, reader)
if err != nil {
re... | go | func (b *Bot) Download(file *File, localFilename string) error {
reader, err := b.GetFile(file)
if err != nil {
return wrapSystem(err)
}
defer reader.Close()
out, err := os.Create(localFilename)
if err != nil {
return wrapSystem(err)
}
defer out.Close()
_, err = io.Copy(out, reader)
if err != nil {
re... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Download",
"(",
"file",
"*",
"File",
",",
"localFilename",
"string",
")",
"error",
"{",
"reader",
",",
"err",
":=",
"b",
".",
"GetFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"wrapSyste... | // Download saves the file from Telegram servers locally.
//
// Maximum file size to download is 20 MB. | [
"Download",
"saves",
"the",
"file",
"from",
"Telegram",
"servers",
"locally",
".",
"Maximum",
"file",
"size",
"to",
"download",
"is",
"20",
"MB",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1016-L1036 | train |
tucnak/telebot | bot.go | GetFile | func (b *Bot) GetFile(file *File) (io.ReadCloser, error) {
f, err := b.FileByID(file.FileID)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%s/file/bot%s/%s",
b.URL, b.Token, f.FilePath)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
// set FilePath
*file = f
return resp.Body, ni... | go | func (b *Bot) GetFile(file *File) (io.ReadCloser, error) {
f, err := b.FileByID(file.FileID)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%s/file/bot%s/%s",
b.URL, b.Token, f.FilePath)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
// set FilePath
*file = f
return resp.Body, ni... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"GetFile",
"(",
"file",
"*",
"File",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"b",
".",
"FileByID",
"(",
"file",
".",
"FileID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // GetFile from Telegram servers | [
"GetFile",
"from",
"Telegram",
"servers"
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1039-L1056 | train |
tucnak/telebot | bot.go | StopLiveLocation | func (b *Bot) StopLiveLocation(message Editable, options ...interface{}) (*Message, error) {
messageID, chatID := message.MessageSig()
params := map[string]string{
"chat_id": fmt.Sprintf("%d", chatID),
"message_id": messageID,
}
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
resp... | go | func (b *Bot) StopLiveLocation(message Editable, options ...interface{}) (*Message, error) {
messageID, chatID := message.MessageSig()
params := map[string]string{
"chat_id": fmt.Sprintf("%d", chatID),
"message_id": messageID,
}
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
resp... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"StopLiveLocation",
"(",
"message",
"Editable",
",",
"options",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"messageID",
",",
"chatID",
":=",
"message",
".",
"MessageSig",
"(",
")",... | // StopLiveLocation should be called to stop broadcasting live message location
// before Location.LivePeriod expires.
//
// It supports telebot.ReplyMarkup. | [
"StopLiveLocation",
"should",
"be",
"called",
"to",
"stop",
"broadcasting",
"live",
"message",
"location",
"before",
"Location",
".",
"LivePeriod",
"expires",
".",
"It",
"supports",
"telebot",
".",
"ReplyMarkup",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1061-L1078 | train |
tucnak/telebot | bot.go | SetGroupTitle | func (b *Bot) SetGroupTitle(chat *Chat, newTitle string) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"title": newTitle,
}
respJSON, err := b.Raw("setChatTitle", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | go | func (b *Bot) SetGroupTitle(chat *Chat, newTitle string) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"title": newTitle,
}
respJSON, err := b.Raw("setChatTitle", params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"SetGroupTitle",
"(",
"chat",
"*",
"Chat",
",",
"newTitle",
"string",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"chat",
".",
"Recipient",
"(",
")",
",",
"\"",
... | // SetChatTitle should be used to update group title. | [
"SetChatTitle",
"should",
"be",
"used",
"to",
"update",
"group",
"title",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1110-L1122 | train |
tucnak/telebot | bot.go | SetGroupPhoto | func (b *Bot) SetGroupPhoto(chat *Chat, p *Photo) error {
params := map[string]string{
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendFiles("setChatPhoto", map[string]File{"photo": p.File}, params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | go | func (b *Bot) SetGroupPhoto(chat *Chat, p *Photo) error {
params := map[string]string{
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendFiles("setChatPhoto", map[string]File{"photo": p.File}, params)
if err != nil {
return err
}
return extractOkResponse(respJSON)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"SetGroupPhoto",
"(",
"chat",
"*",
"Chat",
",",
"p",
"*",
"Photo",
")",
"error",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"chat",
".",
"Recipient",
"(",
")",
",",
"}",
"\... | // SetGroupPhoto should be used to update group photo. | [
"SetGroupPhoto",
"should",
"be",
"used",
"to",
"update",
"group",
"photo",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1140-L1151 | train |
tucnak/telebot | bot.go | Pin | func (b *Bot) Pin(message Editable, options ...interface{}) error {
messageID, chatID := message.MessageSig()
params := map[string]string{
"chat_id": strconv.FormatInt(chatID, 10),
"message_id": messageID,
}
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.Raw("p... | go | func (b *Bot) Pin(message Editable, options ...interface{}) error {
messageID, chatID := message.MessageSig()
params := map[string]string{
"chat_id": strconv.FormatInt(chatID, 10),
"message_id": messageID,
}
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.Raw("p... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Pin",
"(",
"message",
"Editable",
",",
"options",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"messageID",
",",
"chatID",
":=",
"message",
".",
"MessageSig",
"(",
")",
"\n\n",
"params",
":=",
"map",
"[",
"stri... | // Use this method to pin a message in a supergroup or a channel.
//
// It supports telebot.Silent option. | [
"Use",
"this",
"method",
"to",
"pin",
"a",
"message",
"in",
"a",
"supergroup",
"or",
"a",
"channel",
".",
"It",
"supports",
"telebot",
".",
"Silent",
"option",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1213-L1230 | train |
tucnak/telebot | bot.go | ChatByID | func (b *Bot) ChatByID(id string) (*Chat, error) {
params := map[string]string{
"chat_id": id,
}
respJSON, err := b.Raw("getChat", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Description string
Result *Chat
}
err = json.Unmarshal(respJSON, &resp)
if err != nil... | go | func (b *Bot) ChatByID(id string) (*Chat, error) {
params := map[string]string{
"chat_id": id,
}
respJSON, err := b.Raw("getChat", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Description string
Result *Chat
}
err = json.Unmarshal(respJSON, &resp)
if err != nil... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"ChatByID",
"(",
"id",
"string",
")",
"(",
"*",
"Chat",
",",
"error",
")",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"id",
",",
"}",
"\n\n",
"respJSON",
",",
"err",
":=",
... | // ChatByID fetches chat info of its ID.
//
// Including current name of the user for one-on-one conversations,
// current username of a user, group or channel, etc.
//
// Returns a Chat object on success. | [
"ChatByID",
"fetches",
"chat",
"info",
"of",
"its",
"ID",
".",
"Including",
"current",
"name",
"of",
"the",
"user",
"for",
"one",
"-",
"on",
"-",
"one",
"conversations",
"current",
"username",
"of",
"a",
"user",
"group",
"or",
"channel",
"etc",
".",
"Ret... | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1254-L1285 | train |
tucnak/telebot | bot.go | ProfilePhotosOf | func (b *Bot) ProfilePhotosOf(user *User) ([]Photo, error) {
params := map[string]string{
"user_id": user.Recipient(),
}
respJSON, err := b.Raw("getUserProfilePhotos", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Result struct {
Count int `json:"total_count"`
Photos... | go | func (b *Bot) ProfilePhotosOf(user *User) ([]Photo, error) {
params := map[string]string{
"user_id": user.Recipient(),
}
respJSON, err := b.Raw("getUserProfilePhotos", params)
if err != nil {
return nil, err
}
var resp struct {
Ok bool
Result struct {
Count int `json:"total_count"`
Photos... | [
"func",
"(",
"b",
"*",
"Bot",
")",
"ProfilePhotosOf",
"(",
"user",
"*",
"User",
")",
"(",
"[",
"]",
"Photo",
",",
"error",
")",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"user",
".",
"Recipient",
"(",
")",
... | // ProfilePhotosOf return list of profile pictures for a user. | [
"ProfilePhotosOf",
"return",
"list",
"of",
"profile",
"pictures",
"for",
"a",
"user",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1288-L1318 | train |
tucnak/telebot | bot.go | FileURLByID | func (b *Bot) FileURLByID(fileID string) (string, error) {
f, err := b.FileByID(fileID)
if err != nil {
return "", err
}
return fmt.Sprintf("%s/file/bot%s/%s", b.URL, b.Token, f.FilePath), nil
} | go | func (b *Bot) FileURLByID(fileID string) (string, error) {
f, err := b.FileByID(fileID)
if err != nil {
return "", err
}
return fmt.Sprintf("%s/file/bot%s/%s", b.URL, b.Token, f.FilePath), nil
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"FileURLByID",
"(",
"fileID",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"b",
".",
"FileByID",
"(",
"fileID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"... | // FileURLByID returns direct url for files using FileId which you can get from File object | [
"FileURLByID",
"returns",
"direct",
"url",
"for",
"files",
"using",
"FileId",
"which",
"you",
"can",
"get",
"from",
"File",
"object"
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/bot.go#L1353-L1359 | train |
tucnak/telebot | file.go | OnDisk | func (f *File) OnDisk() bool {
if _, err := os.Stat(f.FileLocal); err != nil {
return false
}
return true
} | go | func (f *File) OnDisk() bool {
if _, err := os.Stat(f.FileLocal); err != nil {
return false
}
return true
} | [
"func",
"(",
"f",
"*",
"File",
")",
"OnDisk",
"(",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"f",
".",
"FileLocal",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
... | // OnDisk will return true if file is present on disk. | [
"OnDisk",
"will",
"return",
"true",
"if",
"file",
"is",
"present",
"on",
"disk",
"."
] | 8c1c512262f2f97b1212eb1751efb498d2038a0c | https://github.com/tucnak/telebot/blob/8c1c512262f2f97b1212eb1751efb498d2038a0c/file.go#L81-L87 | train |
remind101/empire | pkg/constraints/constraints.go | NewCPUShare | func NewCPUShare(i int) (CPUShare, error) {
if i < 2 {
return 0, ErrInvalidCPUShare
}
return CPUShare(i), nil
} | go | func NewCPUShare(i int) (CPUShare, error) {
if i < 2 {
return 0, ErrInvalidCPUShare
}
return CPUShare(i), nil
} | [
"func",
"NewCPUShare",
"(",
"i",
"int",
")",
"(",
"CPUShare",
",",
"error",
")",
"{",
"if",
"i",
"<",
"2",
"{",
"return",
"0",
",",
"ErrInvalidCPUShare",
"\n",
"}",
"\n\n",
"return",
"CPUShare",
"(",
"i",
")",
",",
"nil",
"\n",
"}"
] | // NewCPUShare casts i to a CPUShare and ensures its validity. | [
"NewCPUShare",
"casts",
"i",
"to",
"a",
"CPUShare",
"and",
"ensures",
"its",
"validity",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/constraints/constraints.go#L44-L50 | train |
remind101/empire | pkg/constraints/constraints.go | ParseMemory | func ParseMemory(s string) (Memory, error) {
i, err := parseMemory(s)
return Memory(i), err
} | go | func ParseMemory(s string) (Memory, error) {
i, err := parseMemory(s)
return Memory(i), err
} | [
"func",
"ParseMemory",
"(",
"s",
"string",
")",
"(",
"Memory",
",",
"error",
")",
"{",
"i",
",",
"err",
":=",
"parseMemory",
"(",
"s",
")",
"\n",
"return",
"Memory",
"(",
"i",
")",
",",
"err",
"\n",
"}"
] | // ParseMemory parses a string in memory format and returns the amount of memory
// in bytes. | [
"ParseMemory",
"parses",
"a",
"string",
"in",
"memory",
"format",
"and",
"returns",
"the",
"amount",
"of",
"memory",
"in",
"bytes",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/constraints/constraints.go#L69-L72 | train |
remind101/empire | releases.go | BeforeCreate | func (r *Release) BeforeCreate() error {
t := timex.Now()
r.CreatedAt = &t
return nil
} | go | func (r *Release) BeforeCreate() error {
t := timex.Now()
r.CreatedAt = &t
return nil
} | [
"func",
"(",
"r",
"*",
"Release",
")",
"BeforeCreate",
"(",
")",
"error",
"{",
"t",
":=",
"timex",
".",
"Now",
"(",
")",
"\n",
"r",
".",
"CreatedAt",
"=",
"&",
"t",
"\n",
"return",
"nil",
"\n",
"}"
] | // BeforeCreate sets created_at before inserting. | [
"BeforeCreate",
"sets",
"created_at",
"before",
"inserting",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L61-L65 | train |
remind101/empire | releases.go | DefaultRange | func (q ReleasesQuery) DefaultRange() headerutil.Range {
sort, order := "version", "desc"
return headerutil.Range{
Sort: &sort,
Order: &order,
}
} | go | func (q ReleasesQuery) DefaultRange() headerutil.Range {
sort, order := "version", "desc"
return headerutil.Range{
Sort: &sort,
Order: &order,
}
} | [
"func",
"(",
"q",
"ReleasesQuery",
")",
"DefaultRange",
"(",
")",
"headerutil",
".",
"Range",
"{",
"sort",
",",
"order",
":=",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"return",
"headerutil",
".",
"Range",
"{",
"Sort",
":",
"&",
"sort",
",",
"Order",
":",
... | // DefaultRange returns the default headerutil.Range used if values aren't
// provided. | [
"DefaultRange",
"returns",
"the",
"default",
"headerutil",
".",
"Range",
"used",
"if",
"values",
"aren",
"t",
"provided",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L99-L105 | train |
remind101/empire | releases.go | CreateAndRelease | func (s *releasesService) CreateAndRelease(ctx context.Context, db *gorm.DB, r *Release, ss twelvefactor.StatusStream) (*Release, error) {
r, err := s.Create(ctx, db, r)
if err != nil {
return r, err
}
// Schedule the new release onto the cluster.
return r, s.Release(ctx, r, ss)
} | go | func (s *releasesService) CreateAndRelease(ctx context.Context, db *gorm.DB, r *Release, ss twelvefactor.StatusStream) (*Release, error) {
r, err := s.Create(ctx, db, r)
if err != nil {
return r, err
}
// Schedule the new release onto the cluster.
return r, s.Release(ctx, r, ss)
} | [
"func",
"(",
"s",
"*",
"releasesService",
")",
"CreateAndRelease",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"r",
"*",
"Release",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
")",
"(",
"*",
"Release",
",",
"error... | // CreateAndRelease creates a new release then submits it to the scheduler. | [
"CreateAndRelease",
"creates",
"a",
"new",
"release",
"then",
"submits",
"it",
"to",
"the",
"scheduler",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L113-L120 | train |
remind101/empire | releases.go | Create | func (s *releasesService) Create(ctx context.Context, db *gorm.DB, r *Release) (*Release, error) {
// Lock all releases for the given application to ensure that the
// release version is updated automically.
if err := db.Exec(`select 1 from releases where app_id = ? for update`, r.App.ID).Error; err != nil {
retur... | go | func (s *releasesService) Create(ctx context.Context, db *gorm.DB, r *Release) (*Release, error) {
// Lock all releases for the given application to ensure that the
// release version is updated automically.
if err := db.Exec(`select 1 from releases where app_id = ? for update`, r.App.ID).Error; err != nil {
retur... | [
"func",
"(",
"s",
"*",
"releasesService",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"r",
"*",
"Release",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"// Lock all releases for the given application t... | // Create creates a new release. | [
"Create",
"creates",
"a",
"new",
"release",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L123-L141 | train |
remind101/empire | releases.go | Rollback | func (s *releasesService) Rollback(ctx context.Context, db *gorm.DB, opts RollbackOpts) (*Release, error) {
app, version := opts.App, opts.Version
r, err := releasesFind(db, ReleasesQuery{App: app, Version: &version})
if err != nil {
return nil, err
}
desc := fmt.Sprintf("Rollback to v%d", version)
desc = appe... | go | func (s *releasesService) Rollback(ctx context.Context, db *gorm.DB, opts RollbackOpts) (*Release, error) {
app, version := opts.App, opts.Version
r, err := releasesFind(db, ReleasesQuery{App: app, Version: &version})
if err != nil {
return nil, err
}
desc := fmt.Sprintf("Rollback to v%d", version)
desc = appe... | [
"func",
"(",
"s",
"*",
"releasesService",
")",
"Rollback",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"opts",
"RollbackOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"app",
",",
"version",
":=",
"opts",
... | // Rolls back to a specific release version. | [
"Rolls",
"back",
"to",
"a",
"specific",
"release",
"version",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L144-L160 | 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.