id int32 0 167k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,800 | tylertreat/BoomFilters | cuckoo.go | getEmptyEntry | func (b bucket) getEmptyEntry() (int, error) {
for i, fingerprint := range b {
if fingerprint == nil {
return i, nil
}
}
return -1, errors.New("full")
} | go | func (b bucket) getEmptyEntry() (int, error) {
for i, fingerprint := range b {
if fingerprint == nil {
return i, nil
}
}
return -1, errors.New("full")
} | [
"func",
"(",
"b",
"bucket",
")",
"getEmptyEntry",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"for",
"i",
",",
"fingerprint",
":=",
"range",
"b",
"{",
"if",
"fingerprint",
"==",
"nil",
"{",
"return",
"i",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",... | // getEmptyEntry returns the index of the next available entry in the bucket or
// an error if it's full. | [
"getEmptyEntry",
"returns",
"the",
"index",
"of",
"the",
"next",
"available",
"entry",
"in",
"the",
"bucket",
"or",
"an",
"error",
"if",
"it",
"s",
"full",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L39-L46 |
18,801 | tylertreat/BoomFilters | cuckoo.go | NewCuckooFilter | func NewCuckooFilter(n uint, fpRate float64) *CuckooFilter {
var (
b = uint(4)
f = calculateF(b, fpRate)
m = power2(n / f * 8)
buckets = make([]bucket, m)
)
for i := uint(0); i < m; i++ {
buckets[i] = make(bucket, b)
}
return &CuckooFilter{
buckets: buckets,
hash: fnv.New32(),
m: m,
b: b,
f: f,
n: n,
}
} | go | func NewCuckooFilter(n uint, fpRate float64) *CuckooFilter {
var (
b = uint(4)
f = calculateF(b, fpRate)
m = power2(n / f * 8)
buckets = make([]bucket, m)
)
for i := uint(0); i < m; i++ {
buckets[i] = make(bucket, b)
}
return &CuckooFilter{
buckets: buckets,
hash: fnv.New32(),
m: m,
b: b,
f: f,
n: n,
}
} | [
"func",
"NewCuckooFilter",
"(",
"n",
"uint",
",",
"fpRate",
"float64",
")",
"*",
"CuckooFilter",
"{",
"var",
"(",
"b",
"=",
"uint",
"(",
"4",
")",
"\n",
"f",
"=",
"calculateF",
"(",
"b",
",",
"fpRate",
")",
"\n",
"m",
"=",
"power2",
"(",
"n",
"/"... | // NewCuckooFilter creates a new Cuckoo Bloom filter optimized to store n items
// with a specified target false-positive rate. | [
"NewCuckooFilter",
"creates",
"a",
"new",
"Cuckoo",
"Bloom",
"filter",
"optimized",
"to",
"store",
"n",
"items",
"with",
"a",
"specified",
"target",
"false",
"-",
"positive",
"rate",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L75-L95 |
18,802 | tylertreat/BoomFilters | cuckoo.go | Add | func (c *CuckooFilter) Add(data []byte) error {
return c.add(c.components(data))
} | go | func (c *CuckooFilter) Add(data []byte) error {
return c.add(c.components(data))
} | [
"func",
"(",
"c",
"*",
"CuckooFilter",
")",
"Add",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"c",
".",
"add",
"(",
"c",
".",
"components",
"(",
"data",
")",
")",
"\n",
"}"
] | // Add will add the data to the Cuckoo Filter. It returns an error if the
// filter is full. If the filter is full, an item is removed to make room for
// the new item. This introduces a possibility for false negatives. To avoid
// this, use Count and Capacity to check if the filter is full before adding an
// item. | [
"Add",
"will",
"add",
"the",
"data",
"to",
"the",
"Cuckoo",
"Filter",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"filter",
"is",
"full",
".",
"If",
"the",
"filter",
"is",
"full",
"an",
"item",
"is",
"removed",
"to",
"make",
"room",
"for",
"the... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L127-L129 |
18,803 | tylertreat/BoomFilters | cuckoo.go | add | func (c *CuckooFilter) add(i1, i2 uint, f []byte) error {
// Try to insert into bucket[i1].
b1 := c.buckets[i1%c.m]
if idx, err := b1.getEmptyEntry(); err == nil {
b1[idx] = f
c.count++
return nil
}
// Try to insert into bucket[i2].
b2 := c.buckets[i2%c.m]
if idx, err := b2.getEmptyEntry(); err == nil {
b2[idx] = f
c.count++
return nil
}
// Must relocate existing items.
i := i1
for n := 0; n < maxNumKicks; n++ {
bucketIdx := i % c.m
entryIdx := rand.Intn(int(c.b))
f, c.buckets[bucketIdx][entryIdx] = c.buckets[bucketIdx][entryIdx], f
i = i ^ uint(binary.BigEndian.Uint32(c.computeHash(f)))
b := c.buckets[i%c.m]
if idx, err := b.getEmptyEntry(); err == nil {
b[idx] = f
c.count++
return nil
}
}
return errors.New("full")
} | go | func (c *CuckooFilter) add(i1, i2 uint, f []byte) error {
// Try to insert into bucket[i1].
b1 := c.buckets[i1%c.m]
if idx, err := b1.getEmptyEntry(); err == nil {
b1[idx] = f
c.count++
return nil
}
// Try to insert into bucket[i2].
b2 := c.buckets[i2%c.m]
if idx, err := b2.getEmptyEntry(); err == nil {
b2[idx] = f
c.count++
return nil
}
// Must relocate existing items.
i := i1
for n := 0; n < maxNumKicks; n++ {
bucketIdx := i % c.m
entryIdx := rand.Intn(int(c.b))
f, c.buckets[bucketIdx][entryIdx] = c.buckets[bucketIdx][entryIdx], f
i = i ^ uint(binary.BigEndian.Uint32(c.computeHash(f)))
b := c.buckets[i%c.m]
if idx, err := b.getEmptyEntry(); err == nil {
b[idx] = f
c.count++
return nil
}
}
return errors.New("full")
} | [
"func",
"(",
"c",
"*",
"CuckooFilter",
")",
"add",
"(",
"i1",
",",
"i2",
"uint",
",",
"f",
"[",
"]",
"byte",
")",
"error",
"{",
"// Try to insert into bucket[i1].",
"b1",
":=",
"c",
".",
"buckets",
"[",
"i1",
"%",
"c",
".",
"m",
"]",
"\n",
"if",
... | // add will insert the fingerprint into the filter returning an error if the
// filter is full. | [
"add",
"will",
"insert",
"the",
"fingerprint",
"into",
"the",
"filter",
"returning",
"an",
"error",
"if",
"the",
"filter",
"is",
"full",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L185-L218 |
18,804 | tylertreat/BoomFilters | cuckoo.go | components | func (c *CuckooFilter) components(data []byte) (uint, uint, []byte) {
var (
hash = c.computeHash(data)
f = hash[0:c.f]
i1 = uint(binary.BigEndian.Uint32(hash))
i2 = i1 ^ uint(binary.BigEndian.Uint32(c.computeHash(f)))
)
return i1, i2, f
} | go | func (c *CuckooFilter) components(data []byte) (uint, uint, []byte) {
var (
hash = c.computeHash(data)
f = hash[0:c.f]
i1 = uint(binary.BigEndian.Uint32(hash))
i2 = i1 ^ uint(binary.BigEndian.Uint32(c.computeHash(f)))
)
return i1, i2, f
} | [
"func",
"(",
"c",
"*",
"CuckooFilter",
")",
"components",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"uint",
",",
"uint",
",",
"[",
"]",
"byte",
")",
"{",
"var",
"(",
"hash",
"=",
"c",
".",
"computeHash",
"(",
"data",
")",
"\n",
"f",
"=",
"hash",... | // components returns the two hash values used to index into the buckets and
// the fingerprint for the given element. | [
"components",
"returns",
"the",
"two",
"hash",
"values",
"used",
"to",
"index",
"into",
"the",
"buckets",
"and",
"the",
"fingerprint",
"for",
"the",
"given",
"element",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L222-L231 |
18,805 | tylertreat/BoomFilters | cuckoo.go | computeHash | func (c *CuckooFilter) computeHash(data []byte) []byte {
c.hash.Write(data)
hash := c.hash.Sum(nil)
c.hash.Reset()
return hash
} | go | func (c *CuckooFilter) computeHash(data []byte) []byte {
c.hash.Write(data)
hash := c.hash.Sum(nil)
c.hash.Reset()
return hash
} | [
"func",
"(",
"c",
"*",
"CuckooFilter",
")",
"computeHash",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"c",
".",
"hash",
".",
"Write",
"(",
"data",
")",
"\n",
"hash",
":=",
"c",
".",
"hash",
".",
"Sum",
"(",
"nil",
")",
"\n",
"... | // computeHash returns a 32-bit hash value for the given data. | [
"computeHash",
"returns",
"a",
"32",
"-",
"bit",
"hash",
"value",
"for",
"the",
"given",
"data",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L234-L239 |
18,806 | tylertreat/BoomFilters | cuckoo.go | calculateF | func calculateF(b uint, epsilon float64) uint {
f := uint(math.Ceil(math.Log(2 * float64(b) / epsilon)))
f = f / 8
if f <= 0 {
f = 1
}
return f
} | go | func calculateF(b uint, epsilon float64) uint {
f := uint(math.Ceil(math.Log(2 * float64(b) / epsilon)))
f = f / 8
if f <= 0 {
f = 1
}
return f
} | [
"func",
"calculateF",
"(",
"b",
"uint",
",",
"epsilon",
"float64",
")",
"uint",
"{",
"f",
":=",
"uint",
"(",
"math",
".",
"Ceil",
"(",
"math",
".",
"Log",
"(",
"2",
"*",
"float64",
"(",
"b",
")",
"/",
"epsilon",
")",
")",
")",
"\n",
"f",
"=",
... | // calculateF returns the optimal fingerprint length in bytes for the given
// bucket size and false-positive rate epsilon. | [
"calculateF",
"returns",
"the",
"optimal",
"fingerprint",
"length",
"in",
"bytes",
"for",
"the",
"given",
"bucket",
"size",
"and",
"false",
"-",
"positive",
"rate",
"epsilon",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L249-L256 |
18,807 | tylertreat/BoomFilters | cuckoo.go | power2 | func power2(x uint) uint {
x--
x |= x >> 1
x |= x >> 2
x |= x >> 4
x |= x >> 8
x |= x >> 16
x |= x >> 32
x++
return x
} | go | func power2(x uint) uint {
x--
x |= x >> 1
x |= x >> 2
x |= x >> 4
x |= x >> 8
x |= x >> 16
x |= x >> 32
x++
return x
} | [
"func",
"power2",
"(",
"x",
"uint",
")",
"uint",
"{",
"x",
"--",
"\n",
"x",
"|=",
"x",
">>",
"1",
"\n",
"x",
"|=",
"x",
">>",
"2",
"\n",
"x",
"|=",
"x",
">>",
"4",
"\n",
"x",
"|=",
"x",
">>",
"8",
"\n",
"x",
"|=",
"x",
">>",
"16",
"\n",... | // power2 calculates the next power of two for the given value. | [
"power2",
"calculates",
"the",
"next",
"power",
"of",
"two",
"for",
"the",
"given",
"value",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/cuckoo.go#L259-L269 |
18,808 | tylertreat/BoomFilters | topk.go | NewTopK | func NewTopK(epsilon, delta float64, k uint) *TopK {
elements := make(elementHeap, 0, k)
heap.Init(&elements)
return &TopK{
cms: NewCountMinSketch(epsilon, delta),
k: k,
elements: &elements,
}
} | go | func NewTopK(epsilon, delta float64, k uint) *TopK {
elements := make(elementHeap, 0, k)
heap.Init(&elements)
return &TopK{
cms: NewCountMinSketch(epsilon, delta),
k: k,
elements: &elements,
}
} | [
"func",
"NewTopK",
"(",
"epsilon",
",",
"delta",
"float64",
",",
"k",
"uint",
")",
"*",
"TopK",
"{",
"elements",
":=",
"make",
"(",
"elementHeap",
",",
"0",
",",
"k",
")",
"\n",
"heap",
".",
"Init",
"(",
"&",
"elements",
")",
"\n",
"return",
"&",
... | // NewTopK creates a new TopK backed by a Count-Min sketch whose relative
// accuracy is within a factor of epsilon with probability delta. It tracks the
// k-most frequent elements. | [
"NewTopK",
"creates",
"a",
"new",
"TopK",
"backed",
"by",
"a",
"Count",
"-",
"Min",
"sketch",
"whose",
"relative",
"accuracy",
"is",
"within",
"a",
"factor",
"of",
"epsilon",
"with",
"probability",
"delta",
".",
"It",
"tracks",
"the",
"k",
"-",
"most",
"... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L45-L53 |
18,809 | tylertreat/BoomFilters | topk.go | Add | func (t *TopK) Add(data []byte) *TopK {
t.cms.Add(data)
t.n++
freq := t.cms.Count(data)
if t.isTop(freq) {
t.insert(data, freq)
}
return t
} | go | func (t *TopK) Add(data []byte) *TopK {
t.cms.Add(data)
t.n++
freq := t.cms.Count(data)
if t.isTop(freq) {
t.insert(data, freq)
}
return t
} | [
"func",
"(",
"t",
"*",
"TopK",
")",
"Add",
"(",
"data",
"[",
"]",
"byte",
")",
"*",
"TopK",
"{",
"t",
".",
"cms",
".",
"Add",
"(",
"data",
")",
"\n",
"t",
".",
"n",
"++",
"\n\n",
"freq",
":=",
"t",
".",
"cms",
".",
"Count",
"(",
"data",
"... | // Add will add the data to the Count-Min Sketch and update the top-k heap if
// applicable. Returns the TopK to allow for chaining. | [
"Add",
"will",
"add",
"the",
"data",
"to",
"the",
"Count",
"-",
"Min",
"Sketch",
"and",
"update",
"the",
"top",
"-",
"k",
"heap",
"if",
"applicable",
".",
"Returns",
"the",
"TopK",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L57-L67 |
18,810 | tylertreat/BoomFilters | topk.go | Elements | func (t *TopK) Elements() []*Element {
if t.elements.Len() == 0 {
return make([]*Element, 0)
}
elements := make(elementHeap, t.elements.Len())
copy(elements, *t.elements)
heap.Init(&elements)
topK := make([]*Element, 0, t.k)
for elements.Len() > 0 {
topK = append(topK, heap.Pop(&elements).(*Element))
}
return topK
} | go | func (t *TopK) Elements() []*Element {
if t.elements.Len() == 0 {
return make([]*Element, 0)
}
elements := make(elementHeap, t.elements.Len())
copy(elements, *t.elements)
heap.Init(&elements)
topK := make([]*Element, 0, t.k)
for elements.Len() > 0 {
topK = append(topK, heap.Pop(&elements).(*Element))
}
return topK
} | [
"func",
"(",
"t",
"*",
"TopK",
")",
"Elements",
"(",
")",
"[",
"]",
"*",
"Element",
"{",
"if",
"t",
".",
"elements",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"make",
"(",
"[",
"]",
"*",
"Element",
",",
"0",
")",
"\n",
"}",
"\n\n",
"e... | // Elements returns the top-k elements from lowest to highest frequency. | [
"Elements",
"returns",
"the",
"top",
"-",
"k",
"elements",
"from",
"lowest",
"to",
"highest",
"frequency",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L70-L85 |
18,811 | tylertreat/BoomFilters | topk.go | Reset | func (t *TopK) Reset() *TopK {
t.cms.Reset()
elements := make(elementHeap, 0, t.k)
heap.Init(&elements)
t.elements = &elements
t.n = 0
return t
} | go | func (t *TopK) Reset() *TopK {
t.cms.Reset()
elements := make(elementHeap, 0, t.k)
heap.Init(&elements)
t.elements = &elements
t.n = 0
return t
} | [
"func",
"(",
"t",
"*",
"TopK",
")",
"Reset",
"(",
")",
"*",
"TopK",
"{",
"t",
".",
"cms",
".",
"Reset",
"(",
")",
"\n",
"elements",
":=",
"make",
"(",
"elementHeap",
",",
"0",
",",
"t",
".",
"k",
")",
"\n",
"heap",
".",
"Init",
"(",
"&",
"e... | // Reset restores the TopK to its original state. It returns itself to allow
// for chaining. | [
"Reset",
"restores",
"the",
"TopK",
"to",
"its",
"original",
"state",
".",
"It",
"returns",
"itself",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L89-L96 |
18,812 | tylertreat/BoomFilters | topk.go | isTop | func (t *TopK) isTop(freq uint64) bool {
if t.elements.Len() < int(t.k) {
return true
}
return freq >= (*t.elements)[0].Freq
} | go | func (t *TopK) isTop(freq uint64) bool {
if t.elements.Len() < int(t.k) {
return true
}
return freq >= (*t.elements)[0].Freq
} | [
"func",
"(",
"t",
"*",
"TopK",
")",
"isTop",
"(",
"freq",
"uint64",
")",
"bool",
"{",
"if",
"t",
".",
"elements",
".",
"Len",
"(",
")",
"<",
"int",
"(",
"t",
".",
"k",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"freq",
">=",
"("... | // isTop indicates if the given frequency falls within the top-k heap. | [
"isTop",
"indicates",
"if",
"the",
"given",
"frequency",
"falls",
"within",
"the",
"top",
"-",
"k",
"heap",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L99-L105 |
18,813 | tylertreat/BoomFilters | topk.go | insert | func (t *TopK) insert(data []byte, freq uint64) {
for i, element := range *t.elements {
if bytes.Equal(data, element.Data) {
// Element already in top-k, replace it with new frequency.
heap.Remove(t.elements, i)
element.Freq = freq
heap.Push(t.elements, element)
return
}
}
if t.elements.Len() == int(t.k) {
// Remove minimum-frequency element.
heap.Pop(t.elements)
}
// Add element to top-k.
heap.Push(t.elements, &Element{Data: data, Freq: freq})
} | go | func (t *TopK) insert(data []byte, freq uint64) {
for i, element := range *t.elements {
if bytes.Equal(data, element.Data) {
// Element already in top-k, replace it with new frequency.
heap.Remove(t.elements, i)
element.Freq = freq
heap.Push(t.elements, element)
return
}
}
if t.elements.Len() == int(t.k) {
// Remove minimum-frequency element.
heap.Pop(t.elements)
}
// Add element to top-k.
heap.Push(t.elements, &Element{Data: data, Freq: freq})
} | [
"func",
"(",
"t",
"*",
"TopK",
")",
"insert",
"(",
"data",
"[",
"]",
"byte",
",",
"freq",
"uint64",
")",
"{",
"for",
"i",
",",
"element",
":=",
"range",
"*",
"t",
".",
"elements",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"data",
",",
"element",
"... | // insert adds the data to the top-k heap. If the data is already an element,
// the frequency is updated. If the heap already has k elements, the element
// with the minimum frequency is removed. | [
"insert",
"adds",
"the",
"data",
"to",
"the",
"top",
"-",
"k",
"heap",
".",
"If",
"the",
"data",
"is",
"already",
"an",
"element",
"the",
"frequency",
"is",
"updated",
".",
"If",
"the",
"heap",
"already",
"has",
"k",
"elements",
"the",
"element",
"with... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/topk.go#L110-L128 |
18,814 | tylertreat/BoomFilters | buckets.go | NewBuckets | func NewBuckets(count uint, bucketSize uint8) *Buckets {
return &Buckets{
count: count,
data: make([]byte, (count*uint(bucketSize)+7)/8),
bucketSize: bucketSize,
max: (1 << bucketSize) - 1,
}
} | go | func NewBuckets(count uint, bucketSize uint8) *Buckets {
return &Buckets{
count: count,
data: make([]byte, (count*uint(bucketSize)+7)/8),
bucketSize: bucketSize,
max: (1 << bucketSize) - 1,
}
} | [
"func",
"NewBuckets",
"(",
"count",
"uint",
",",
"bucketSize",
"uint8",
")",
"*",
"Buckets",
"{",
"return",
"&",
"Buckets",
"{",
"count",
":",
"count",
",",
"data",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"(",
"count",
"*",
"uint",
"(",
"bucketSize"... | // NewBuckets creates a new Buckets with the provided number of buckets where
// each bucket is the specified number of bits. | [
"NewBuckets",
"creates",
"a",
"new",
"Buckets",
"with",
"the",
"provided",
"number",
"of",
"buckets",
"where",
"each",
"bucket",
"is",
"the",
"specified",
"number",
"of",
"bits",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L20-L27 |
18,815 | tylertreat/BoomFilters | buckets.go | Increment | func (b *Buckets) Increment(bucket uint, delta int32) *Buckets {
val := int32(b.getBits(bucket*uint(b.bucketSize), uint(b.bucketSize))) + delta
if val > int32(b.max) {
val = int32(b.max)
} else if val < 0 {
val = 0
}
b.setBits(uint32(bucket)*uint32(b.bucketSize), uint32(b.bucketSize), uint32(val))
return b
} | go | func (b *Buckets) Increment(bucket uint, delta int32) *Buckets {
val := int32(b.getBits(bucket*uint(b.bucketSize), uint(b.bucketSize))) + delta
if val > int32(b.max) {
val = int32(b.max)
} else if val < 0 {
val = 0
}
b.setBits(uint32(bucket)*uint32(b.bucketSize), uint32(b.bucketSize), uint32(val))
return b
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"Increment",
"(",
"bucket",
"uint",
",",
"delta",
"int32",
")",
"*",
"Buckets",
"{",
"val",
":=",
"int32",
"(",
"b",
".",
"getBits",
"(",
"bucket",
"*",
"uint",
"(",
"b",
".",
"bucketSize",
")",
",",
"uint",
... | // Increment will increment the value in the specified bucket by the provided
// delta. A bucket can be decremented by providing a negative delta. The value
// is clamped to zero and the maximum bucket value. Returns itself to allow for
// chaining. | [
"Increment",
"will",
"increment",
"the",
"value",
"in",
"the",
"specified",
"bucket",
"by",
"the",
"provided",
"delta",
".",
"A",
"bucket",
"can",
"be",
"decremented",
"by",
"providing",
"a",
"negative",
"delta",
".",
"The",
"value",
"is",
"clamped",
"to",
... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L43-L53 |
18,816 | tylertreat/BoomFilters | buckets.go | Set | func (b *Buckets) Set(bucket uint, value uint8) *Buckets {
if value > b.max {
value = b.max
}
b.setBits(uint32(bucket)*uint32(b.bucketSize), uint32(b.bucketSize), uint32(value))
return b
} | go | func (b *Buckets) Set(bucket uint, value uint8) *Buckets {
if value > b.max {
value = b.max
}
b.setBits(uint32(bucket)*uint32(b.bucketSize), uint32(b.bucketSize), uint32(value))
return b
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"Set",
"(",
"bucket",
"uint",
",",
"value",
"uint8",
")",
"*",
"Buckets",
"{",
"if",
"value",
">",
"b",
".",
"max",
"{",
"value",
"=",
"b",
".",
"max",
"\n",
"}",
"\n\n",
"b",
".",
"setBits",
"(",
"uint32"... | // Set will set the bucket value. The value is clamped to zero and the maximum
// bucket value. Returns itself to allow for chaining. | [
"Set",
"will",
"set",
"the",
"bucket",
"value",
".",
"The",
"value",
"is",
"clamped",
"to",
"zero",
"and",
"the",
"maximum",
"bucket",
"value",
".",
"Returns",
"itself",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L57-L64 |
18,817 | tylertreat/BoomFilters | buckets.go | Get | func (b *Buckets) Get(bucket uint) uint32 {
return b.getBits(bucket*uint(b.bucketSize), uint(b.bucketSize))
} | go | func (b *Buckets) Get(bucket uint) uint32 {
return b.getBits(bucket*uint(b.bucketSize), uint(b.bucketSize))
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"Get",
"(",
"bucket",
"uint",
")",
"uint32",
"{",
"return",
"b",
".",
"getBits",
"(",
"bucket",
"*",
"uint",
"(",
"b",
".",
"bucketSize",
")",
",",
"uint",
"(",
"b",
".",
"bucketSize",
")",
")",
"\n",
"}"
] | // Get returns the value in the specified bucket. | [
"Get",
"returns",
"the",
"value",
"in",
"the",
"specified",
"bucket",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L67-L69 |
18,818 | tylertreat/BoomFilters | buckets.go | Reset | func (b *Buckets) Reset() *Buckets {
b.data = make([]byte, (b.count*uint(b.bucketSize)+7)/8)
return b
} | go | func (b *Buckets) Reset() *Buckets {
b.data = make([]byte, (b.count*uint(b.bucketSize)+7)/8)
return b
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"Reset",
"(",
")",
"*",
"Buckets",
"{",
"b",
".",
"data",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"(",
"b",
".",
"count",
"*",
"uint",
"(",
"b",
".",
"bucketSize",
")",
"+",
"7",
")",
"/",
"8",
")",
... | // Reset restores the Buckets to the original state. Returns itself to allow
// for chaining. | [
"Reset",
"restores",
"the",
"Buckets",
"to",
"the",
"original",
"state",
".",
"Returns",
"itself",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L73-L76 |
18,819 | tylertreat/BoomFilters | buckets.go | getBits | func (b *Buckets) getBits(offset, length uint) uint32 {
byteIndex := offset / 8
byteOffset := offset % 8
if byteOffset+length > 8 {
rem := 8 - byteOffset
return b.getBits(offset, rem) | (b.getBits(offset+rem, length-rem) << rem)
}
bitMask := uint32((1 << length) - 1)
return (uint32(b.data[byteIndex]) & (bitMask << byteOffset)) >> byteOffset
} | go | func (b *Buckets) getBits(offset, length uint) uint32 {
byteIndex := offset / 8
byteOffset := offset % 8
if byteOffset+length > 8 {
rem := 8 - byteOffset
return b.getBits(offset, rem) | (b.getBits(offset+rem, length-rem) << rem)
}
bitMask := uint32((1 << length) - 1)
return (uint32(b.data[byteIndex]) & (bitMask << byteOffset)) >> byteOffset
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"getBits",
"(",
"offset",
",",
"length",
"uint",
")",
"uint32",
"{",
"byteIndex",
":=",
"offset",
"/",
"8",
"\n",
"byteOffset",
":=",
"offset",
"%",
"8",
"\n",
"if",
"byteOffset",
"+",
"length",
">",
"8",
"{",
... | // getBits returns the bits at the specified offset and length. | [
"getBits",
"returns",
"the",
"bits",
"at",
"the",
"specified",
"offset",
"and",
"length",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L79-L88 |
18,820 | tylertreat/BoomFilters | buckets.go | setBits | func (b *Buckets) setBits(offset, length, bits uint32) {
byteIndex := offset / 8
byteOffset := offset % 8
if byteOffset+length > 8 {
rem := 8 - byteOffset
b.setBits(offset, rem, bits)
b.setBits(offset+rem, length-rem, bits>>rem)
return
}
bitMask := uint32((1 << length) - 1)
b.data[byteIndex] = byte(uint32(b.data[byteIndex]) & ^(bitMask << byteOffset))
b.data[byteIndex] = byte(uint32(b.data[byteIndex]) | ((bits & bitMask) << byteOffset))
} | go | func (b *Buckets) setBits(offset, length, bits uint32) {
byteIndex := offset / 8
byteOffset := offset % 8
if byteOffset+length > 8 {
rem := 8 - byteOffset
b.setBits(offset, rem, bits)
b.setBits(offset+rem, length-rem, bits>>rem)
return
}
bitMask := uint32((1 << length) - 1)
b.data[byteIndex] = byte(uint32(b.data[byteIndex]) & ^(bitMask << byteOffset))
b.data[byteIndex] = byte(uint32(b.data[byteIndex]) | ((bits & bitMask) << byteOffset))
} | [
"func",
"(",
"b",
"*",
"Buckets",
")",
"setBits",
"(",
"offset",
",",
"length",
",",
"bits",
"uint32",
")",
"{",
"byteIndex",
":=",
"offset",
"/",
"8",
"\n",
"byteOffset",
":=",
"offset",
"%",
"8",
"\n",
"if",
"byteOffset",
"+",
"length",
">",
"8",
... | // setBits sets bits at the specified offset and length. | [
"setBits",
"sets",
"bits",
"at",
"the",
"specified",
"offset",
"and",
"length",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/buckets.go#L91-L103 |
18,821 | tylertreat/BoomFilters | stable.go | NewStableBloomFilter | func NewStableBloomFilter(m uint, d uint8, fpRate float64) *StableBloomFilter {
k := OptimalK(fpRate) / 2
if k > m {
k = m
} else if k <= 0 {
k = 1
}
cells := NewBuckets(m, d)
return &StableBloomFilter{
hash: fnv.New64(),
m: m,
k: k,
p: optimalStableP(m, k, d, fpRate),
max: cells.MaxBucketValue(),
cells: cells,
indexBuffer: make([]uint, k),
}
} | go | func NewStableBloomFilter(m uint, d uint8, fpRate float64) *StableBloomFilter {
k := OptimalK(fpRate) / 2
if k > m {
k = m
} else if k <= 0 {
k = 1
}
cells := NewBuckets(m, d)
return &StableBloomFilter{
hash: fnv.New64(),
m: m,
k: k,
p: optimalStableP(m, k, d, fpRate),
max: cells.MaxBucketValue(),
cells: cells,
indexBuffer: make([]uint, k),
}
} | [
"func",
"NewStableBloomFilter",
"(",
"m",
"uint",
",",
"d",
"uint8",
",",
"fpRate",
"float64",
")",
"*",
"StableBloomFilter",
"{",
"k",
":=",
"OptimalK",
"(",
"fpRate",
")",
"/",
"2",
"\n",
"if",
"k",
">",
"m",
"{",
"k",
"=",
"m",
"\n",
"}",
"else"... | // NewStableBloomFilter creates a new Stable Bloom Filter with m cells and d
// bits allocated per cell optimized for the target false-positive rate. Use
// NewDefaultStableFilter if you don't want to calculate d. | [
"NewStableBloomFilter",
"creates",
"a",
"new",
"Stable",
"Bloom",
"Filter",
"with",
"m",
"cells",
"and",
"d",
"bits",
"allocated",
"per",
"cell",
"optimized",
"for",
"the",
"target",
"false",
"-",
"positive",
"rate",
".",
"Use",
"NewDefaultStableFilter",
"if",
... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L49-L68 |
18,822 | tylertreat/BoomFilters | stable.go | NewUnstableBloomFilter | func NewUnstableBloomFilter(m uint, fpRate float64) *StableBloomFilter {
var (
cells = NewBuckets(m, 1)
k = OptimalK(fpRate)
)
return &StableBloomFilter{
hash: fnv.New64(),
m: m,
k: k,
p: 0,
max: cells.MaxBucketValue(),
cells: cells,
indexBuffer: make([]uint, k),
}
} | go | func NewUnstableBloomFilter(m uint, fpRate float64) *StableBloomFilter {
var (
cells = NewBuckets(m, 1)
k = OptimalK(fpRate)
)
return &StableBloomFilter{
hash: fnv.New64(),
m: m,
k: k,
p: 0,
max: cells.MaxBucketValue(),
cells: cells,
indexBuffer: make([]uint, k),
}
} | [
"func",
"NewUnstableBloomFilter",
"(",
"m",
"uint",
",",
"fpRate",
"float64",
")",
"*",
"StableBloomFilter",
"{",
"var",
"(",
"cells",
"=",
"NewBuckets",
"(",
"m",
",",
"1",
")",
"\n",
"k",
"=",
"OptimalK",
"(",
"fpRate",
")",
"\n",
")",
"\n\n",
"retur... | // NewUnstableBloomFilter creates a new special case of Stable Bloom Filter
// which is a traditional Bloom filter with m bits and an optimal number of
// hash functions for the target false-positive rate. Unlike the stable
// variant, data is not evicted and a cell contains a maximum of 1 hash value. | [
"NewUnstableBloomFilter",
"creates",
"a",
"new",
"special",
"case",
"of",
"Stable",
"Bloom",
"Filter",
"which",
"is",
"a",
"traditional",
"Bloom",
"filter",
"with",
"m",
"bits",
"and",
"an",
"optimal",
"number",
"of",
"hash",
"functions",
"for",
"the",
"target... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L82-L97 |
18,823 | tylertreat/BoomFilters | stable.go | StablePoint | func (s *StableBloomFilter) StablePoint() float64 {
var (
subDenom = float64(s.p) * (1/float64(s.k) - 1/float64(s.m))
denom = 1 + 1/subDenom
base = 1 / denom
)
return math.Pow(base, float64(s.max))
} | go | func (s *StableBloomFilter) StablePoint() float64 {
var (
subDenom = float64(s.p) * (1/float64(s.k) - 1/float64(s.m))
denom = 1 + 1/subDenom
base = 1 / denom
)
return math.Pow(base, float64(s.max))
} | [
"func",
"(",
"s",
"*",
"StableBloomFilter",
")",
"StablePoint",
"(",
")",
"float64",
"{",
"var",
"(",
"subDenom",
"=",
"float64",
"(",
"s",
".",
"p",
")",
"*",
"(",
"1",
"/",
"float64",
"(",
"s",
".",
"k",
")",
"-",
"1",
"/",
"float64",
"(",
"s... | // StablePoint returns the limit of the expected fraction of zeros in the
// Stable Bloom Filter when the number of iterations goes to infinity. When
// this limit is reached, the Stable Bloom Filter is considered stable. | [
"StablePoint",
"returns",
"the",
"limit",
"of",
"the",
"expected",
"fraction",
"of",
"zeros",
"in",
"the",
"Stable",
"Bloom",
"Filter",
"when",
"the",
"number",
"of",
"iterations",
"goes",
"to",
"infinity",
".",
"When",
"this",
"limit",
"is",
"reached",
"the... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L117-L125 |
18,824 | tylertreat/BoomFilters | stable.go | FalsePositiveRate | func (s *StableBloomFilter) FalsePositiveRate() float64 {
return math.Pow(1-s.StablePoint(), float64(s.k))
} | go | func (s *StableBloomFilter) FalsePositiveRate() float64 {
return math.Pow(1-s.StablePoint(), float64(s.k))
} | [
"func",
"(",
"s",
"*",
"StableBloomFilter",
")",
"FalsePositiveRate",
"(",
")",
"float64",
"{",
"return",
"math",
".",
"Pow",
"(",
"1",
"-",
"s",
".",
"StablePoint",
"(",
")",
",",
"float64",
"(",
"s",
".",
"k",
")",
")",
"\n",
"}"
] | // FalsePositiveRate returns the upper bound on false positives when the filter
// has become stable. | [
"FalsePositiveRate",
"returns",
"the",
"upper",
"bound",
"on",
"false",
"positives",
"when",
"the",
"filter",
"has",
"become",
"stable",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L129-L131 |
18,825 | tylertreat/BoomFilters | stable.go | Add | func (s *StableBloomFilter) Add(data []byte) Filter {
// Randomly decrement p cells to make room for new elements.
s.decrement()
lower, upper := hashKernel(data, s.hash)
// Set the K cells to max.
for i := uint(0); i < s.k; i++ {
s.cells.Set((uint(lower)+uint(upper)*i)%s.m, s.max)
}
return s
} | go | func (s *StableBloomFilter) Add(data []byte) Filter {
// Randomly decrement p cells to make room for new elements.
s.decrement()
lower, upper := hashKernel(data, s.hash)
// Set the K cells to max.
for i := uint(0); i < s.k; i++ {
s.cells.Set((uint(lower)+uint(upper)*i)%s.m, s.max)
}
return s
} | [
"func",
"(",
"s",
"*",
"StableBloomFilter",
")",
"Add",
"(",
"data",
"[",
"]",
"byte",
")",
"Filter",
"{",
"// Randomly decrement p cells to make room for new elements.",
"s",
".",
"decrement",
"(",
")",
"\n\n",
"lower",
",",
"upper",
":=",
"hashKernel",
"(",
... | // Add will add the data to the Stable Bloom Filter. It returns the filter to
// allow for chaining. | [
"Add",
"will",
"add",
"the",
"data",
"to",
"the",
"Stable",
"Bloom",
"Filter",
".",
"It",
"returns",
"the",
"filter",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L151-L163 |
18,826 | tylertreat/BoomFilters | stable.go | optimalStableP | func optimalStableP(m, k uint, d uint8, fpRate float64) uint {
var (
max = math.Pow(2, float64(d)) - 1
subDenom = math.Pow(1-math.Pow(fpRate, 1/float64(k)), 1/max)
denom = (1/subDenom - 1) * (1/float64(k) - 1/float64(m))
)
p := uint(1 / denom)
if p <= 0 {
p = 1
}
return p
} | go | func optimalStableP(m, k uint, d uint8, fpRate float64) uint {
var (
max = math.Pow(2, float64(d)) - 1
subDenom = math.Pow(1-math.Pow(fpRate, 1/float64(k)), 1/max)
denom = (1/subDenom - 1) * (1/float64(k) - 1/float64(m))
)
p := uint(1 / denom)
if p <= 0 {
p = 1
}
return p
} | [
"func",
"optimalStableP",
"(",
"m",
",",
"k",
"uint",
",",
"d",
"uint8",
",",
"fpRate",
"float64",
")",
"uint",
"{",
"var",
"(",
"max",
"=",
"math",
".",
"Pow",
"(",
"2",
",",
"float64",
"(",
"d",
")",
")",
"-",
"1",
"\n",
"subDenom",
"=",
"mat... | // optimalStableP returns the optimal number of cells to decrement, p, per
// iteration for the provided parameters of an SBF. | [
"optimalStableP",
"returns",
"the",
"optimal",
"number",
"of",
"cells",
"to",
"decrement",
"p",
"per",
"iteration",
"for",
"the",
"provided",
"parameters",
"of",
"an",
"SBF",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/stable.go#L320-L333 |
18,827 | tylertreat/BoomFilters | scalable.go | NewScalableBloomFilter | func NewScalableBloomFilter(hint uint, fpRate, r float64) *ScalableBloomFilter {
s := &ScalableBloomFilter{
filters: make([]*PartitionedBloomFilter, 0, 1),
r: r,
fp: fpRate,
p: fillRatio,
hint: hint,
}
s.addFilter()
return s
} | go | func NewScalableBloomFilter(hint uint, fpRate, r float64) *ScalableBloomFilter {
s := &ScalableBloomFilter{
filters: make([]*PartitionedBloomFilter, 0, 1),
r: r,
fp: fpRate,
p: fillRatio,
hint: hint,
}
s.addFilter()
return s
} | [
"func",
"NewScalableBloomFilter",
"(",
"hint",
"uint",
",",
"fpRate",
",",
"r",
"float64",
")",
"*",
"ScalableBloomFilter",
"{",
"s",
":=",
"&",
"ScalableBloomFilter",
"{",
"filters",
":",
"make",
"(",
"[",
"]",
"*",
"PartitionedBloomFilter",
",",
"0",
",",
... | // NewScalableBloomFilter creates a new Scalable Bloom Filter with the
// specified target false-positive rate and tightening ratio. Use
// NewDefaultScalableBloomFilter if you don't want to calculate these
// parameters. | [
"NewScalableBloomFilter",
"creates",
"a",
"new",
"Scalable",
"Bloom",
"Filter",
"with",
"the",
"specified",
"target",
"false",
"-",
"positive",
"rate",
"and",
"tightening",
"ratio",
".",
"Use",
"NewDefaultScalableBloomFilter",
"if",
"you",
"don",
"t",
"want",
"to"... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/scalable.go#L54-L65 |
18,828 | tylertreat/BoomFilters | scalable.go | Capacity | func (s *ScalableBloomFilter) Capacity() uint {
capacity := uint(0)
for _, bf := range s.filters {
capacity += bf.Capacity()
}
return capacity
} | go | func (s *ScalableBloomFilter) Capacity() uint {
capacity := uint(0)
for _, bf := range s.filters {
capacity += bf.Capacity()
}
return capacity
} | [
"func",
"(",
"s",
"*",
"ScalableBloomFilter",
")",
"Capacity",
"(",
")",
"uint",
"{",
"capacity",
":=",
"uint",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"bf",
":=",
"range",
"s",
".",
"filters",
"{",
"capacity",
"+=",
"bf",
".",
"Capacity",
"(",
")",
... | // Capacity returns the current Scalable Bloom Filter capacity, which is the
// sum of the capacities for the contained series of Bloom filters. | [
"Capacity",
"returns",
"the",
"current",
"Scalable",
"Bloom",
"Filter",
"capacity",
"which",
"is",
"the",
"sum",
"of",
"the",
"capacities",
"for",
"the",
"contained",
"series",
"of",
"Bloom",
"filters",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/scalable.go#L75-L81 |
18,829 | tylertreat/BoomFilters | scalable.go | FillRatio | func (s *ScalableBloomFilter) FillRatio() float64 {
sum := 0.0
for _, filter := range s.filters {
sum += filter.FillRatio()
}
return sum / float64(len(s.filters))
} | go | func (s *ScalableBloomFilter) FillRatio() float64 {
sum := 0.0
for _, filter := range s.filters {
sum += filter.FillRatio()
}
return sum / float64(len(s.filters))
} | [
"func",
"(",
"s",
"*",
"ScalableBloomFilter",
")",
"FillRatio",
"(",
")",
"float64",
"{",
"sum",
":=",
"0.0",
"\n",
"for",
"_",
",",
"filter",
":=",
"range",
"s",
".",
"filters",
"{",
"sum",
"+=",
"filter",
".",
"FillRatio",
"(",
")",
"\n",
"}",
"\... | // FillRatio returns the average ratio of set bits across every filter. | [
"FillRatio",
"returns",
"the",
"average",
"ratio",
"of",
"set",
"bits",
"across",
"every",
"filter",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/scalable.go#L90-L96 |
18,830 | tylertreat/BoomFilters | scalable.go | addFilter | func (s *ScalableBloomFilter) addFilter() {
fpRate := s.fp * math.Pow(s.r, float64(len(s.filters)))
p := NewPartitionedBloomFilter(s.hint, fpRate)
if len(s.filters) > 0 {
p.SetHash(s.filters[0].hash)
}
s.filters = append(s.filters, p)
} | go | func (s *ScalableBloomFilter) addFilter() {
fpRate := s.fp * math.Pow(s.r, float64(len(s.filters)))
p := NewPartitionedBloomFilter(s.hint, fpRate)
if len(s.filters) > 0 {
p.SetHash(s.filters[0].hash)
}
s.filters = append(s.filters, p)
} | [
"func",
"(",
"s",
"*",
"ScalableBloomFilter",
")",
"addFilter",
"(",
")",
"{",
"fpRate",
":=",
"s",
".",
"fp",
"*",
"math",
".",
"Pow",
"(",
"s",
".",
"r",
",",
"float64",
"(",
"len",
"(",
"s",
".",
"filters",
")",
")",
")",
"\n",
"p",
":=",
... | // addFilter adds a new Bloom filter with a restricted false-positive rate to
// the Scalable Bloom Filter | [
"addFilter",
"adds",
"a",
"new",
"Bloom",
"filter",
"with",
"a",
"restricted",
"false",
"-",
"positive",
"rate",
"to",
"the",
"Scalable",
"Bloom",
"Filter"
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/scalable.go#L146-L153 |
18,831 | tylertreat/BoomFilters | hyperloglog.go | NewHyperLogLog | func NewHyperLogLog(m uint) (*HyperLogLog, error) {
if (m & (m - 1)) != 0 {
return nil, errors.New("m must be a power of two")
}
return &HyperLogLog{
registers: make([]uint8, m),
m: m,
b: uint32(math.Ceil(math.Log2(float64(m)))),
alpha: calculateAlpha(m),
hash: fnv.New32(),
}, nil
} | go | func NewHyperLogLog(m uint) (*HyperLogLog, error) {
if (m & (m - 1)) != 0 {
return nil, errors.New("m must be a power of two")
}
return &HyperLogLog{
registers: make([]uint8, m),
m: m,
b: uint32(math.Ceil(math.Log2(float64(m)))),
alpha: calculateAlpha(m),
hash: fnv.New32(),
}, nil
} | [
"func",
"NewHyperLogLog",
"(",
"m",
"uint",
")",
"(",
"*",
"HyperLogLog",
",",
"error",
")",
"{",
"if",
"(",
"m",
"&",
"(",
"m",
"-",
"1",
")",
")",
"!=",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
... | // NewHyperLogLog creates a new HyperLogLog with m registers. Returns an error
// if m isn't a power of two. | [
"NewHyperLogLog",
"creates",
"a",
"new",
"HyperLogLog",
"with",
"m",
"registers",
".",
"Returns",
"an",
"error",
"if",
"m",
"isn",
"t",
"a",
"power",
"of",
"two",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L61-L73 |
18,832 | tylertreat/BoomFilters | hyperloglog.go | NewDefaultHyperLogLog | func NewDefaultHyperLogLog(e float64) (*HyperLogLog, error) {
m := math.Pow(1.04/e, 2)
return NewHyperLogLog(uint(math.Pow(2, math.Ceil(math.Log2(m)))))
} | go | func NewDefaultHyperLogLog(e float64) (*HyperLogLog, error) {
m := math.Pow(1.04/e, 2)
return NewHyperLogLog(uint(math.Pow(2, math.Ceil(math.Log2(m)))))
} | [
"func",
"NewDefaultHyperLogLog",
"(",
"e",
"float64",
")",
"(",
"*",
"HyperLogLog",
",",
"error",
")",
"{",
"m",
":=",
"math",
".",
"Pow",
"(",
"1.04",
"/",
"e",
",",
"2",
")",
"\n",
"return",
"NewHyperLogLog",
"(",
"uint",
"(",
"math",
".",
"Pow",
... | // NewDefaultHyperLogLog creates a new HyperLogLog optimized for the specified
// standard error. Returns an error if the number of registers can't be
// calculated for the provided accuracy. | [
"NewDefaultHyperLogLog",
"creates",
"a",
"new",
"HyperLogLog",
"optimized",
"for",
"the",
"specified",
"standard",
"error",
".",
"Returns",
"an",
"error",
"if",
"the",
"number",
"of",
"registers",
"can",
"t",
"be",
"calculated",
"for",
"the",
"provided",
"accura... | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L78-L81 |
18,833 | tylertreat/BoomFilters | hyperloglog.go | Add | func (h *HyperLogLog) Add(data []byte) *HyperLogLog {
var (
hash = h.calculateHash(data)
k = 32 - h.b
r = calculateRho(hash<<h.b, k)
j = hash >> uint(k)
)
if r > h.registers[j] {
h.registers[j] = r
}
return h
} | go | func (h *HyperLogLog) Add(data []byte) *HyperLogLog {
var (
hash = h.calculateHash(data)
k = 32 - h.b
r = calculateRho(hash<<h.b, k)
j = hash >> uint(k)
)
if r > h.registers[j] {
h.registers[j] = r
}
return h
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"Add",
"(",
"data",
"[",
"]",
"byte",
")",
"*",
"HyperLogLog",
"{",
"var",
"(",
"hash",
"=",
"h",
".",
"calculateHash",
"(",
"data",
")",
"\n",
"k",
"=",
"32",
"-",
"h",
".",
"b",
"\n",
"r",
"=",
"ca... | // Add will add the data to the set. Returns the HyperLogLog to allow for
// chaining. | [
"Add",
"will",
"add",
"the",
"data",
"to",
"the",
"set",
".",
"Returns",
"the",
"HyperLogLog",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L85-L98 |
18,834 | tylertreat/BoomFilters | hyperloglog.go | Count | func (h *HyperLogLog) Count() uint64 {
sum := 0.0
m := float64(h.m)
for _, val := range h.registers {
sum += 1.0 / math.Pow(2.0, float64(val))
}
estimate := h.alpha * m * m / sum
if estimate <= 5.0/2.0*m {
// Small range correction
v := 0
for _, r := range h.registers {
if r == 0 {
v++
}
}
if v > 0 {
estimate = m * math.Log(m/float64(v))
}
} else if estimate > 1.0/30.0*exp32 {
// Large range correction
estimate = -exp32 * math.Log(1-estimate/exp32)
}
return uint64(estimate)
} | go | func (h *HyperLogLog) Count() uint64 {
sum := 0.0
m := float64(h.m)
for _, val := range h.registers {
sum += 1.0 / math.Pow(2.0, float64(val))
}
estimate := h.alpha * m * m / sum
if estimate <= 5.0/2.0*m {
// Small range correction
v := 0
for _, r := range h.registers {
if r == 0 {
v++
}
}
if v > 0 {
estimate = m * math.Log(m/float64(v))
}
} else if estimate > 1.0/30.0*exp32 {
// Large range correction
estimate = -exp32 * math.Log(1-estimate/exp32)
}
return uint64(estimate)
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"Count",
"(",
")",
"uint64",
"{",
"sum",
":=",
"0.0",
"\n",
"m",
":=",
"float64",
"(",
"h",
".",
"m",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"h",
".",
"registers",
"{",
"sum",
"+=",
"1.0",
... | // Count returns the approximated cardinality of the set. | [
"Count",
"returns",
"the",
"approximated",
"cardinality",
"of",
"the",
"set",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L101-L124 |
18,835 | tylertreat/BoomFilters | hyperloglog.go | Merge | func (h *HyperLogLog) Merge(other *HyperLogLog) error {
if h.m != other.m {
return errors.New("number of registers must match")
}
for j, r := range other.registers {
if r > h.registers[j] {
h.registers[j] = r
}
}
return nil
} | go | func (h *HyperLogLog) Merge(other *HyperLogLog) error {
if h.m != other.m {
return errors.New("number of registers must match")
}
for j, r := range other.registers {
if r > h.registers[j] {
h.registers[j] = r
}
}
return nil
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"Merge",
"(",
"other",
"*",
"HyperLogLog",
")",
"error",
"{",
"if",
"h",
".",
"m",
"!=",
"other",
".",
"m",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"j",
","... | // Merge combines this HyperLogLog with another. Returns an error if the number
// of registers in the two HyperLogLogs are not equal. | [
"Merge",
"combines",
"this",
"HyperLogLog",
"with",
"another",
".",
"Returns",
"an",
"error",
"if",
"the",
"number",
"of",
"registers",
"in",
"the",
"two",
"HyperLogLogs",
"are",
"not",
"equal",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L128-L140 |
18,836 | tylertreat/BoomFilters | hyperloglog.go | Reset | func (h *HyperLogLog) Reset() *HyperLogLog {
h.registers = make([]uint8, h.m)
return h
} | go | func (h *HyperLogLog) Reset() *HyperLogLog {
h.registers = make([]uint8, h.m)
return h
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"Reset",
"(",
")",
"*",
"HyperLogLog",
"{",
"h",
".",
"registers",
"=",
"make",
"(",
"[",
"]",
"uint8",
",",
"h",
".",
"m",
")",
"\n",
"return",
"h",
"\n",
"}"
] | // Reset restores the HyperLogLog to its original state. It returns itself to
// allow for chaining. | [
"Reset",
"restores",
"the",
"HyperLogLog",
"to",
"its",
"original",
"state",
".",
"It",
"returns",
"itself",
"to",
"allow",
"for",
"chaining",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L144-L147 |
18,837 | tylertreat/BoomFilters | hyperloglog.go | calculateHash | func (h *HyperLogLog) calculateHash(data []byte) uint32 {
h.hash.Write(data)
sum := h.hash.Sum32()
h.hash.Reset()
return sum
} | go | func (h *HyperLogLog) calculateHash(data []byte) uint32 {
h.hash.Write(data)
sum := h.hash.Sum32()
h.hash.Reset()
return sum
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"calculateHash",
"(",
"data",
"[",
"]",
"byte",
")",
"uint32",
"{",
"h",
".",
"hash",
".",
"Write",
"(",
"data",
")",
"\n",
"sum",
":=",
"h",
".",
"hash",
".",
"Sum32",
"(",
")",
"\n",
"h",
".",
"hash"... | // calculateHash calculates the 32-bit hash value for the provided data. | [
"calculateHash",
"calculates",
"the",
"32",
"-",
"bit",
"hash",
"value",
"for",
"the",
"provided",
"data",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L150-L155 |
18,838 | tylertreat/BoomFilters | hyperloglog.go | calculateAlpha | func calculateAlpha(m uint) (result float64) {
switch m {
case 16:
result = 0.673
case 32:
result = 0.697
case 64:
result = 0.709
default:
result = 0.7213 / (1.0 + 1.079/float64(m))
}
return result
} | go | func calculateAlpha(m uint) (result float64) {
switch m {
case 16:
result = 0.673
case 32:
result = 0.697
case 64:
result = 0.709
default:
result = 0.7213 / (1.0 + 1.079/float64(m))
}
return result
} | [
"func",
"calculateAlpha",
"(",
"m",
"uint",
")",
"(",
"result",
"float64",
")",
"{",
"switch",
"m",
"{",
"case",
"16",
":",
"result",
"=",
"0.673",
"\n",
"case",
"32",
":",
"result",
"=",
"0.697",
"\n",
"case",
"64",
":",
"result",
"=",
"0.709",
"\... | // calculateAlpha calculates the bias-correction constant alpha based on the
// number of registers, m. | [
"calculateAlpha",
"calculates",
"the",
"bias",
"-",
"correction",
"constant",
"alpha",
"based",
"on",
"the",
"number",
"of",
"registers",
"m",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L164-L176 |
18,839 | tylertreat/BoomFilters | hyperloglog.go | calculateRho | func calculateRho(val, max uint32) uint8 {
r := uint32(1)
for val&0x80000000 == 0 && r <= max {
r++
val <<= 1
}
return uint8(r)
} | go | func calculateRho(val, max uint32) uint8 {
r := uint32(1)
for val&0x80000000 == 0 && r <= max {
r++
val <<= 1
}
return uint8(r)
} | [
"func",
"calculateRho",
"(",
"val",
",",
"max",
"uint32",
")",
"uint8",
"{",
"r",
":=",
"uint32",
"(",
"1",
")",
"\n",
"for",
"val",
"&",
"0x80000000",
"==",
"0",
"&&",
"r",
"<=",
"max",
"{",
"r",
"++",
"\n",
"val",
"<<=",
"1",
"\n",
"}",
"\n",... | // calculateRho calculates the position of the leftmost 1-bit. | [
"calculateRho",
"calculates",
"the",
"position",
"of",
"the",
"leftmost",
"1",
"-",
"bit",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L179-L186 |
18,840 | tylertreat/BoomFilters | hyperloglog.go | WriteDataTo | func (h *HyperLogLog) WriteDataTo(stream io.Writer) (n int, err error) {
buf := new(bytes.Buffer)
// write register number first
err = binary.Write(buf, binary.LittleEndian, uint64(h.m))
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.b)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.alpha)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.registers)
if err != nil {
return
}
n, err = stream.Write(buf.Bytes())
return
} | go | func (h *HyperLogLog) WriteDataTo(stream io.Writer) (n int, err error) {
buf := new(bytes.Buffer)
// write register number first
err = binary.Write(buf, binary.LittleEndian, uint64(h.m))
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.b)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.alpha)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, h.registers)
if err != nil {
return
}
n, err = stream.Write(buf.Bytes())
return
} | [
"func",
"(",
"h",
"*",
"HyperLogLog",
")",
"WriteDataTo",
"(",
"stream",
"io",
".",
"Writer",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"// write register number first",
"err",
"=",... | // WriteDataTo writes a binary representation of the Hll data to
// an io stream. It returns the number of bytes written and error | [
"WriteDataTo",
"writes",
"a",
"binary",
"representation",
"of",
"the",
"Hll",
"data",
"to",
"an",
"io",
"stream",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"error"
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/hyperloglog.go#L190-L215 |
18,841 | tylertreat/BoomFilters | boom.go | OptimalM | func OptimalM(n uint, fpRate float64) uint {
return uint(math.Ceil(float64(n) / ((math.Log(fillRatio) *
math.Log(1-fillRatio)) / math.Abs(math.Log(fpRate)))))
} | go | func OptimalM(n uint, fpRate float64) uint {
return uint(math.Ceil(float64(n) / ((math.Log(fillRatio) *
math.Log(1-fillRatio)) / math.Abs(math.Log(fpRate)))))
} | [
"func",
"OptimalM",
"(",
"n",
"uint",
",",
"fpRate",
"float64",
")",
"uint",
"{",
"return",
"uint",
"(",
"math",
".",
"Ceil",
"(",
"float64",
"(",
"n",
")",
"/",
"(",
"(",
"math",
".",
"Log",
"(",
"fillRatio",
")",
"*",
"math",
".",
"Log",
"(",
... | // OptimalM calculates the optimal Bloom filter size, m, based on the number of
// items and the desired rate of false positives. | [
"OptimalM",
"calculates",
"the",
"optimal",
"Bloom",
"filter",
"size",
"m",
"based",
"on",
"the",
"number",
"of",
"items",
"and",
"the",
"desired",
"rate",
"of",
"false",
"positives",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/boom.go#L65-L68 |
18,842 | tylertreat/BoomFilters | boom.go | OptimalK | func OptimalK(fpRate float64) uint {
return uint(math.Ceil(math.Log2(1 / fpRate)))
} | go | func OptimalK(fpRate float64) uint {
return uint(math.Ceil(math.Log2(1 / fpRate)))
} | [
"func",
"OptimalK",
"(",
"fpRate",
"float64",
")",
"uint",
"{",
"return",
"uint",
"(",
"math",
".",
"Ceil",
"(",
"math",
".",
"Log2",
"(",
"1",
"/",
"fpRate",
")",
")",
")",
"\n",
"}"
] | // OptimalK calculates the optimal number of hash functions to use for a Bloom
// filter based on the desired rate of false positives. | [
"OptimalK",
"calculates",
"the",
"optimal",
"number",
"of",
"hash",
"functions",
"to",
"use",
"for",
"a",
"Bloom",
"filter",
"based",
"on",
"the",
"desired",
"rate",
"of",
"false",
"positives",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/boom.go#L72-L74 |
18,843 | tylertreat/BoomFilters | boom.go | hashKernel | func hashKernel(data []byte, hash hash.Hash64) (uint32, uint32) {
hash.Write(data)
sum := hash.Sum(nil)
hash.Reset()
return binary.BigEndian.Uint32(sum[4:8]), binary.BigEndian.Uint32(sum[0:4])
} | go | func hashKernel(data []byte, hash hash.Hash64) (uint32, uint32) {
hash.Write(data)
sum := hash.Sum(nil)
hash.Reset()
return binary.BigEndian.Uint32(sum[4:8]), binary.BigEndian.Uint32(sum[0:4])
} | [
"func",
"hashKernel",
"(",
"data",
"[",
"]",
"byte",
",",
"hash",
"hash",
".",
"Hash64",
")",
"(",
"uint32",
",",
"uint32",
")",
"{",
"hash",
".",
"Write",
"(",
"data",
")",
"\n",
"sum",
":=",
"hash",
".",
"Sum",
"(",
"nil",
")",
"\n",
"hash",
... | // hashKernel returns the upper and lower base hash values from which the k
// hashes are derived. | [
"hashKernel",
"returns",
"the",
"upper",
"and",
"lower",
"base",
"hash",
"values",
"from",
"which",
"the",
"k",
"hashes",
"are",
"derived",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/boom.go#L78-L83 |
18,844 | tylertreat/BoomFilters | partitioned.go | NewPartitionedBloomFilter | func NewPartitionedBloomFilter(n uint, fpRate float64) *PartitionedBloomFilter {
var (
m = OptimalM(n, fpRate)
k = OptimalK(fpRate)
partitions = make([]*Buckets, k)
s = uint(math.Ceil(float64(m) / float64(k)))
)
for i := uint(0); i < k; i++ {
partitions[i] = NewBuckets(s, 1)
}
return &PartitionedBloomFilter{
partitions: partitions,
hash: fnv.New64(),
m: m,
k: k,
s: s,
}
} | go | func NewPartitionedBloomFilter(n uint, fpRate float64) *PartitionedBloomFilter {
var (
m = OptimalM(n, fpRate)
k = OptimalK(fpRate)
partitions = make([]*Buckets, k)
s = uint(math.Ceil(float64(m) / float64(k)))
)
for i := uint(0); i < k; i++ {
partitions[i] = NewBuckets(s, 1)
}
return &PartitionedBloomFilter{
partitions: partitions,
hash: fnv.New64(),
m: m,
k: k,
s: s,
}
} | [
"func",
"NewPartitionedBloomFilter",
"(",
"n",
"uint",
",",
"fpRate",
"float64",
")",
"*",
"PartitionedBloomFilter",
"{",
"var",
"(",
"m",
"=",
"OptimalM",
"(",
"n",
",",
"fpRate",
")",
"\n",
"k",
"=",
"OptimalK",
"(",
"fpRate",
")",
"\n",
"partitions",
... | // NewPartitionedBloomFilter creates a new partitioned Bloom filter optimized
// to store n items with a specified target false-positive rate. | [
"NewPartitionedBloomFilter",
"creates",
"a",
"new",
"partitioned",
"Bloom",
"filter",
"optimized",
"to",
"store",
"n",
"items",
"with",
"a",
"specified",
"target",
"false",
"-",
"positive",
"rate",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/partitioned.go#L48-L67 |
18,845 | tylertreat/BoomFilters | partitioned.go | FillRatio | func (p *PartitionedBloomFilter) FillRatio() float64 {
t := float64(0)
for i := uint(0); i < p.k; i++ {
sum := uint32(0)
for j := uint(0); j < p.partitions[i].Count(); j++ {
sum += p.partitions[i].Get(j)
}
t += (float64(sum) / float64(p.s))
}
return t / float64(p.k)
} | go | func (p *PartitionedBloomFilter) FillRatio() float64 {
t := float64(0)
for i := uint(0); i < p.k; i++ {
sum := uint32(0)
for j := uint(0); j < p.partitions[i].Count(); j++ {
sum += p.partitions[i].Get(j)
}
t += (float64(sum) / float64(p.s))
}
return t / float64(p.k)
} | [
"func",
"(",
"p",
"*",
"PartitionedBloomFilter",
")",
"FillRatio",
"(",
")",
"float64",
"{",
"t",
":=",
"float64",
"(",
"0",
")",
"\n",
"for",
"i",
":=",
"uint",
"(",
"0",
")",
";",
"i",
"<",
"p",
".",
"k",
";",
"i",
"++",
"{",
"sum",
":=",
"... | // FillRatio returns the average ratio of set bits across all partitions. | [
"FillRatio",
"returns",
"the",
"average",
"ratio",
"of",
"set",
"bits",
"across",
"all",
"partitions",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/partitioned.go#L90-L100 |
18,846 | tylertreat/BoomFilters | classic.go | NewBloomFilter | func NewBloomFilter(n uint, fpRate float64) *BloomFilter {
m := OptimalM(n, fpRate)
return &BloomFilter{
buckets: NewBuckets(m, 1),
hash: fnv.New64(),
m: m,
k: OptimalK(fpRate),
}
} | go | func NewBloomFilter(n uint, fpRate float64) *BloomFilter {
m := OptimalM(n, fpRate)
return &BloomFilter{
buckets: NewBuckets(m, 1),
hash: fnv.New64(),
m: m,
k: OptimalK(fpRate),
}
} | [
"func",
"NewBloomFilter",
"(",
"n",
"uint",
",",
"fpRate",
"float64",
")",
"*",
"BloomFilter",
"{",
"m",
":=",
"OptimalM",
"(",
"n",
",",
"fpRate",
")",
"\n",
"return",
"&",
"BloomFilter",
"{",
"buckets",
":",
"NewBuckets",
"(",
"m",
",",
"1",
")",
"... | // NewBloomFilter creates a new Bloom filter optimized to store n items with a
// specified target false-positive rate. | [
"NewBloomFilter",
"creates",
"a",
"new",
"Bloom",
"filter",
"optimized",
"to",
"store",
"n",
"items",
"with",
"a",
"specified",
"target",
"false",
"-",
"positive",
"rate",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/classic.go#L24-L32 |
18,847 | tylertreat/BoomFilters | classic.go | FillRatio | func (b *BloomFilter) FillRatio() float64 {
sum := uint32(0)
for i := uint(0); i < b.buckets.Count(); i++ {
sum += b.buckets.Get(i)
}
return float64(sum) / float64(b.m)
} | go | func (b *BloomFilter) FillRatio() float64 {
sum := uint32(0)
for i := uint(0); i < b.buckets.Count(); i++ {
sum += b.buckets.Get(i)
}
return float64(sum) / float64(b.m)
} | [
"func",
"(",
"b",
"*",
"BloomFilter",
")",
"FillRatio",
"(",
")",
"float64",
"{",
"sum",
":=",
"uint32",
"(",
"0",
")",
"\n",
"for",
"i",
":=",
"uint",
"(",
"0",
")",
";",
"i",
"<",
"b",
".",
"buckets",
".",
"Count",
"(",
")",
";",
"i",
"++",... | // FillRatio returns the ratio of set bits. | [
"FillRatio",
"returns",
"the",
"ratio",
"of",
"set",
"bits",
"."
] | 611b3dbe80e85df3a0a10a43997d4d5784e86245 | https://github.com/tylertreat/BoomFilters/blob/611b3dbe80e85df3a0a10a43997d4d5784e86245/classic.go#L55-L61 |
18,848 | howeyc/fsnotify | fsnotify_windows.go | NewWatcher | func NewWatcher() (*Watcher, error) {
port, e := syscall.CreateIoCompletionPort(syscall.InvalidHandle, 0, 0, 0)
if e != nil {
return nil, os.NewSyscallError("CreateIoCompletionPort", e)
}
w := &Watcher{
port: port,
watches: make(watchMap),
fsnFlags: make(map[string]uint32),
input: make(chan *input, 1),
Event: make(chan *FileEvent, 50),
internalEvent: make(chan *FileEvent),
Error: make(chan error),
quit: make(chan chan<- error, 1),
}
go w.readEvents()
go w.purgeEvents()
return w, nil
} | go | func NewWatcher() (*Watcher, error) {
port, e := syscall.CreateIoCompletionPort(syscall.InvalidHandle, 0, 0, 0)
if e != nil {
return nil, os.NewSyscallError("CreateIoCompletionPort", e)
}
w := &Watcher{
port: port,
watches: make(watchMap),
fsnFlags: make(map[string]uint32),
input: make(chan *input, 1),
Event: make(chan *FileEvent, 50),
internalEvent: make(chan *FileEvent),
Error: make(chan error),
quit: make(chan chan<- error, 1),
}
go w.readEvents()
go w.purgeEvents()
return w, nil
} | [
"func",
"NewWatcher",
"(",
")",
"(",
"*",
"Watcher",
",",
"error",
")",
"{",
"port",
",",
"e",
":=",
"syscall",
".",
"CreateIoCompletionPort",
"(",
"syscall",
".",
"InvalidHandle",
",",
"0",
",",
"0",
",",
"0",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{... | // NewWatcher creates and returns a Watcher. | [
"NewWatcher",
"creates",
"and",
"returns",
"a",
"Watcher",
"."
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_windows.go#L133-L151 |
18,849 | howeyc/fsnotify | fsnotify.go | purgeEvents | func (w *Watcher) purgeEvents() {
for ev := range w.internalEvent {
sendEvent := false
w.fsnmut.Lock()
fsnFlags := w.fsnFlags[ev.Name]
w.fsnmut.Unlock()
if (fsnFlags&FSN_CREATE == FSN_CREATE) && ev.IsCreate() {
sendEvent = true
}
if (fsnFlags&FSN_MODIFY == FSN_MODIFY) && ev.IsModify() {
sendEvent = true
}
if (fsnFlags&FSN_DELETE == FSN_DELETE) && ev.IsDelete() {
sendEvent = true
}
if (fsnFlags&FSN_RENAME == FSN_RENAME) && ev.IsRename() {
sendEvent = true
}
if sendEvent {
w.Event <- ev
}
// If there's no file, then no more events for user
// BSD must keep watch for internal use (watches DELETEs to keep track
// what files exist for create events)
if ev.IsDelete() {
w.fsnmut.Lock()
delete(w.fsnFlags, ev.Name)
w.fsnmut.Unlock()
}
}
close(w.Event)
} | go | func (w *Watcher) purgeEvents() {
for ev := range w.internalEvent {
sendEvent := false
w.fsnmut.Lock()
fsnFlags := w.fsnFlags[ev.Name]
w.fsnmut.Unlock()
if (fsnFlags&FSN_CREATE == FSN_CREATE) && ev.IsCreate() {
sendEvent = true
}
if (fsnFlags&FSN_MODIFY == FSN_MODIFY) && ev.IsModify() {
sendEvent = true
}
if (fsnFlags&FSN_DELETE == FSN_DELETE) && ev.IsDelete() {
sendEvent = true
}
if (fsnFlags&FSN_RENAME == FSN_RENAME) && ev.IsRename() {
sendEvent = true
}
if sendEvent {
w.Event <- ev
}
// If there's no file, then no more events for user
// BSD must keep watch for internal use (watches DELETEs to keep track
// what files exist for create events)
if ev.IsDelete() {
w.fsnmut.Lock()
delete(w.fsnFlags, ev.Name)
w.fsnmut.Unlock()
}
}
close(w.Event)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"purgeEvents",
"(",
")",
"{",
"for",
"ev",
":=",
"range",
"w",
".",
"internalEvent",
"{",
"sendEvent",
":=",
"false",
"\n",
"w",
".",
"fsnmut",
".",
"Lock",
"(",
")",
"\n",
"fsnFlags",
":=",
"w",
".",
"fsnFlag... | // Purge events from interal chan to external chan if passes filter | [
"Purge",
"events",
"from",
"interal",
"chan",
"to",
"external",
"chan",
"if",
"passes",
"filter"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify.go#L20-L58 |
18,850 | howeyc/fsnotify | fsnotify.go | Watch | func (w *Watcher) Watch(path string) error {
return w.WatchFlags(path, FSN_ALL)
} | go | func (w *Watcher) Watch(path string) error {
return w.WatchFlags(path, FSN_ALL)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"Watch",
"(",
"path",
"string",
")",
"error",
"{",
"return",
"w",
".",
"WatchFlags",
"(",
"path",
",",
"FSN_ALL",
")",
"\n",
"}"
] | // Watch a given file path | [
"Watch",
"a",
"given",
"file",
"path"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify.go#L61-L63 |
18,851 | howeyc/fsnotify | fsnotify.go | RemoveWatch | func (w *Watcher) RemoveWatch(path string) error {
w.fsnmut.Lock()
delete(w.fsnFlags, path)
w.fsnmut.Unlock()
return w.removeWatch(path)
} | go | func (w *Watcher) RemoveWatch(path string) error {
w.fsnmut.Lock()
delete(w.fsnFlags, path)
w.fsnmut.Unlock()
return w.removeWatch(path)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"RemoveWatch",
"(",
"path",
"string",
")",
"error",
"{",
"w",
".",
"fsnmut",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"w",
".",
"fsnFlags",
",",
"path",
")",
"\n",
"w",
".",
"fsnmut",
".",
"Unlock",
"(",
... | // Remove a watch on a file | [
"Remove",
"a",
"watch",
"on",
"a",
"file"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify.go#L74-L79 |
18,852 | howeyc/fsnotify | fsnotify_linux.go | IsCreate | func (e *FileEvent) IsCreate() bool {
return (e.mask&sys_IN_CREATE) == sys_IN_CREATE || (e.mask&sys_IN_MOVED_TO) == sys_IN_MOVED_TO
} | go | func (e *FileEvent) IsCreate() bool {
return (e.mask&sys_IN_CREATE) == sys_IN_CREATE || (e.mask&sys_IN_MOVED_TO) == sys_IN_MOVED_TO
} | [
"func",
"(",
"e",
"*",
"FileEvent",
")",
"IsCreate",
"(",
")",
"bool",
"{",
"return",
"(",
"e",
".",
"mask",
"&",
"sys_IN_CREATE",
")",
"==",
"sys_IN_CREATE",
"||",
"(",
"e",
".",
"mask",
"&",
"sys_IN_MOVED_TO",
")",
"==",
"sys_IN_MOVED_TO",
"\n",
"}"
... | // IsCreate reports whether the FileEvent was triggered by a creation | [
"IsCreate",
"reports",
"whether",
"the",
"FileEvent",
"was",
"triggered",
"by",
"a",
"creation"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_linux.go#L66-L68 |
18,853 | howeyc/fsnotify | fsnotify_linux.go | Close | func (w *Watcher) Close() error {
if w.isClosed {
return nil
}
w.isClosed = true
// Remove all watches
for path := range w.watches {
w.RemoveWatch(path)
}
// Send "quit" message to the reader goroutine
w.done <- true
return nil
} | go | func (w *Watcher) Close() error {
if w.isClosed {
return nil
}
w.isClosed = true
// Remove all watches
for path := range w.watches {
w.RemoveWatch(path)
}
// Send "quit" message to the reader goroutine
w.done <- true
return nil
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"w",
".",
"isClosed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"w",
".",
"isClosed",
"=",
"true",
"\n\n",
"// Remove all watches",
"for",
"path",
":=",
"range",
"w",
".",
"... | // Close closes an inotify watcher instance
// It sends a message to the reader goroutine to quit and removes all watches
// associated with the inotify instance | [
"Close",
"closes",
"an",
"inotify",
"watcher",
"instance",
"It",
"sends",
"a",
"message",
"to",
"the",
"reader",
"goroutine",
"to",
"quit",
"and",
"removes",
"all",
"watches",
"associated",
"with",
"the",
"inotify",
"instance"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_linux.go#L134-L149 |
18,854 | howeyc/fsnotify | fsnotify_linux.go | readEvents | func (w *Watcher) readEvents() {
var (
buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
n int // Number of bytes read with read()
errno error // Syscall errno
)
for {
// See if there is a message on the "done" channel
select {
case <-w.done:
syscall.Close(w.fd)
close(w.internalEvent)
close(w.Error)
return
default:
}
n, errno = syscall.Read(w.fd, buf[:])
// If EOF is received
if n == 0 {
syscall.Close(w.fd)
close(w.internalEvent)
close(w.Error)
return
}
if n < 0 {
w.Error <- os.NewSyscallError("read", errno)
continue
}
if n < syscall.SizeofInotifyEvent {
w.Error <- errors.New("inotify: short read in readEvents()")
continue
}
var offset uint32 = 0
// We don't know how many events we just read into the buffer
// While the offset points to at least one whole event...
for offset <= uint32(n-syscall.SizeofInotifyEvent) {
// Point "raw" to the event in the buffer
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset]))
event := new(FileEvent)
event.mask = uint32(raw.Mask)
event.cookie = uint32(raw.Cookie)
nameLen := uint32(raw.Len)
// If the event happened to the watched directory or the watched file, the kernel
// doesn't append the filename to the event, but we would like to always fill the
// the "Name" field with a valid filename. We retrieve the path of the watch from
// the "paths" map.
w.mu.Lock()
event.Name = w.paths[int(raw.Wd)]
w.mu.Unlock()
watchedName := event.Name
if nameLen > 0 {
// Point "bytes" at the first byte of the filename
bytes := (*[syscall.PathMax]byte)(unsafe.Pointer(&buf[offset+syscall.SizeofInotifyEvent]))
// The filename is padded with NUL bytes. TrimRight() gets rid of those.
event.Name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
}
// Send the events that are not ignored on the events channel
if !event.ignoreLinux() {
// Setup FSNotify flags (inherit from directory watch)
w.fsnmut.Lock()
if _, fsnFound := w.fsnFlags[event.Name]; !fsnFound {
if fsnFlags, watchFound := w.fsnFlags[watchedName]; watchFound {
w.fsnFlags[event.Name] = fsnFlags
} else {
w.fsnFlags[event.Name] = FSN_ALL
}
}
w.fsnmut.Unlock()
w.internalEvent <- event
}
// Move to the next event in the buffer
offset += syscall.SizeofInotifyEvent + nameLen
}
}
} | go | func (w *Watcher) readEvents() {
var (
buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
n int // Number of bytes read with read()
errno error // Syscall errno
)
for {
// See if there is a message on the "done" channel
select {
case <-w.done:
syscall.Close(w.fd)
close(w.internalEvent)
close(w.Error)
return
default:
}
n, errno = syscall.Read(w.fd, buf[:])
// If EOF is received
if n == 0 {
syscall.Close(w.fd)
close(w.internalEvent)
close(w.Error)
return
}
if n < 0 {
w.Error <- os.NewSyscallError("read", errno)
continue
}
if n < syscall.SizeofInotifyEvent {
w.Error <- errors.New("inotify: short read in readEvents()")
continue
}
var offset uint32 = 0
// We don't know how many events we just read into the buffer
// While the offset points to at least one whole event...
for offset <= uint32(n-syscall.SizeofInotifyEvent) {
// Point "raw" to the event in the buffer
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset]))
event := new(FileEvent)
event.mask = uint32(raw.Mask)
event.cookie = uint32(raw.Cookie)
nameLen := uint32(raw.Len)
// If the event happened to the watched directory or the watched file, the kernel
// doesn't append the filename to the event, but we would like to always fill the
// the "Name" field with a valid filename. We retrieve the path of the watch from
// the "paths" map.
w.mu.Lock()
event.Name = w.paths[int(raw.Wd)]
w.mu.Unlock()
watchedName := event.Name
if nameLen > 0 {
// Point "bytes" at the first byte of the filename
bytes := (*[syscall.PathMax]byte)(unsafe.Pointer(&buf[offset+syscall.SizeofInotifyEvent]))
// The filename is padded with NUL bytes. TrimRight() gets rid of those.
event.Name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
}
// Send the events that are not ignored on the events channel
if !event.ignoreLinux() {
// Setup FSNotify flags (inherit from directory watch)
w.fsnmut.Lock()
if _, fsnFound := w.fsnFlags[event.Name]; !fsnFound {
if fsnFlags, watchFound := w.fsnFlags[watchedName]; watchFound {
w.fsnFlags[event.Name] = fsnFlags
} else {
w.fsnFlags[event.Name] = FSN_ALL
}
}
w.fsnmut.Unlock()
w.internalEvent <- event
}
// Move to the next event in the buffer
offset += syscall.SizeofInotifyEvent + nameLen
}
}
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"readEvents",
"(",
")",
"{",
"var",
"(",
"buf",
"[",
"syscall",
".",
"SizeofInotifyEvent",
"*",
"4096",
"]",
"byte",
"// Buffer for a maximum of 4096 raw events",
"\n",
"n",
"int",
"// Number of bytes read with read()",
"\n",... | // readEvents reads from the inotify file descriptor, converts the
// received events into Event objects and sends them via the Event channel | [
"readEvents",
"reads",
"from",
"the",
"inotify",
"file",
"descriptor",
"converts",
"the",
"received",
"events",
"into",
"Event",
"objects",
"and",
"sends",
"them",
"via",
"the",
"Event",
"channel"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_linux.go#L201-L283 |
18,855 | howeyc/fsnotify | fsnotify_linux.go | ignoreLinux | func (e *FileEvent) ignoreLinux() bool {
// Ignore anything the inotify API says to ignore
if e.mask&sys_IN_IGNORED == sys_IN_IGNORED {
return true
}
// If the event is not a DELETE or RENAME, the file must exist.
// Otherwise the event is ignored.
// *Note*: this was put in place because it was seen that a MODIFY
// event was sent after the DELETE. This ignores that MODIFY and
// assumes a DELETE will come or has come if the file doesn't exist.
if !(e.IsDelete() || e.IsRename()) {
_, statErr := os.Lstat(e.Name)
return os.IsNotExist(statErr)
}
return false
} | go | func (e *FileEvent) ignoreLinux() bool {
// Ignore anything the inotify API says to ignore
if e.mask&sys_IN_IGNORED == sys_IN_IGNORED {
return true
}
// If the event is not a DELETE or RENAME, the file must exist.
// Otherwise the event is ignored.
// *Note*: this was put in place because it was seen that a MODIFY
// event was sent after the DELETE. This ignores that MODIFY and
// assumes a DELETE will come or has come if the file doesn't exist.
if !(e.IsDelete() || e.IsRename()) {
_, statErr := os.Lstat(e.Name)
return os.IsNotExist(statErr)
}
return false
} | [
"func",
"(",
"e",
"*",
"FileEvent",
")",
"ignoreLinux",
"(",
")",
"bool",
"{",
"// Ignore anything the inotify API says to ignore",
"if",
"e",
".",
"mask",
"&",
"sys_IN_IGNORED",
"==",
"sys_IN_IGNORED",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// If the event is... | // Certain types of events can be "ignored" and not sent over the Event
// channel. Such as events marked ignore by the kernel, or MODIFY events
// against files that do not exist. | [
"Certain",
"types",
"of",
"events",
"can",
"be",
"ignored",
"and",
"not",
"sent",
"over",
"the",
"Event",
"channel",
".",
"Such",
"as",
"events",
"marked",
"ignore",
"by",
"the",
"kernel",
"or",
"MODIFY",
"events",
"against",
"files",
"that",
"do",
"not",
... | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_linux.go#L288-L304 |
18,856 | howeyc/fsnotify | fsnotify_bsd.go | IsModify | func (e *FileEvent) IsModify() bool {
return ((e.mask&sys_NOTE_WRITE) == sys_NOTE_WRITE || (e.mask&sys_NOTE_ATTRIB) == sys_NOTE_ATTRIB)
} | go | func (e *FileEvent) IsModify() bool {
return ((e.mask&sys_NOTE_WRITE) == sys_NOTE_WRITE || (e.mask&sys_NOTE_ATTRIB) == sys_NOTE_ATTRIB)
} | [
"func",
"(",
"e",
"*",
"FileEvent",
")",
"IsModify",
"(",
")",
"bool",
"{",
"return",
"(",
"(",
"e",
".",
"mask",
"&",
"sys_NOTE_WRITE",
")",
"==",
"sys_NOTE_WRITE",
"||",
"(",
"e",
".",
"mask",
"&",
"sys_NOTE_ATTRIB",
")",
"==",
"sys_NOTE_ATTRIB",
")"... | // IsModify reports whether the FileEvent was triggered by a file modification | [
"IsModify",
"reports",
"whether",
"the",
"FileEvent",
"was",
"triggered",
"by",
"a",
"file",
"modification"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_bsd.go#L49-L51 |
18,857 | howeyc/fsnotify | fsnotify_bsd.go | Close | func (w *Watcher) Close() error {
w.mu.Lock()
if w.isClosed {
w.mu.Unlock()
return nil
}
w.isClosed = true
w.mu.Unlock()
// Send "quit" message to the reader goroutine
w.done <- true
w.wmut.Lock()
ws := w.watches
w.wmut.Unlock()
for path := range ws {
w.removeWatch(path)
}
return nil
} | go | func (w *Watcher) Close() error {
w.mu.Lock()
if w.isClosed {
w.mu.Unlock()
return nil
}
w.isClosed = true
w.mu.Unlock()
// Send "quit" message to the reader goroutine
w.done <- true
w.wmut.Lock()
ws := w.watches
w.wmut.Unlock()
for path := range ws {
w.removeWatch(path)
}
return nil
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"w",
".",
"isClosed",
"{",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"w",
".",... | // Close closes a kevent watcher instance
// It sends a message to the reader goroutine to quit and removes all watches
// associated with the kevent instance | [
"Close",
"closes",
"a",
"kevent",
"watcher",
"instance",
"It",
"sends",
"a",
"message",
"to",
"the",
"reader",
"goroutine",
"to",
"quit",
"and",
"removes",
"all",
"watches",
"associated",
"with",
"the",
"kevent",
"instance"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_bsd.go#L113-L132 |
18,858 | howeyc/fsnotify | fsnotify_bsd.go | sendDirectoryChangeEvents | func (w *Watcher) sendDirectoryChangeEvents(dirPath string) {
// Get all files
files, err := ioutil.ReadDir(dirPath)
if err != nil {
w.Error <- err
}
// Search for new files
for _, fileInfo := range files {
filePath := filepath.Join(dirPath, fileInfo.Name())
w.femut.Lock()
_, doesExist := w.fileExists[filePath]
w.femut.Unlock()
if !doesExist {
// Inherit fsnFlags from parent directory
w.fsnmut.Lock()
if flags, found := w.fsnFlags[dirPath]; found {
w.fsnFlags[filePath] = flags
} else {
w.fsnFlags[filePath] = FSN_ALL
}
w.fsnmut.Unlock()
// Send create event
fileEvent := new(FileEvent)
fileEvent.Name = filePath
fileEvent.create = true
w.internalEvent <- fileEvent
}
w.femut.Lock()
w.fileExists[filePath] = true
w.femut.Unlock()
}
w.watchDirectoryFiles(dirPath)
} | go | func (w *Watcher) sendDirectoryChangeEvents(dirPath string) {
// Get all files
files, err := ioutil.ReadDir(dirPath)
if err != nil {
w.Error <- err
}
// Search for new files
for _, fileInfo := range files {
filePath := filepath.Join(dirPath, fileInfo.Name())
w.femut.Lock()
_, doesExist := w.fileExists[filePath]
w.femut.Unlock()
if !doesExist {
// Inherit fsnFlags from parent directory
w.fsnmut.Lock()
if flags, found := w.fsnFlags[dirPath]; found {
w.fsnFlags[filePath] = flags
} else {
w.fsnFlags[filePath] = FSN_ALL
}
w.fsnmut.Unlock()
// Send create event
fileEvent := new(FileEvent)
fileEvent.Name = filePath
fileEvent.create = true
w.internalEvent <- fileEvent
}
w.femut.Lock()
w.fileExists[filePath] = true
w.femut.Unlock()
}
w.watchDirectoryFiles(dirPath)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"sendDirectoryChangeEvents",
"(",
"dirPath",
"string",
")",
"{",
"// Get all files",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"dirPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"Error",
... | // sendDirectoryEvents searches the directory for newly created files
// and sends them over the event channel. This functionality is to have
// the BSD version of fsnotify match linux fsnotify which provides a
// create event for files created in a watched directory. | [
"sendDirectoryEvents",
"searches",
"the",
"directory",
"for",
"newly",
"created",
"files",
"and",
"sends",
"them",
"over",
"the",
"event",
"channel",
".",
"This",
"functionality",
"is",
"to",
"have",
"the",
"BSD",
"version",
"of",
"fsnotify",
"match",
"linux",
... | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_bsd.go#L462-L496 |
18,859 | coreos/go-oidc | jwks.go | NewRemoteKeySet | func NewRemoteKeySet(ctx context.Context, jwksURL string) KeySet {
return newRemoteKeySet(ctx, jwksURL, time.Now)
} | go | func NewRemoteKeySet(ctx context.Context, jwksURL string) KeySet {
return newRemoteKeySet(ctx, jwksURL, time.Now)
} | [
"func",
"NewRemoteKeySet",
"(",
"ctx",
"context",
".",
"Context",
",",
"jwksURL",
"string",
")",
"KeySet",
"{",
"return",
"newRemoteKeySet",
"(",
"ctx",
",",
"jwksURL",
",",
"time",
".",
"Now",
")",
"\n",
"}"
] | // NewRemoteKeySet returns a KeySet that can validate JSON web tokens by using HTTP
// GETs to fetch JSON web token sets hosted at a remote URL. This is automatically
// used by NewProvider using the URLs returned by OpenID Connect discovery, but is
// exposed for providers that don't support discovery or to prevent round trips to the
// discovery URL.
//
// The returned KeySet is a long lived verifier that caches keys based on cache-control
// headers. Reuse a common remote key set instead of creating new ones as needed.
//
// The behavior of the returned KeySet is undefined once the context is canceled. | [
"NewRemoteKeySet",
"returns",
"a",
"KeySet",
"that",
"can",
"validate",
"JSON",
"web",
"tokens",
"by",
"using",
"HTTP",
"GETs",
"to",
"fetch",
"JSON",
"web",
"token",
"sets",
"hosted",
"at",
"a",
"remote",
"URL",
".",
"This",
"is",
"automatically",
"used",
... | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L36-L38 |
18,860 | coreos/go-oidc | jwks.go | done | func (i *inflight) done(keys []jose.JSONWebKey, err error) {
i.keys = keys
i.err = err
close(i.doneCh)
} | go | func (i *inflight) done(keys []jose.JSONWebKey, err error) {
i.keys = keys
i.err = err
close(i.doneCh)
} | [
"func",
"(",
"i",
"*",
"inflight",
")",
"done",
"(",
"keys",
"[",
"]",
"jose",
".",
"JSONWebKey",
",",
"err",
"error",
")",
"{",
"i",
".",
"keys",
"=",
"keys",
"\n",
"i",
".",
"err",
"=",
"err",
"\n",
"close",
"(",
"i",
".",
"doneCh",
")",
"\... | // done can only be called by a single goroutine. It records the result of the
// inflight request and signals other goroutines that the result is safe to
// inspect. | [
"done",
"can",
"only",
"be",
"called",
"by",
"a",
"single",
"goroutine",
".",
"It",
"records",
"the",
"result",
"of",
"the",
"inflight",
"request",
"and",
"signals",
"other",
"goroutines",
"that",
"the",
"result",
"is",
"safe",
"to",
"inspect",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L85-L89 |
18,861 | coreos/go-oidc | jwks.go | keysFromRemote | func (r *remoteKeySet) keysFromRemote(ctx context.Context) ([]jose.JSONWebKey, error) {
// Need to lock to inspect the inflight request field.
r.mu.Lock()
// If there's not a current inflight request, create one.
if r.inflight == nil {
r.inflight = newInflight()
// This goroutine has exclusive ownership over the current inflight
// request. It releases the resource by nil'ing the inflight field
// once the goroutine is done.
go func() {
// Sync keys and finish inflight when that's done.
keys, expiry, err := r.updateKeys()
r.inflight.done(keys, err)
// Lock to update the keys and indicate that there is no longer an
// inflight request.
r.mu.Lock()
defer r.mu.Unlock()
if err == nil {
r.cachedKeys = keys
r.expiry = expiry
}
// Free inflight so a different request can run.
r.inflight = nil
}()
}
inflight := r.inflight
r.mu.Unlock()
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-inflight.wait():
return inflight.result()
}
} | go | func (r *remoteKeySet) keysFromRemote(ctx context.Context) ([]jose.JSONWebKey, error) {
// Need to lock to inspect the inflight request field.
r.mu.Lock()
// If there's not a current inflight request, create one.
if r.inflight == nil {
r.inflight = newInflight()
// This goroutine has exclusive ownership over the current inflight
// request. It releases the resource by nil'ing the inflight field
// once the goroutine is done.
go func() {
// Sync keys and finish inflight when that's done.
keys, expiry, err := r.updateKeys()
r.inflight.done(keys, err)
// Lock to update the keys and indicate that there is no longer an
// inflight request.
r.mu.Lock()
defer r.mu.Unlock()
if err == nil {
r.cachedKeys = keys
r.expiry = expiry
}
// Free inflight so a different request can run.
r.inflight = nil
}()
}
inflight := r.inflight
r.mu.Unlock()
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-inflight.wait():
return inflight.result()
}
} | [
"func",
"(",
"r",
"*",
"remoteKeySet",
")",
"keysFromRemote",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"jose",
".",
"JSONWebKey",
",",
"error",
")",
"{",
"// Need to lock to inspect the inflight request field.",
"r",
".",
"mu",
".",
"Lock",
... | // keysFromRemote syncs the key set from the remote set, records the values in the
// cache, and returns the key set. | [
"keysFromRemote",
"syncs",
"the",
"key",
"set",
"from",
"the",
"remote",
"set",
"records",
"the",
"values",
"in",
"the",
"cache",
"and",
"returns",
"the",
"key",
"set",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L151-L190 |
18,862 | coreos/go-oidc | verify.go | Verifier | func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
return NewVerifier(p.issuer, p.remoteKeySet, config)
} | go | func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
return NewVerifier(p.issuer, p.remoteKeySet, config)
} | [
"func",
"(",
"p",
"*",
"Provider",
")",
"Verifier",
"(",
"config",
"*",
"Config",
")",
"*",
"IDTokenVerifier",
"{",
"return",
"NewVerifier",
"(",
"p",
".",
"issuer",
",",
"p",
".",
"remoteKeySet",
",",
"config",
")",
"\n",
"}"
] | // Verifier returns an IDTokenVerifier that uses the provider's key set to verify JWTs.
//
// The returned IDTokenVerifier is tied to the Provider's context and its behavior is
// undefined once the Provider's context is canceled. | [
"Verifier",
"returns",
"an",
"IDTokenVerifier",
"that",
"uses",
"the",
"provider",
"s",
"key",
"set",
"to",
"verify",
"JWTs",
".",
"The",
"returned",
"IDTokenVerifier",
"is",
"tied",
"to",
"the",
"Provider",
"s",
"context",
"and",
"its",
"behavior",
"is",
"u... | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/verify.go#L98-L100 |
18,863 | coreos/go-oidc | verify.go | resolveDistributedClaim | func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src claimSource) ([]byte, error) {
req, err := http.NewRequest("GET", src.Endpoint, nil)
if err != nil {
return nil, fmt.Errorf("malformed request: %v", err)
}
if src.AccessToken != "" {
req.Header.Set("Authorization", "Bearer "+src.AccessToken)
}
resp, err := doRequest(ctx, req)
if err != nil {
return nil, fmt.Errorf("oidc: Request to endpoint failed: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to read response body: %v", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("oidc: request failed: %v", resp.StatusCode)
}
token, err := verifier.Verify(ctx, string(body))
if err != nil {
return nil, fmt.Errorf("malformed response body: %v", err)
}
return token.claims, nil
} | go | func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src claimSource) ([]byte, error) {
req, err := http.NewRequest("GET", src.Endpoint, nil)
if err != nil {
return nil, fmt.Errorf("malformed request: %v", err)
}
if src.AccessToken != "" {
req.Header.Set("Authorization", "Bearer "+src.AccessToken)
}
resp, err := doRequest(ctx, req)
if err != nil {
return nil, fmt.Errorf("oidc: Request to endpoint failed: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to read response body: %v", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("oidc: request failed: %v", resp.StatusCode)
}
token, err := verifier.Verify(ctx, string(body))
if err != nil {
return nil, fmt.Errorf("malformed response body: %v", err)
}
return token.claims, nil
} | [
"func",
"resolveDistributedClaim",
"(",
"ctx",
"context",
".",
"Context",
",",
"verifier",
"*",
"IDTokenVerifier",
",",
"src",
"claimSource",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"... | // Returns the Claims from the distributed JWT token | [
"Returns",
"the",
"Claims",
"from",
"the",
"distributed",
"JWT",
"token"
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/verify.go#L124-L154 |
18,864 | coreos/go-oidc | oidc.go | Claims | func (u *UserInfo) Claims(v interface{}) error {
if u.claims == nil {
return errors.New("oidc: claims not set")
}
return json.Unmarshal(u.claims, v)
} | go | func (u *UserInfo) Claims(v interface{}) error {
if u.claims == nil {
return errors.New("oidc: claims not set")
}
return json.Unmarshal(u.claims, v)
} | [
"func",
"(",
"u",
"*",
"UserInfo",
")",
"Claims",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"u",
".",
"claims",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unm... | // Claims unmarshals the raw JSON object claims into the provided object. | [
"Claims",
"unmarshals",
"the",
"raw",
"JSON",
"object",
"claims",
"into",
"the",
"provided",
"object",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/oidc.go#L172-L177 |
18,865 | scylladb/gocqlx | qb/utils.go | placeholders | func placeholders(cql *bytes.Buffer, count int) {
if count < 1 {
return
}
for i := 0; i < count-1; i++ {
cql.WriteByte('?')
cql.WriteByte(',')
}
cql.WriteByte('?')
} | go | func placeholders(cql *bytes.Buffer, count int) {
if count < 1 {
return
}
for i := 0; i < count-1; i++ {
cql.WriteByte('?')
cql.WriteByte(',')
}
cql.WriteByte('?')
} | [
"func",
"placeholders",
"(",
"cql",
"*",
"bytes",
".",
"Buffer",
",",
"count",
"int",
")",
"{",
"if",
"count",
"<",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
"-",
"1",
";",
"i",
"++",
"{",
"cql",
".... | // placeholders returns a string with count ? placeholders joined with commas. | [
"placeholders",
"returns",
"a",
"string",
"with",
"count",
"?",
"placeholders",
"joined",
"with",
"commas",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/utils.go#L12-L22 |
18,866 | scylladb/gocqlx | qb/update.go | Table | func (b *UpdateBuilder) Table(table string) *UpdateBuilder {
b.table = table
return b
} | go | func (b *UpdateBuilder) Table(table string) *UpdateBuilder {
b.table = table
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Table",
"(",
"table",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"table",
"=",
"table",
"\n",
"return",
"b",
"\n",
"}"
] | // Table sets the table to be updated. | [
"Table",
"sets",
"the",
"table",
"to",
"be",
"updated",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L77-L80 |
18,867 | scylladb/gocqlx | qb/update.go | Set | func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder {
for _, c := range columns {
b.assignments = append(b.assignments, assignment{
column: c,
value: param(c),
})
}
return b
} | go | func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder {
for _, c := range columns {
b.assignments = append(b.assignments, assignment{
column: c,
value: param(c),
})
}
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Set",
"(",
"columns",
"...",
"string",
")",
"*",
"UpdateBuilder",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"columns",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assi... | // Set adds SET clauses to the query. | [
"Set",
"adds",
"SET",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L108-L117 |
18,868 | scylladb/gocqlx | qb/update.go | SetNamed | func (b *UpdateBuilder) SetNamed(column, name string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: param(name)})
return b
} | go | func (b *UpdateBuilder) SetNamed(column, name string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: param(name)})
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"SetNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assignment",
"{",
"column",
":",
"column",
",",
"... | // SetNamed adds SET column=? clause to the query with a custom parameter name. | [
"SetNamed",
"adds",
"SET",
"column",
"=",
"?",
"clause",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L120-L124 |
18,869 | scylladb/gocqlx | qb/update.go | SetLit | func (b *UpdateBuilder) SetLit(column, literal string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: lit(literal)})
return b
} | go | func (b *UpdateBuilder) SetLit(column, literal string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: lit(literal)})
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"SetLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assignment",
"{",
"column",
":",
"column",
",",
... | // SetLit adds SET column=literal clause to the query. | [
"SetLit",
"adds",
"SET",
"column",
"=",
"literal",
"clause",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L127-L131 |
18,870 | scylladb/gocqlx | qb/update.go | Add | func (b *UpdateBuilder) Add(column string) *UpdateBuilder {
return b.addValue(column, param(column))
} | go | func (b *UpdateBuilder) Add(column string) *UpdateBuilder {
return b.addValue(column, param(column))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Add",
"(",
"column",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"param",
"(",
"column",
")",
")",
"\n",
"}"
] | // Add adds SET column=column+? clauses to the query. | [
"Add",
"adds",
"SET",
"column",
"=",
"column",
"+",
"?",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L140-L142 |
18,871 | scylladb/gocqlx | qb/update.go | AddNamed | func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder {
return b.addValue(column, param(name))
} | go | func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder {
return b.addValue(column, param(name))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"AddNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"param",
"(",
"name",
")",
")",
"\n",
"}"
] | // AddNamed adds SET column=column+? clauses to the query with a custom
// parameter name. | [
"AddNamed",
"adds",
"SET",
"column",
"=",
"column",
"+",
"?",
"clauses",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L146-L148 |
18,872 | scylladb/gocqlx | qb/update.go | AddLit | func (b *UpdateBuilder) AddLit(column, literal string) *UpdateBuilder {
return b.addValue(column, lit(literal))
} | go | func (b *UpdateBuilder) AddLit(column, literal string) *UpdateBuilder {
return b.addValue(column, lit(literal))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"AddLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"lit",
"(",
"literal",
")",
")",
"\n",
"}"
] | // AddLit adds SET column=column+literal clauses to the query. | [
"AddLit",
"adds",
"SET",
"column",
"=",
"column",
"+",
"literal",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L151-L153 |
18,873 | scylladb/gocqlx | qb/update.go | Remove | func (b *UpdateBuilder) Remove(column string) *UpdateBuilder {
return b.removeValue(column, param(column))
} | go | func (b *UpdateBuilder) Remove(column string) *UpdateBuilder {
return b.removeValue(column, param(column))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Remove",
"(",
"column",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"param",
"(",
"column",
")",
")",
"\n",
"}"
] | // Remove adds SET column=column-? clauses to the query. | [
"Remove",
"adds",
"SET",
"column",
"=",
"column",
"-",
"?",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L170-L172 |
18,874 | scylladb/gocqlx | qb/update.go | RemoveNamed | func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder {
return b.removeValue(column, param(name))
} | go | func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder {
return b.removeValue(column, param(name))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"RemoveNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"param",
"(",
"name",
")",
")",
"\n",
"}"
] | // RemoveNamed adds SET column=column-? clauses to the query with a custom
// parameter name. | [
"RemoveNamed",
"adds",
"SET",
"column",
"=",
"column",
"-",
"?",
"clauses",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L176-L178 |
18,875 | scylladb/gocqlx | qb/update.go | RemoveLit | func (b *UpdateBuilder) RemoveLit(column, literal string) *UpdateBuilder {
return b.removeValue(column, lit(literal))
} | go | func (b *UpdateBuilder) RemoveLit(column, literal string) *UpdateBuilder {
return b.removeValue(column, lit(literal))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"RemoveLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"lit",
"(",
"literal",
")",
")",
"\n",
"}"
] | // RemoveLit adds SET column=column-literal clauses to the query. | [
"RemoveLit",
"adds",
"SET",
"column",
"=",
"column",
"-",
"literal",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L181-L183 |
18,876 | scylladb/gocqlx | queryx.go | Query | func Query(q *gocql.Query, names []string) *Queryx {
return &Queryx{
Query: q,
Names: names,
Mapper: DefaultMapper,
}
} | go | func Query(q *gocql.Query, names []string) *Queryx {
return &Queryx{
Query: q,
Names: names,
Mapper: DefaultMapper,
}
} | [
"func",
"Query",
"(",
"q",
"*",
"gocql",
".",
"Query",
",",
"names",
"[",
"]",
"string",
")",
"*",
"Queryx",
"{",
"return",
"&",
"Queryx",
"{",
"Query",
":",
"q",
",",
"Names",
":",
"names",
",",
"Mapper",
":",
"DefaultMapper",
",",
"}",
"\n",
"}... | // Query creates a new Queryx from gocql.Query using a default mapper. | [
"Query",
"creates",
"a",
"new",
"Queryx",
"from",
"gocql",
".",
"Query",
"using",
"a",
"default",
"mapper",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L92-L98 |
18,877 | scylladb/gocqlx | queryx.go | BindStruct | func (q *Queryx) BindStruct(arg interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg, nil, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindStruct(arg interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg, nil, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindStruct",
"(",
"arg",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindStructArgs",
"(",
"q",
".",
"Names",
",",
"arg",
",",
"nil",
",",
"q",
".",
"Mapper",
")",
"\n",
"if... | // BindStruct binds query named parameters to values from arg using mapper. If
// value cannot be found error is reported. | [
"BindStruct",
"binds",
"query",
"named",
"parameters",
"to",
"values",
"from",
"arg",
"using",
"mapper",
".",
"If",
"value",
"cannot",
"be",
"found",
"error",
"is",
"reported",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L102-L112 |
18,878 | scylladb/gocqlx | queryx.go | BindStructMap | func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg0, arg1, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg0, arg1, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindStructMap",
"(",
"arg0",
"interface",
"{",
"}",
",",
"arg1",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindStructArgs",
"(",
"q",
".",
"Names",
... | // BindStructMap binds query named parameters to values from arg0 and arg1
// using a mapper. If value cannot be found in arg0 it's looked up in arg1
// before reporting an error. | [
"BindStructMap",
"binds",
"query",
"named",
"parameters",
"to",
"values",
"from",
"arg0",
"and",
"arg1",
"using",
"a",
"mapper",
".",
"If",
"value",
"cannot",
"be",
"found",
"in",
"arg0",
"it",
"s",
"looked",
"up",
"in",
"arg1",
"before",
"reporting",
"an"... | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L117-L127 |
18,879 | scylladb/gocqlx | queryx.go | BindMap | func (q *Queryx) BindMap(arg map[string]interface{}) *Queryx {
arglist, err := bindMapArgs(q.Names, arg)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindMap(arg map[string]interface{}) *Queryx {
arglist, err := bindMapArgs(q.Names, arg)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindMap",
"(",
"arg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindMapArgs",
"(",
"q",
".",
"Names",
",",
"arg",
")",
"\n",
"if",
"err",
"!=",
... | // BindMap binds query named parameters using map. | [
"BindMap",
"binds",
"query",
"named",
"parameters",
"using",
"map",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L157-L167 |
18,880 | scylladb/gocqlx | queryx.go | Exec | func (q *Queryx) Exec() error {
if q.err != nil {
return q.err
}
return q.Query.Exec()
} | go | func (q *Queryx) Exec() error {
if q.err != nil {
return q.err
}
return q.Query.Exec()
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Exec",
"(",
")",
"error",
"{",
"if",
"q",
".",
"err",
"!=",
"nil",
"{",
"return",
"q",
".",
"err",
"\n",
"}",
"\n",
"return",
"q",
".",
"Query",
".",
"Exec",
"(",
")",
"\n",
"}"
] | // Exec executes the query without returning any rows. | [
"Exec",
"executes",
"the",
"query",
"without",
"returning",
"any",
"rows",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L188-L193 |
18,881 | scylladb/gocqlx | queryx.go | Get | func (q *Queryx) Get(dest interface{}) error {
if q.err != nil {
return q.err
}
return Iter(q.Query).Get(dest)
} | go | func (q *Queryx) Get(dest interface{}) error {
if q.err != nil {
return q.err
}
return Iter(q.Query).Get(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"q",
".",
"err",
"!=",
"nil",
"{",
"return",
"q",
".",
"err",
"\n",
"}",
"\n",
"return",
"Iter",
"(",
"q",
".",
"Query",
")",
".",
"Get"... | // Get scans first row into a destination. If the destination type is a struct
// pointer, then Iter.StructScan will be used. If the destination is some
// other type, then the row must only have one column which can scan into that
// type.
//
// If no rows were selected, ErrNotFound is returned. | [
"Get",
"scans",
"first",
"row",
"into",
"a",
"destination",
".",
"If",
"the",
"destination",
"type",
"is",
"a",
"struct",
"pointer",
"then",
"Iter",
".",
"StructScan",
"will",
"be",
"used",
".",
"If",
"the",
"destination",
"is",
"some",
"other",
"type",
... | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L208-L213 |
18,882 | scylladb/gocqlx | queryx.go | GetRelease | func (q *Queryx) GetRelease(dest interface{}) error {
defer q.Release()
return q.Get(dest)
} | go | func (q *Queryx) GetRelease(dest interface{}) error {
defer q.Release()
return q.Get(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"GetRelease",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"q",
".",
"Release",
"(",
")",
"\n",
"return",
"q",
".",
"Get",
"(",
"dest",
")",
"\n",
"}"
] | // GetRelease calls Get and releases the query, a released query cannot be
// reused. | [
"GetRelease",
"calls",
"Get",
"and",
"releases",
"the",
"query",
"a",
"released",
"query",
"cannot",
"be",
"reused",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L217-L220 |
18,883 | scylladb/gocqlx | queryx.go | SelectRelease | func (q *Queryx) SelectRelease(dest interface{}) error {
defer q.Release()
return q.Select(dest)
} | go | func (q *Queryx) SelectRelease(dest interface{}) error {
defer q.Release()
return q.Select(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"SelectRelease",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"q",
".",
"Release",
"(",
")",
"\n",
"return",
"q",
".",
"Select",
"(",
"dest",
")",
"\n",
"}"
] | // SelectRelease calls Select and releases the query, a released query cannot be
// reused. | [
"SelectRelease",
"calls",
"Select",
"and",
"releases",
"the",
"query",
"a",
"released",
"query",
"cannot",
"be",
"reused",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L237-L240 |
18,884 | scylladb/gocqlx | iterx.go | Get | func Get(dest interface{}, q *gocql.Query) error {
return Iter(q).Get(dest)
} | go | func Get(dest interface{}, q *gocql.Query) error {
return Iter(q).Get(dest)
} | [
"func",
"Get",
"(",
"dest",
"interface",
"{",
"}",
",",
"q",
"*",
"gocql",
".",
"Query",
")",
"error",
"{",
"return",
"Iter",
"(",
"q",
")",
".",
"Get",
"(",
"dest",
")",
"\n",
"}"
] | // Get is a convenience function for creating iterator and calling Get.
//
// DEPRECATED use Queryx.Get or Queryx.GetRelease. | [
"Get",
"is",
"a",
"convenience",
"function",
"for",
"creating",
"iterator",
"and",
"calling",
"Get",
".",
"DEPRECATED",
"use",
"Queryx",
".",
"Get",
"or",
"Queryx",
".",
"GetRelease",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L19-L21 |
18,885 | scylladb/gocqlx | iterx.go | Select | func Select(dest interface{}, q *gocql.Query) error {
return Iter(q).Select(dest)
} | go | func Select(dest interface{}, q *gocql.Query) error {
return Iter(q).Select(dest)
} | [
"func",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"q",
"*",
"gocql",
".",
"Query",
")",
"error",
"{",
"return",
"Iter",
"(",
"q",
")",
".",
"Select",
"(",
"dest",
")",
"\n",
"}"
] | // Select is a convenience function for creating iterator and calling Select.
//
// DEPRECATED use Queryx.Select or Queryx.SelectRelease. | [
"Select",
"is",
"a",
"convenience",
"function",
"for",
"creating",
"iterator",
"and",
"calling",
"Select",
".",
"DEPRECATED",
"use",
"Queryx",
".",
"Select",
"or",
"Queryx",
".",
"SelectRelease",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L26-L28 |
18,886 | scylladb/gocqlx | iterx.go | Iter | func Iter(q *gocql.Query) *Iterx {
return &Iterx{
Iter: q.Iter(),
Mapper: DefaultMapper,
}
} | go | func Iter(q *gocql.Query) *Iterx {
return &Iterx{
Iter: q.Iter(),
Mapper: DefaultMapper,
}
} | [
"func",
"Iter",
"(",
"q",
"*",
"gocql",
".",
"Query",
")",
"*",
"Iterx",
"{",
"return",
"&",
"Iterx",
"{",
"Iter",
":",
"q",
".",
"Iter",
"(",
")",
",",
"Mapper",
":",
"DefaultMapper",
",",
"}",
"\n",
"}"
] | // Iter creates a new Iterx from gocql.Query using a default mapper. | [
"Iter",
"creates",
"a",
"new",
"Iterx",
"from",
"gocql",
".",
"Query",
"using",
"a",
"default",
"mapper",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L44-L49 |
18,887 | scylladb/gocqlx | iterx.go | Get | func (iter *Iterx) Get(dest interface{}) error {
iter.scanAny(dest, false)
iter.Close()
return iter.checkErrAndNotFound()
} | go | func (iter *Iterx) Get(dest interface{}) error {
iter.scanAny(dest, false)
iter.Close()
return iter.checkErrAndNotFound()
} | [
"func",
"(",
"iter",
"*",
"Iterx",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"iter",
".",
"scanAny",
"(",
"dest",
",",
"false",
")",
"\n",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"return",
"iter",
".",
"checkErrAndNotFound",
... | // Get scans first row into a destination and closes the iterator. If the
// destination type is a struct pointer, then StructScan will be used.
// If the destination is some other type, then the row must only have one column
// which can scan into that type.
//
// If no rows were selected, ErrNotFound is returned. | [
"Get",
"scans",
"first",
"row",
"into",
"a",
"destination",
"and",
"closes",
"the",
"iterator",
".",
"If",
"the",
"destination",
"type",
"is",
"a",
"struct",
"pointer",
"then",
"StructScan",
"will",
"be",
"used",
".",
"If",
"the",
"destination",
"is",
"som... | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L65-L70 |
18,888 | scylladb/gocqlx | iterx.go | Select | func (iter *Iterx) Select(dest interface{}) error {
iter.scanAll(dest, false)
iter.Close()
return iter.err
} | go | func (iter *Iterx) Select(dest interface{}) error {
iter.scanAll(dest, false)
iter.Close()
return iter.err
} | [
"func",
"(",
"iter",
"*",
"Iterx",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"iter",
".",
"scanAll",
"(",
"dest",
",",
"false",
")",
"\n",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"return",
"iter",
".",
"err",
"\n",
"}"... | // Select scans all rows into a destination, which must be a pointer to slice
// of any type and closes the iterator. If the destination slice type is
// a struct, then StructScan will be used on each row. If the destination is
// some other type, then each row must only have one column which can scan into
// that type.
//
// If no rows were selected, ErrNotFound is NOT returned. | [
"Select",
"scans",
"all",
"rows",
"into",
"a",
"destination",
"which",
"must",
"be",
"a",
"pointer",
"to",
"slice",
"of",
"any",
"type",
"and",
"closes",
"the",
"iterator",
".",
"If",
"the",
"destination",
"slice",
"type",
"is",
"a",
"struct",
"then",
"S... | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L115-L120 |
18,889 | scylladb/gocqlx | queryx_wrap.go | SetSpeculativeExecutionPolicy | func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx {
q.Query.SetSpeculativeExecutionPolicy(sp)
return q
} | go | func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx {
q.Query.SetSpeculativeExecutionPolicy(sp)
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"SetSpeculativeExecutionPolicy",
"(",
"sp",
"gocql",
".",
"SpeculativeExecutionPolicy",
")",
"*",
"Queryx",
"{",
"q",
".",
"Query",
".",
"SetSpeculativeExecutionPolicy",
"(",
"sp",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // SetSpeculativeExecutionPolicy sets the execution policy. | [
"SetSpeculativeExecutionPolicy",
"sets",
"the",
"execution",
"policy",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx_wrap.go#L108-L111 |
18,890 | scylladb/gocqlx | queryx_wrap.go | Bind | func (q *Queryx) Bind(v ...interface{}) *Queryx {
q.Query.Bind(v...)
return q
} | go | func (q *Queryx) Bind(v ...interface{}) *Queryx {
q.Query.Bind(v...)
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Bind",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"q",
".",
"Query",
".",
"Bind",
"(",
"v",
"...",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // Bind sets query arguments of query. This can also be used to rebind new query arguments
// to an existing query instance. | [
"Bind",
"sets",
"query",
"arguments",
"of",
"query",
".",
"This",
"can",
"also",
"be",
"used",
"to",
"rebind",
"new",
"query",
"arguments",
"to",
"an",
"existing",
"query",
"instance",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx_wrap.go#L122-L125 |
18,891 | scylladb/gocqlx | qb/cmp.go | Eq | func Eq(column string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(column),
}
} | go | func Eq(column string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(column),
}
} | [
"func",
"Eq",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Eq produces column=?. | [
"Eq",
"produces",
"column",
"=",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L61-L67 |
18,892 | scylladb/gocqlx | qb/cmp.go | EqNamed | func EqNamed(column, name string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(name),
}
} | go | func EqNamed(column, name string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(name),
}
} | [
"func",
"EqNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // EqNamed produces column=? with a custom parameter name. | [
"EqNamed",
"produces",
"column",
"=",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L70-L76 |
18,893 | scylladb/gocqlx | qb/cmp.go | EqLit | func EqLit(column, literal string) Cmp {
return Cmp{
op: eq,
column: column,
value: lit(literal),
}
} | go | func EqLit(column, literal string) Cmp {
return Cmp{
op: eq,
column: column,
value: lit(literal),
}
} | [
"func",
"EqLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // EqLit produces column=literal and does not add a parameter to the query. | [
"EqLit",
"produces",
"column",
"=",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L79-L85 |
18,894 | scylladb/gocqlx | qb/cmp.go | Lt | func Lt(column string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(column),
}
} | go | func Lt(column string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(column),
}
} | [
"func",
"Lt",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Lt produces column<?. | [
"Lt",
"produces",
"column<?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L97-L103 |
18,895 | scylladb/gocqlx | qb/cmp.go | LtNamed | func LtNamed(column, name string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(name),
}
} | go | func LtNamed(column, name string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(name),
}
} | [
"func",
"LtNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // LtNamed produces column<? with a custom parameter name. | [
"LtNamed",
"produces",
"column<?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L106-L112 |
18,896 | scylladb/gocqlx | qb/cmp.go | LtLit | func LtLit(column, literal string) Cmp {
return Cmp{
op: lt,
column: column,
value: lit(literal),
}
} | go | func LtLit(column, literal string) Cmp {
return Cmp{
op: lt,
column: column,
value: lit(literal),
}
} | [
"func",
"LtLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // LtLit produces column<literal and does not add a parameter to the query. | [
"LtLit",
"produces",
"column<literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L115-L121 |
18,897 | scylladb/gocqlx | qb/cmp.go | LtOrEq | func LtOrEq(column string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(column),
}
} | go | func LtOrEq(column string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(column),
}
} | [
"func",
"LtOrEq",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // LtOrEq produces column<=?. | [
"LtOrEq",
"produces",
"column<",
"=",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L133-L139 |
18,898 | scylladb/gocqlx | qb/cmp.go | LtOrEqNamed | func LtOrEqNamed(column, name string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(name),
}
} | go | func LtOrEqNamed(column, name string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(name),
}
} | [
"func",
"LtOrEqNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // LtOrEqNamed produces column<=? with a custom parameter name. | [
"LtOrEqNamed",
"produces",
"column<",
"=",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L142-L148 |
18,899 | scylladb/gocqlx | qb/cmp.go | LtOrEqLit | func LtOrEqLit(column, literal string) Cmp {
return Cmp{
op: leq,
column: column,
value: lit(literal),
}
} | go | func LtOrEqLit(column, literal string) Cmp {
return Cmp{
op: leq,
column: column,
value: lit(literal),
}
} | [
"func",
"LtOrEqLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // LtOrEqLit produces column<=literal and does not add a parameter to the query. | [
"LtOrEqLit",
"produces",
"column<",
"=",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L151-L157 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.