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 listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
127,100 | kung-foo/freki | netfilter/netfilter.go | SetVerdictModifed | func (nfq *Queue) SetVerdictModifed(packet *RawPacket, buffer []byte, verdict Verdict) (err error) {
C.nfq_set_verdict(
nfq.qh,
C.u_int32_t(packet.ID),
C.u_int32_t(verdict),
C.u_int32_t(len(buffer)),
(*C.uchar)(unsafe.Pointer(&buffer[0])),
)
return
} | go | func (nfq *Queue) SetVerdictModifed(packet *RawPacket, buffer []byte, verdict Verdict) (err error) {
C.nfq_set_verdict(
nfq.qh,
C.u_int32_t(packet.ID),
C.u_int32_t(verdict),
C.u_int32_t(len(buffer)),
(*C.uchar)(unsafe.Pointer(&buffer[0])),
)
return
} | [
"func",
"(",
"nfq",
"*",
"Queue",
")",
"SetVerdictModifed",
"(",
"packet",
"*",
"RawPacket",
",",
"buffer",
"[",
"]",
"byte",
",",
"verdict",
"Verdict",
")",
"(",
"err",
"error",
")",
"{",
"C",
".",
"nfq_set_verdict",
"(",
"nfq",
".",
"qh",
",",
"C",... | // SetVerdictModifed tells nfq that the packet should be replaced with what is
// in buffer. | [
"SetVerdictModifed",
"tells",
"nfq",
"that",
"the",
"packet",
"should",
"be",
"replaced",
"with",
"what",
"is",
"in",
"buffer",
"."
] | 37bf522904e242e4b820d9c52667937ea90e24f7 | https://github.com/kung-foo/freki/blob/37bf522904e242e4b820d9c52667937ea90e24f7/netfilter/netfilter.go#L176-L185 |
127,101 | kung-foo/freki | netfilter/dispatch.go | register | func register(qid uint16, c chan *RawPacket) {
_dispatcher.Lock()
_dispatcher.queues[qid] = c
_dispatcher.Unlock()
} | go | func register(qid uint16, c chan *RawPacket) {
_dispatcher.Lock()
_dispatcher.queues[qid] = c
_dispatcher.Unlock()
} | [
"func",
"register",
"(",
"qid",
"uint16",
",",
"c",
"chan",
"*",
"RawPacket",
")",
"{",
"_dispatcher",
".",
"Lock",
"(",
")",
"\n",
"_dispatcher",
".",
"queues",
"[",
"qid",
"]",
"=",
"c",
"\n",
"_dispatcher",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // register registers a RawPacket channel associated with a queue_id. | [
"register",
"registers",
"a",
"RawPacket",
"channel",
"associated",
"with",
"a",
"queue_id",
"."
] | 37bf522904e242e4b820d9c52667937ea90e24f7 | https://github.com/kung-foo/freki/blob/37bf522904e242e4b820d9c52667937ea90e24f7/netfilter/dispatch.go#L20-L24 |
127,102 | kung-foo/freki | netfilter/dispatch.go | dispatch | func dispatch(qid uint16, packet *RawPacket) {
_dispatcher.RLock()
// TODO: what should happen when this blocks?
_dispatcher.queues[qid] <- packet
_dispatcher.RUnlock()
} | go | func dispatch(qid uint16, packet *RawPacket) {
_dispatcher.RLock()
// TODO: what should happen when this blocks?
_dispatcher.queues[qid] <- packet
_dispatcher.RUnlock()
} | [
"func",
"dispatch",
"(",
"qid",
"uint16",
",",
"packet",
"*",
"RawPacket",
")",
"{",
"_dispatcher",
".",
"RLock",
"(",
")",
"\n",
"// TODO: what should happen when this blocks?",
"_dispatcher",
".",
"queues",
"[",
"qid",
"]",
"<-",
"packet",
"\n",
"_dispatcher",... | // dispatch routes the RawPacket to the correct handler. | [
"dispatch",
"routes",
"the",
"RawPacket",
"to",
"the",
"correct",
"handler",
"."
] | 37bf522904e242e4b820d9c52667937ea90e24f7 | https://github.com/kung-foo/freki/blob/37bf522904e242e4b820d9c52667937ea90e24f7/netfilter/dispatch.go#L27-L32 |
127,103 | d4l3k/messagediff | messagediff.go | PrettyDiff | func PrettyDiff(a, b interface{}, options ...Option) (string, bool) {
d, equal := DeepDiff(a, b, options...)
var dstr []string
for path, added := range d.Added {
dstr = append(dstr, fmt.Sprintf("added: %s = %#v\n", path.String(), added))
}
for path, removed := range d.Removed {
dstr = append(dstr, fmt.Sprintf(... | go | func PrettyDiff(a, b interface{}, options ...Option) (string, bool) {
d, equal := DeepDiff(a, b, options...)
var dstr []string
for path, added := range d.Added {
dstr = append(dstr, fmt.Sprintf("added: %s = %#v\n", path.String(), added))
}
for path, removed := range d.Removed {
dstr = append(dstr, fmt.Sprintf(... | [
"func",
"PrettyDiff",
"(",
"a",
",",
"b",
"interface",
"{",
"}",
",",
"options",
"...",
"Option",
")",
"(",
"string",
",",
"bool",
")",
"{",
"d",
",",
"equal",
":=",
"DeepDiff",
"(",
"a",
",",
"b",
",",
"options",
"...",
")",
"\n",
"var",
"dstr",... | // PrettyDiff does a deep comparison and returns the nicely formated results.
// See DeepDiff for more details. | [
"PrettyDiff",
"does",
"a",
"deep",
"comparison",
"and",
"returns",
"the",
"nicely",
"formated",
"results",
".",
"See",
"DeepDiff",
"for",
"more",
"details",
"."
] | b9e99b2f9263a86c71c1ca4507f34502448c58a4 | https://github.com/d4l3k/messagediff/blob/b9e99b2f9263a86c71c1ca4507f34502448c58a4/messagediff.go#L14-L28 |
127,104 | d4l3k/messagediff | messagediff.go | DeepDiff | func DeepDiff(a, b interface{}, options ...Option) (*Diff, bool) {
d := newDiff()
opts := &opts{}
for _, o := range options {
o.apply(opts)
}
return d, d.diff(reflect.ValueOf(a), reflect.ValueOf(b), nil, opts)
} | go | func DeepDiff(a, b interface{}, options ...Option) (*Diff, bool) {
d := newDiff()
opts := &opts{}
for _, o := range options {
o.apply(opts)
}
return d, d.diff(reflect.ValueOf(a), reflect.ValueOf(b), nil, opts)
} | [
"func",
"DeepDiff",
"(",
"a",
",",
"b",
"interface",
"{",
"}",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Diff",
",",
"bool",
")",
"{",
"d",
":=",
"newDiff",
"(",
")",
"\n",
"opts",
":=",
"&",
"opts",
"{",
"}",
"\n",
"for",
"_",
",",
"o... | // DeepDiff does a deep comparison and returns the results.
// If the field is time.Time, use Equal to compare | [
"DeepDiff",
"does",
"a",
"deep",
"comparison",
"and",
"returns",
"the",
"results",
".",
"If",
"the",
"field",
"is",
"time",
".",
"Time",
"use",
"Equal",
"to",
"compare"
] | b9e99b2f9263a86c71c1ca4507f34502448c58a4 | https://github.com/d4l3k/messagediff/blob/b9e99b2f9263a86c71c1ca4507f34502448c58a4/messagediff.go#L32-L39 |
127,105 | papertrail/go-tail | main.go | init | func init() {
flag.Int64VarP(&number, "number", "n", 10, "how many lines to return")
flag.BoolVarP(&follow, "follow", "f", false, "follow file changes")
flag.BoolVarP(&reopen, "reopen", "F", false, "implies -f and re-opens moved / truncated files")
} | go | func init() {
flag.Int64VarP(&number, "number", "n", 10, "how many lines to return")
flag.BoolVarP(&follow, "follow", "f", false, "follow file changes")
flag.BoolVarP(&reopen, "reopen", "F", false, "implies -f and re-opens moved / truncated files")
} | [
"func",
"init",
"(",
")",
"{",
"flag",
".",
"Int64VarP",
"(",
"&",
"number",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"10",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"BoolVarP",
"(",
"&",
"follow",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",... | // "number" and "follow" are ignored for now, since the follower is the only behavior
// until reading the end of the file is implemented | [
"number",
"and",
"follow",
"are",
"ignored",
"for",
"now",
"since",
"the",
"follower",
"is",
"the",
"only",
"behavior",
"until",
"reading",
"the",
"end",
"of",
"the",
"file",
"is",
"implemented"
] | 973c153b04319fc4604d847b09861a5730cbbde2 | https://github.com/papertrail/go-tail/blob/973c153b04319fc4604d847b09861a5730cbbde2/main.go#L20-L24 |
127,106 | cnf/structhash | structhash.go | Version | func Version(h string) int {
if h == "" {
return -1
}
if h[0] != 'v' {
return -1
}
if spos := strings.IndexRune(h[1:], '_'); spos >= 0 {
n, e := strconv.Atoi(h[1 : spos+1])
if e != nil {
return -1
}
return n
}
return -1
} | go | func Version(h string) int {
if h == "" {
return -1
}
if h[0] != 'v' {
return -1
}
if spos := strings.IndexRune(h[1:], '_'); spos >= 0 {
n, e := strconv.Atoi(h[1 : spos+1])
if e != nil {
return -1
}
return n
}
return -1
} | [
"func",
"Version",
"(",
"h",
"string",
")",
"int",
"{",
"if",
"h",
"==",
"\"",
"\"",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"if",
"h",
"[",
"0",
"]",
"!=",
"'v'",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"if",
"spos",
":=",
"strings",
"... | // Version returns the version of the supplied hash as an integer
// or -1 on failure | [
"Version",
"returns",
"the",
"version",
"of",
"the",
"supplied",
"hash",
"as",
"an",
"integer",
"or",
"-",
"1",
"on",
"failure"
] | 62a607eb02243845670f25a61cbc2d394c1ede10 | https://github.com/cnf/structhash/blob/62a607eb02243845670f25a61cbc2d394c1ede10/structhash.go#L16-L31 |
127,107 | gocraft/health | stack/frame.go | NewFrame | func NewFrame(pc uintptr) Frame {
frame := Frame{ProgramCounter: pc}
if frame.Func() == nil {
return frame
}
frame.Package, frame.Name = packageAndName(frame.Func())
// pc -1 because the program counters we use are usually return addresses,
// and we want to show the line that corresponds to the function call
... | go | func NewFrame(pc uintptr) Frame {
frame := Frame{ProgramCounter: pc}
if frame.Func() == nil {
return frame
}
frame.Package, frame.Name = packageAndName(frame.Func())
// pc -1 because the program counters we use are usually return addresses,
// and we want to show the line that corresponds to the function call
... | [
"func",
"NewFrame",
"(",
"pc",
"uintptr",
")",
"Frame",
"{",
"frame",
":=",
"Frame",
"{",
"ProgramCounter",
":",
"pc",
"}",
"\n",
"if",
"frame",
".",
"Func",
"(",
")",
"==",
"nil",
"{",
"return",
"frame",
"\n",
"}",
"\n",
"frame",
".",
"Package",
"... | // NewFrame popoulates a stack frame object from the program counter. | [
"NewFrame",
"popoulates",
"a",
"stack",
"frame",
"object",
"from",
"the",
"program",
"counter",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/stack/frame.go#L22-L35 |
127,108 | gocraft/health | healthd/debouncer.go | debouncer | func debouncer(doit chan<- struct{}, needitdone <-chan struct{}, threshold time.Duration, sleepTime time.Duration) {
var oldestNeedItDone time.Time
for {
select {
case <-needitdone:
if oldestNeedItDone.IsZero() {
oldestNeedItDone = now()
}
default:
// This sleep time is the max error that we'll be... | go | func debouncer(doit chan<- struct{}, needitdone <-chan struct{}, threshold time.Duration, sleepTime time.Duration) {
var oldestNeedItDone time.Time
for {
select {
case <-needitdone:
if oldestNeedItDone.IsZero() {
oldestNeedItDone = now()
}
default:
// This sleep time is the max error that we'll be... | [
"func",
"debouncer",
"(",
"doit",
"chan",
"<-",
"struct",
"{",
"}",
",",
"needitdone",
"<-",
"chan",
"struct",
"{",
"}",
",",
"threshold",
"time",
".",
"Duration",
",",
"sleepTime",
"time",
".",
"Duration",
")",
"{",
"var",
"oldestNeedItDone",
"time",
".... | // A) don't fire more than every 2 seconds B) the time between an input and output should be at most 2 seconds | [
"A",
")",
"don",
"t",
"fire",
"more",
"than",
"every",
"2",
"seconds",
"B",
")",
"the",
"time",
"between",
"an",
"input",
"and",
"output",
"should",
"be",
"at",
"most",
"2",
"seconds"
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/debouncer.go#L8-L27 |
127,109 | gocraft/health | stack/stack.go | Stack | func (t *Trace) Stack() []byte {
buf := bytes.Buffer{}
for _, frame := range t.Frames() {
buf.WriteString(frame.String())
buf.WriteRune('\n')
}
return buf.Bytes()
} | go | func (t *Trace) Stack() []byte {
buf := bytes.Buffer{}
for _, frame := range t.Frames() {
buf.WriteString(frame.String())
buf.WriteRune('\n')
}
return buf.Bytes()
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"Stack",
"(",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"for",
"_",
",",
"frame",
":=",
"range",
"t",
".",
"Frames",
"(",
")",
"{",
"buf",
".",
"WriteString",
"(",
... | // Stack returns a formatted callstack. | [
"Stack",
"returns",
"a",
"formatted",
"callstack",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/stack/stack.go#L38-L47 |
127,110 | gocraft/health | healthd/healthd.go | shouldStop | func (hd *HealthD) shouldStop() bool {
v := atomic.LoadInt64(&hd.stopFlag)
return v == 1
} | go | func (hd *HealthD) shouldStop() bool {
v := atomic.LoadInt64(&hd.stopFlag)
return v == 1
} | [
"func",
"(",
"hd",
"*",
"HealthD",
")",
"shouldStop",
"(",
")",
"bool",
"{",
"v",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"hd",
".",
"stopFlag",
")",
"\n",
"return",
"v",
"==",
"1",
"\n",
"}"
] | // shouldStop returns true if we've been flagged to stop | [
"shouldStop",
"returns",
"true",
"if",
"we",
"ve",
"been",
"flagged",
"to",
"stop"
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/healthd.go#L103-L106 |
127,111 | gocraft/health | healthd/healthd.go | poll | func (hd *HealthD) poll(responses chan *pollResponse) {
var wg sync.WaitGroup
for _, hs := range hd.hostStatus {
wg.Add(1)
go func(hs *HostStatus) {
defer wg.Done()
poll(hd.stream, hs.HostPort, responses)
}(hs)
}
wg.Wait()
responses <- nil
} | go | func (hd *HealthD) poll(responses chan *pollResponse) {
var wg sync.WaitGroup
for _, hs := range hd.hostStatus {
wg.Add(1)
go func(hs *HostStatus) {
defer wg.Done()
poll(hd.stream, hs.HostPort, responses)
}(hs)
}
wg.Wait()
responses <- nil
} | [
"func",
"(",
"hd",
"*",
"HealthD",
")",
"poll",
"(",
"responses",
"chan",
"*",
"pollResponse",
")",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"_",
",",
"hs",
":=",
"range",
"hd",
".",
"hostStatus",
"{",
"wg",
".",
"Add",
"(",
"1",
... | // poll is meant to be alled in a new goroutine.
// It will poll each managed host in a new goroutine.
// When everything has finished, it will send nil to responses to signal that we have all data. | [
"poll",
"is",
"meant",
"to",
"be",
"alled",
"in",
"a",
"new",
"goroutine",
".",
"It",
"will",
"poll",
"each",
"managed",
"host",
"in",
"a",
"new",
"goroutine",
".",
"When",
"everything",
"has",
"finished",
"it",
"will",
"send",
"nil",
"to",
"responses",
... | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/healthd.go#L161-L172 |
127,112 | gocraft/health | healthd/healthd.go | purge | func (agg *HealthD) purge() {
var threshold = agg.intervalDuration * 5 // NOTE: this is arbitrary.
for k, _ := range agg.hostAggregations {
if time.Since(k.Time) > threshold {
delete(agg.hostAggregations, k)
}
}
n := len(agg.intervalAggregations)
if n > agg.maxIntervals {
agg.intervalAggregations = agg.i... | go | func (agg *HealthD) purge() {
var threshold = agg.intervalDuration * 5 // NOTE: this is arbitrary.
for k, _ := range agg.hostAggregations {
if time.Since(k.Time) > threshold {
delete(agg.hostAggregations, k)
}
}
n := len(agg.intervalAggregations)
if n > agg.maxIntervals {
agg.intervalAggregations = agg.i... | [
"func",
"(",
"agg",
"*",
"HealthD",
")",
"purge",
"(",
")",
"{",
"var",
"threshold",
"=",
"agg",
".",
"intervalDuration",
"*",
"5",
"// NOTE: this is arbitrary.",
"\n",
"for",
"k",
",",
"_",
":=",
"range",
"agg",
".",
"hostAggregations",
"{",
"if",
"time... | // purge purges old hostAggregations older than 5 intervals | [
"purge",
"purges",
"old",
"hostAggregations",
"older",
"than",
"5",
"intervals"
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/healthd.go#L266-L278 |
127,113 | gocraft/health | interval_aggregation_clone.go | Clone | func (ia *IntervalAggregation) Clone() *IntervalAggregation {
dup := &IntervalAggregation{}
dup.IntervalStart = ia.IntervalStart
dup.SerialNumber = ia.SerialNumber
dup.aggregationMaps = *ia.aggregationMaps.Clone()
dup.Jobs = make(map[string]*JobAggregation)
for k, v := range ia.Jobs {
dup.Jobs[k] = v.Clone()
... | go | func (ia *IntervalAggregation) Clone() *IntervalAggregation {
dup := &IntervalAggregation{}
dup.IntervalStart = ia.IntervalStart
dup.SerialNumber = ia.SerialNumber
dup.aggregationMaps = *ia.aggregationMaps.Clone()
dup.Jobs = make(map[string]*JobAggregation)
for k, v := range ia.Jobs {
dup.Jobs[k] = v.Clone()
... | [
"func",
"(",
"ia",
"*",
"IntervalAggregation",
")",
"Clone",
"(",
")",
"*",
"IntervalAggregation",
"{",
"dup",
":=",
"&",
"IntervalAggregation",
"{",
"}",
"\n",
"dup",
".",
"IntervalStart",
"=",
"ia",
".",
"IntervalStart",
"\n",
"dup",
".",
"SerialNumber",
... | // Clone does a deep clone of ia, duplicating all maps and whatnot. | [
"Clone",
"does",
"a",
"deep",
"clone",
"of",
"ia",
"duplicating",
"all",
"maps",
"and",
"whatnot",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/interval_aggregation_clone.go#L4-L16 |
127,114 | gocraft/health | cmd/healthtop/jobs.go | filterJobsByName | func filterJobsByName(resp *healthd.ApiResponseJobs, name string) {
filteredSlice := []*healthd.Job{}
for _, job := range resp.Jobs {
if strings.Contains(job.Name, name) {
filteredSlice = append(filteredSlice, job)
}
}
resp.Jobs = filteredSlice
} | go | func filterJobsByName(resp *healthd.ApiResponseJobs, name string) {
filteredSlice := []*healthd.Job{}
for _, job := range resp.Jobs {
if strings.Contains(job.Name, name) {
filteredSlice = append(filteredSlice, job)
}
}
resp.Jobs = filteredSlice
} | [
"func",
"filterJobsByName",
"(",
"resp",
"*",
"healthd",
".",
"ApiResponseJobs",
",",
"name",
"string",
")",
"{",
"filteredSlice",
":=",
"[",
"]",
"*",
"healthd",
".",
"Job",
"{",
"}",
"\n\n",
"for",
"_",
",",
"job",
":=",
"range",
"resp",
".",
"Jobs",... | // Given the api response, remove any job entries that don't have 'name' in them. | [
"Given",
"the",
"api",
"response",
"remove",
"any",
"job",
"entries",
"that",
"don",
"t",
"have",
"name",
"in",
"them",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/cmd/healthtop/jobs.go#L96-L106 |
127,115 | gocraft/health | interval_aggregation_merge.go | Merge | func (ia *IntervalAggregation) Merge(intAgg *IntervalAggregation) {
ia.aggregationMaps.merge(&intAgg.aggregationMaps)
for k, v := range intAgg.Jobs {
if existingJob, ok := ia.Jobs[k]; ok {
existingJob.merge(v)
} else {
ia.Jobs[k] = v.Clone()
}
}
ia.SerialNumber++
} | go | func (ia *IntervalAggregation) Merge(intAgg *IntervalAggregation) {
ia.aggregationMaps.merge(&intAgg.aggregationMaps)
for k, v := range intAgg.Jobs {
if existingJob, ok := ia.Jobs[k]; ok {
existingJob.merge(v)
} else {
ia.Jobs[k] = v.Clone()
}
}
ia.SerialNumber++
} | [
"func",
"(",
"ia",
"*",
"IntervalAggregation",
")",
"Merge",
"(",
"intAgg",
"*",
"IntervalAggregation",
")",
"{",
"ia",
".",
"aggregationMaps",
".",
"merge",
"(",
"&",
"intAgg",
".",
"aggregationMaps",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"i... | // Merge merges intAgg into ia, mutating ia.
// Requires that ia and intAgg are a fully valid with no nil maps. | [
"Merge",
"merges",
"intAgg",
"into",
"ia",
"mutating",
"ia",
".",
"Requires",
"that",
"ia",
"and",
"intAgg",
"are",
"a",
"fully",
"valid",
"with",
"no",
"nil",
"maps",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/interval_aggregation_merge.go#L5-L17 |
127,116 | gocraft/health | healthd/poll.go | poll | func poll(stream *health.Stream, hostPort string, responses chan<- *pollResponse) {
job := stream.NewJob("poll")
var body []byte
var err error
response := &pollResponse{
HostPort: hostPort,
Timestamp: now(),
}
start := time.Now()
client := &http.Client{
Timeout: 5 * time.Second,
}
resp, err := clie... | go | func poll(stream *health.Stream, hostPort string, responses chan<- *pollResponse) {
job := stream.NewJob("poll")
var body []byte
var err error
response := &pollResponse{
HostPort: hostPort,
Timestamp: now(),
}
start := time.Now()
client := &http.Client{
Timeout: 5 * time.Second,
}
resp, err := clie... | [
"func",
"poll",
"(",
"stream",
"*",
"health",
".",
"Stream",
",",
"hostPort",
"string",
",",
"responses",
"chan",
"<-",
"*",
"pollResponse",
")",
"{",
"job",
":=",
"stream",
".",
"NewJob",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"body",
"[",
"]",
"byte"... | // poll checks a server | [
"poll",
"checks",
"a",
"server"
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/poll.go#L23-L70 |
127,117 | gocraft/health | sinks/bugsnag/api.go | Notify | func Notify(config *Config, jobName string, eventName string, err error, trace *stack.Trace, kvs map[string]string) error {
// Make a struct that serializes to the JSON needed for the API request to bugsnag
p := newPayload(config, jobName, eventName, err, trace, kvs)
// JSON serialize it
data, err := json.Marshal... | go | func Notify(config *Config, jobName string, eventName string, err error, trace *stack.Trace, kvs map[string]string) error {
// Make a struct that serializes to the JSON needed for the API request to bugsnag
p := newPayload(config, jobName, eventName, err, trace, kvs)
// JSON serialize it
data, err := json.Marshal... | [
"func",
"Notify",
"(",
"config",
"*",
"Config",
",",
"jobName",
"string",
",",
"eventName",
"string",
",",
"err",
"error",
",",
"trace",
"*",
"stack",
".",
"Trace",
",",
"kvs",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"// Make a struct tha... | // Notify will send the error and stack trace to Bugsnag. Note that this doesn't take advantage of all of Bugsnag's capabilities. | [
"Notify",
"will",
"send",
"the",
"error",
"and",
"stack",
"trace",
"to",
"Bugsnag",
".",
"Note",
"that",
"this",
"doesn",
"t",
"take",
"advantage",
"of",
"all",
"of",
"Bugsnag",
"s",
"capabilities",
"."
] | 8675af27fef0dc5c973d0957f1b1b50ffac513f9 | https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/sinks/bugsnag/api.go#L98-L124 |
127,118 | fukata/golang-stats-api-handler | handler.go | Handler | func Handler(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
for _, c := range []string{"1", "true"} {
if values.Get("pp") == c {
prettyPrint = true
}
}
var jsonBytes []byte
var jsonErr error
if prettyPrint {
jsonBytes, jsonErr = json.MarshalIndent(GetStats(), "", " ")
} else {
jso... | go | func Handler(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
for _, c := range []string{"1", "true"} {
if values.Get("pp") == c {
prettyPrint = true
}
}
var jsonBytes []byte
var jsonErr error
if prettyPrint {
jsonBytes, jsonErr = json.MarshalIndent(GetStats(), "", " ")
} else {
jso... | [
"func",
"Handler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"values",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\""... | // Handler returns activity status of Go. | [
"Handler",
"returns",
"activity",
"status",
"of",
"Go",
"."
] | ab9f90f16caab828afda479fd34bfbbbba2efcee | https://github.com/fukata/golang-stats-api-handler/blob/ab9f90f16caab828afda479fd34bfbbbba2efcee/handler.go#L160-L200 |
127,119 | jetstack/vault-unsealer | pkg/vault/vault.go | New | func New(k kv.Service, cl *api.Client, config Config) (Vault, error) {
if config.SecretShares < config.SecretThreshold {
return nil, errors.New("the secret threshold can't be bigger than the shares")
}
return &vault{
keyStore: k,
cl: cl,
config: &config,
}, nil
} | go | func New(k kv.Service, cl *api.Client, config Config) (Vault, error) {
if config.SecretShares < config.SecretThreshold {
return nil, errors.New("the secret threshold can't be bigger than the shares")
}
return &vault{
keyStore: k,
cl: cl,
config: &config,
}, nil
} | [
"func",
"New",
"(",
"k",
"kv",
".",
"Service",
",",
"cl",
"*",
"api",
".",
"Client",
",",
"config",
"Config",
")",
"(",
"Vault",
",",
"error",
")",
"{",
"if",
"config",
".",
"SecretShares",
"<",
"config",
".",
"SecretThreshold",
"{",
"return",
"nil",... | // New returns a new vault Vault, or an error. | [
"New",
"returns",
"a",
"new",
"vault",
"Vault",
"or",
"an",
"error",
"."
] | 59b05dd56dd01367f28666c577bdaeadc212e5c8 | https://github.com/jetstack/vault-unsealer/blob/59b05dd56dd01367f28666c577bdaeadc212e5c8/pkg/vault/vault.go#L53-L64 |
127,120 | tchap/go-patricia | patricia/patricia.go | NewTrie | func NewTrie(options ...Option) *Trie {
trie := &Trie{}
for _, opt := range options {
opt(trie)
}
if trie.maxPrefixPerNode <= 0 {
trie.maxPrefixPerNode = DefaultMaxPrefixPerNode
}
if trie.maxChildrenPerSparseNode <= 0 {
trie.maxChildrenPerSparseNode = DefaultMaxChildrenPerSparseNode
}
trie.children = n... | go | func NewTrie(options ...Option) *Trie {
trie := &Trie{}
for _, opt := range options {
opt(trie)
}
if trie.maxPrefixPerNode <= 0 {
trie.maxPrefixPerNode = DefaultMaxPrefixPerNode
}
if trie.maxChildrenPerSparseNode <= 0 {
trie.maxChildrenPerSparseNode = DefaultMaxChildrenPerSparseNode
}
trie.children = n... | [
"func",
"NewTrie",
"(",
"options",
"...",
"Option",
")",
"*",
"Trie",
"{",
"trie",
":=",
"&",
"Trie",
"{",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"options",
"{",
"opt",
"(",
"trie",
")",
"\n",
"}",
"\n\n",
"if",
"trie",
".",
"maxPref... | // Trie constructor. | [
"Trie",
"constructor",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L50-L66 |
127,121 | tchap/go-patricia | patricia/patricia.go | Clone | func (trie *Trie) Clone() *Trie {
return &Trie{
prefix: append(Prefix(nil), trie.prefix...),
item: trie.item,
maxPrefixPerNode: trie.maxPrefixPerNode,
maxChildrenPerSparseNode: trie.maxChildrenPerSparseNode,
children: trie.children.clone(),
}
} | go | func (trie *Trie) Clone() *Trie {
return &Trie{
prefix: append(Prefix(nil), trie.prefix...),
item: trie.item,
maxPrefixPerNode: trie.maxPrefixPerNode,
maxChildrenPerSparseNode: trie.maxChildrenPerSparseNode,
children: trie.children.clone(),
}
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Clone",
"(",
")",
"*",
"Trie",
"{",
"return",
"&",
"Trie",
"{",
"prefix",
":",
"append",
"(",
"Prefix",
"(",
"nil",
")",
",",
"trie",
".",
"prefix",
"...",
")",
",",
"item",
":",
"trie",
".",
"item",
",",... | // Clone makes a copy of an existing trie.
// Items stored in both tries become shared, obviously. | [
"Clone",
"makes",
"a",
"copy",
"of",
"an",
"existing",
"trie",
".",
"Items",
"stored",
"in",
"both",
"tries",
"become",
"shared",
"obviously",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L82-L90 |
127,122 | tchap/go-patricia | patricia/patricia.go | Insert | func (trie *Trie) Insert(key Prefix, item Item) (inserted bool) {
return trie.put(key, item, false)
} | go | func (trie *Trie) Insert(key Prefix, item Item) (inserted bool) {
return trie.put(key, item, false)
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Insert",
"(",
"key",
"Prefix",
",",
"item",
"Item",
")",
"(",
"inserted",
"bool",
")",
"{",
"return",
"trie",
".",
"put",
"(",
"key",
",",
"item",
",",
"false",
")",
"\n",
"}"
] | // Insert inserts a new item into the trie using the given prefix. Insert does
// not replace existing items. It returns false if an item was already in place. | [
"Insert",
"inserts",
"a",
"new",
"item",
"into",
"the",
"trie",
"using",
"the",
"given",
"prefix",
".",
"Insert",
"does",
"not",
"replace",
"existing",
"items",
".",
"It",
"returns",
"false",
"if",
"an",
"item",
"was",
"already",
"in",
"place",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L99-L101 |
127,123 | tchap/go-patricia | patricia/patricia.go | Set | func (trie *Trie) Set(key Prefix, item Item) {
trie.put(key, item, true)
} | go | func (trie *Trie) Set(key Prefix, item Item) {
trie.put(key, item, true)
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Set",
"(",
"key",
"Prefix",
",",
"item",
"Item",
")",
"{",
"trie",
".",
"put",
"(",
"key",
",",
"item",
",",
"true",
")",
"\n",
"}"
] | // Set works much like Insert, but it always sets the item, possibly replacing
// the item previously inserted. | [
"Set",
"works",
"much",
"like",
"Insert",
"but",
"it",
"always",
"sets",
"the",
"item",
"possibly",
"replacing",
"the",
"item",
"previously",
"inserted",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L105-L107 |
127,124 | tchap/go-patricia | patricia/patricia.go | Get | func (trie *Trie) Get(key Prefix) (item Item) {
_, node, found, leftover := trie.findSubtree(key)
if !found || len(leftover) != 0 {
return nil
}
return node.item
} | go | func (trie *Trie) Get(key Prefix) (item Item) {
_, node, found, leftover := trie.findSubtree(key)
if !found || len(leftover) != 0 {
return nil
}
return node.item
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Get",
"(",
"key",
"Prefix",
")",
"(",
"item",
"Item",
")",
"{",
"_",
",",
"node",
",",
"found",
",",
"leftover",
":=",
"trie",
".",
"findSubtree",
"(",
"key",
")",
"\n",
"if",
"!",
"found",
"||",
"len",
"... | // Get returns the item located at key.
//
// This method is a bit dangerous, because Get can as well end up in an internal
// node that is not really representing any user-defined value. So when nil is
// a valid value being used, it is not possible to tell if the value was inserted
// into the tree by the user or not... | [
"Get",
"returns",
"the",
"item",
"located",
"at",
"key",
".",
"This",
"method",
"is",
"a",
"bit",
"dangerous",
"because",
"Get",
"can",
"as",
"well",
"end",
"up",
"in",
"an",
"internal",
"node",
"that",
"is",
"not",
"really",
"representing",
"any",
"user... | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L117-L123 |
127,125 | tchap/go-patricia | patricia/patricia.go | MatchSubtree | func (trie *Trie) MatchSubtree(key Prefix) (matched bool) {
_, _, matched, _ = trie.findSubtree(key)
return
} | go | func (trie *Trie) MatchSubtree(key Prefix) (matched bool) {
_, _, matched, _ = trie.findSubtree(key)
return
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"MatchSubtree",
"(",
"key",
"Prefix",
")",
"(",
"matched",
"bool",
")",
"{",
"_",
",",
"_",
",",
"matched",
",",
"_",
"=",
"trie",
".",
"findSubtree",
"(",
"key",
")",
"\n",
"return",
"\n",
"}"
] | // MatchSubtree returns true when there is a subtree representing extensions
// to key, that is if there are any keys in the tree which have key as prefix. | [
"MatchSubtree",
"returns",
"true",
"when",
"there",
"is",
"a",
"subtree",
"representing",
"extensions",
"to",
"key",
"that",
"is",
"if",
"there",
"are",
"any",
"keys",
"in",
"the",
"tree",
"which",
"have",
"key",
"as",
"prefix",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L133-L136 |
127,126 | tchap/go-patricia | patricia/patricia.go | Visit | func (trie *Trie) Visit(visitor VisitorFunc) error {
return trie.walk(nil, visitor)
} | go | func (trie *Trie) Visit(visitor VisitorFunc) error {
return trie.walk(nil, visitor)
} | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Visit",
"(",
"visitor",
"VisitorFunc",
")",
"error",
"{",
"return",
"trie",
".",
"walk",
"(",
"nil",
",",
"visitor",
")",
"\n",
"}"
] | // Visit calls visitor on every node containing a non-nil item
// in alphabetical order.
//
// If an error is returned from visitor, the function stops visiting the tree
// and returns that error, unless it is a special error - SkipSubtree. In that
// case Visit skips the subtree represented by the current node and con... | [
"Visit",
"calls",
"visitor",
"on",
"every",
"node",
"containing",
"a",
"non",
"-",
"nil",
"item",
"in",
"alphabetical",
"order",
".",
"If",
"an",
"error",
"is",
"returned",
"from",
"visitor",
"the",
"function",
"stops",
"visiting",
"the",
"tree",
"and",
"r... | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L145-L147 |
127,127 | tchap/go-patricia | patricia/patricia.go | VisitSubtree | func (trie *Trie) VisitSubtree(prefix Prefix, visitor VisitorFunc) error {
// Nil prefix not allowed.
if prefix == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return nil
}
// Locate the relevant subtree.
_, root, found, leftover := trie.findSubtree(prefix)... | go | func (trie *Trie) VisitSubtree(prefix Prefix, visitor VisitorFunc) error {
// Nil prefix not allowed.
if prefix == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return nil
}
// Locate the relevant subtree.
_, root, found, leftover := trie.findSubtree(prefix)... | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"VisitSubtree",
"(",
"prefix",
"Prefix",
",",
"visitor",
"VisitorFunc",
")",
"error",
"{",
"// Nil prefix not allowed.",
"if",
"prefix",
"==",
"nil",
"{",
"panic",
"(",
"ErrNilPrefix",
")",
"\n",
"}",
"\n\n",
"// Empty ... | // VisitSubtree works much like Visit, but it only visits nodes matching prefix. | [
"VisitSubtree",
"works",
"much",
"like",
"Visit",
"but",
"it",
"only",
"visits",
"nodes",
"matching",
"prefix",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L165-L185 |
127,128 | tchap/go-patricia | patricia/patricia.go | VisitPrefixes | func (trie *Trie) VisitPrefixes(key Prefix, visitor VisitorFunc) error {
// Nil key not allowed.
if key == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return nil
}
// Walk the path matching key prefixes.
node := trie
prefix := key
offset := 0
for {
//... | go | func (trie *Trie) VisitPrefixes(key Prefix, visitor VisitorFunc) error {
// Nil key not allowed.
if key == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return nil
}
// Walk the path matching key prefixes.
node := trie
prefix := key
offset := 0
for {
//... | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"VisitPrefixes",
"(",
"key",
"Prefix",
",",
"visitor",
"VisitorFunc",
")",
"error",
"{",
"// Nil key not allowed.",
"if",
"key",
"==",
"nil",
"{",
"panic",
"(",
"ErrNilPrefix",
")",
"\n",
"}",
"\n\n",
"// Empty trie mus... | // VisitPrefixes visits only nodes that represent prefixes of key.
// To say the obvious, returning SkipSubtree from visitor makes no sense here. | [
"VisitPrefixes",
"visits",
"only",
"nodes",
"that",
"represent",
"prefixes",
"of",
"key",
".",
"To",
"say",
"the",
"obvious",
"returning",
"SkipSubtree",
"from",
"visitor",
"makes",
"no",
"sense",
"here",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L189-L236 |
127,129 | tchap/go-patricia | patricia/patricia.go | Delete | func (trie *Trie) Delete(key Prefix) (deleted bool) {
// Nil prefix not allowed.
if key == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return false
}
// Find the relevant node.
path, found, _ := trie.findSubtreePath(key)
if !found {
return false
}
no... | go | func (trie *Trie) Delete(key Prefix) (deleted bool) {
// Nil prefix not allowed.
if key == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return false
}
// Find the relevant node.
path, found, _ := trie.findSubtreePath(key)
if !found {
return false
}
no... | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"Delete",
"(",
"key",
"Prefix",
")",
"(",
"deleted",
"bool",
")",
"{",
"// Nil prefix not allowed.",
"if",
"key",
"==",
"nil",
"{",
"panic",
"(",
"ErrNilPrefix",
")",
"\n",
"}",
"\n\n",
"// Empty trie must be handled ex... | // Delete deletes the item represented by the given prefix.
//
// True is returned if the matching node was found and deleted. | [
"Delete",
"deletes",
"the",
"item",
"represented",
"by",
"the",
"given",
"prefix",
".",
"True",
"is",
"returned",
"if",
"the",
"matching",
"node",
"was",
"found",
"and",
"deleted",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L241-L329 |
127,130 | tchap/go-patricia | patricia/patricia.go | DeleteSubtree | func (trie *Trie) DeleteSubtree(prefix Prefix) (deleted bool) {
// Nil prefix not allowed.
if prefix == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return false
}
// Locate the relevant subtree.
parent, root, found, _ := trie.findSubtree(prefix)
if !found... | go | func (trie *Trie) DeleteSubtree(prefix Prefix) (deleted bool) {
// Nil prefix not allowed.
if prefix == nil {
panic(ErrNilPrefix)
}
// Empty trie must be handled explicitly.
if trie.prefix == nil {
return false
}
// Locate the relevant subtree.
parent, root, found, _ := trie.findSubtree(prefix)
if !found... | [
"func",
"(",
"trie",
"*",
"Trie",
")",
"DeleteSubtree",
"(",
"prefix",
"Prefix",
")",
"(",
"deleted",
"bool",
")",
"{",
"// Nil prefix not allowed.",
"if",
"prefix",
"==",
"nil",
"{",
"panic",
"(",
"ErrNilPrefix",
")",
"\n",
"}",
"\n\n",
"// Empty trie must ... | // DeleteSubtree finds the subtree exactly matching prefix and deletes it.
//
// True is returned if the subtree was found and deleted. | [
"DeleteSubtree",
"finds",
"the",
"subtree",
"exactly",
"matching",
"prefix",
"and",
"deletes",
"it",
".",
"True",
"is",
"returned",
"if",
"the",
"subtree",
"was",
"found",
"and",
"deleted",
"."
] | a7f0089c6f496e8e70402f61733606daa326cac5 | https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L334-L360 |
127,131 | vanng822/go-premailer | premailer/premailer_from_file.go | NewPremailerFromFile | func NewPremailerFromFile(filename string, options *Options) (Premailer, error) {
fd, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fd.Close()
d, err := goquery.NewDocumentFromReader(fd)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | go | func NewPremailerFromFile(filename string, options *Options) (Premailer, error) {
fd, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fd.Close()
d, err := goquery.NewDocumentFromReader(fd)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | [
"func",
"NewPremailerFromFile",
"(",
"filename",
"string",
",",
"options",
"*",
"Options",
")",
"(",
"Premailer",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // NewPremailerFromFile take an filename
// Read the content of this file
// and create a goquery.Document
// and then create and Premailer instance. | [
"NewPremailerFromFile",
"take",
"an",
"filename",
"Read",
"the",
"content",
"of",
"this",
"file",
"and",
"create",
"a",
"goquery",
".",
"Document",
"and",
"then",
"create",
"and",
"Premailer",
"instance",
"."
] | 5591781d799634cb6cf5363794f8df1eb4b8070c | https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_file.go#L13-L24 |
127,132 | vanng822/go-premailer | premailer/premailer_from_string.go | NewPremailerFromString | func NewPremailerFromString(doc string, options *Options) (Premailer, error) {
read := strings.NewReader(doc)
d, err := goquery.NewDocumentFromReader(read)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | go | func NewPremailerFromString(doc string, options *Options) (Premailer, error) {
read := strings.NewReader(doc)
d, err := goquery.NewDocumentFromReader(read)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | [
"func",
"NewPremailerFromString",
"(",
"doc",
"string",
",",
"options",
"*",
"Options",
")",
"(",
"Premailer",
",",
"error",
")",
"{",
"read",
":=",
"strings",
".",
"NewReader",
"(",
"doc",
")",
"\n",
"d",
",",
"err",
":=",
"goquery",
".",
"NewDocumentFr... | // NewPremailerFromString take in a document in string format
// and create a goquery.Document
// and then create and Premailer instance. | [
"NewPremailerFromString",
"take",
"in",
"a",
"document",
"in",
"string",
"format",
"and",
"create",
"a",
"goquery",
".",
"Document",
"and",
"then",
"create",
"and",
"Premailer",
"instance",
"."
] | 5591781d799634cb6cf5363794f8df1eb4b8070c | https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_string.go#L12-L19 |
127,133 | vanng822/go-premailer | premailer/premailer_from_bytes.go | NewPremailerFromBytes | func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error) {
read := bytes.NewReader(doc)
d, err := goquery.NewDocumentFromReader(read)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | go | func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error) {
read := bytes.NewReader(doc)
d, err := goquery.NewDocumentFromReader(read)
if err != nil {
return nil, err
}
return NewPremailer(d, options), nil
} | [
"func",
"NewPremailerFromBytes",
"(",
"doc",
"[",
"]",
"byte",
",",
"options",
"*",
"Options",
")",
"(",
"Premailer",
",",
"error",
")",
"{",
"read",
":=",
"bytes",
".",
"NewReader",
"(",
"doc",
")",
"\n",
"d",
",",
"err",
":=",
"goquery",
".",
"NewD... | // NewPremailerFromBytes take in a document in byte
// and create a goquery.Document
// and then create and Premailer instance. | [
"NewPremailerFromBytes",
"take",
"in",
"a",
"document",
"in",
"byte",
"and",
"create",
"a",
"goquery",
".",
"Document",
"and",
"then",
"create",
"and",
"Premailer",
"instance",
"."
] | 5591781d799634cb6cf5363794f8df1eb4b8070c | https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_bytes.go#L12-L19 |
127,134 | vanng822/go-premailer | premailer/premailer.go | NewPremailer | func NewPremailer(doc *goquery.Document, options *Options) Premailer {
pr := premailer{}
pr.doc = doc
pr.rules = make([]*styleRule, 0)
pr.allRules = make([][]*css.CSSRule, 0)
pr.leftover = make([]*css.CSSRule, 0)
pr.elements = make(map[string]*elementRules)
pr.elIdAttr = "pr-el-id"
if options == nil {
options... | go | func NewPremailer(doc *goquery.Document, options *Options) Premailer {
pr := premailer{}
pr.doc = doc
pr.rules = make([]*styleRule, 0)
pr.allRules = make([][]*css.CSSRule, 0)
pr.leftover = make([]*css.CSSRule, 0)
pr.elements = make(map[string]*elementRules)
pr.elIdAttr = "pr-el-id"
if options == nil {
options... | [
"func",
"NewPremailer",
"(",
"doc",
"*",
"goquery",
".",
"Document",
",",
"options",
"*",
"Options",
")",
"Premailer",
"{",
"pr",
":=",
"premailer",
"{",
"}",
"\n",
"pr",
".",
"doc",
"=",
"doc",
"\n",
"pr",
".",
"rules",
"=",
"make",
"(",
"[",
"]",... | // NewPremailer return a new instance of Premailer
// It take a Document as argument and it shouldn't be nil | [
"NewPremailer",
"return",
"a",
"new",
"instance",
"of",
"Premailer",
"It",
"take",
"a",
"Document",
"as",
"argument",
"and",
"it",
"shouldn",
"t",
"be",
"nil"
] | 5591781d799634cb6cf5363794f8df1eb4b8070c | https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer.go#L45-L58 |
127,135 | vanng822/go-premailer | premailer/premailer.go | Transform | func (pr *premailer) Transform() (string, error) {
if !pr.processed {
pr.collectRules()
pr.sortRules()
pr.collectElements()
pr.applyInline()
pr.addLeftover()
pr.processed = true
}
return pr.doc.Html()
} | go | func (pr *premailer) Transform() (string, error) {
if !pr.processed {
pr.collectRules()
pr.sortRules()
pr.collectElements()
pr.applyInline()
pr.addLeftover()
pr.processed = true
}
return pr.doc.Html()
} | [
"func",
"(",
"pr",
"*",
"premailer",
")",
"Transform",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"pr",
".",
"processed",
"{",
"pr",
".",
"collectRules",
"(",
")",
"\n",
"pr",
".",
"sortRules",
"(",
")",
"\n",
"pr",
".",
"collect... | // Transform process and inlining css
// It start to collect the rules in the document style tags
// Calculate specificity and sort the rules based on that
// It then collects the affected elements
// And applies the rules on those
// The leftover rules will put back into a style element | [
"Transform",
"process",
"and",
"inlining",
"css",
"It",
"start",
"to",
"collect",
"the",
"rules",
"in",
"the",
"document",
"style",
"tags",
"Calculate",
"specificity",
"and",
"sort",
"the",
"rules",
"based",
"on",
"that",
"It",
"then",
"collects",
"the",
"af... | 5591781d799634cb6cf5363794f8df1eb4b8070c | https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer.go#L199-L209 |
127,136 | gobwas/httphead | httphead.go | String | func (f SelectFlag) String() string {
var flags [2]string
var n int
if f&SelectCopy != 0 {
flags[n] = "copy"
n++
}
if f&SelectUnique != 0 {
flags[n] = "unique"
n++
}
return "[" + strings.Join(flags[:n], "|") + "]"
} | go | func (f SelectFlag) String() string {
var flags [2]string
var n int
if f&SelectCopy != 0 {
flags[n] = "copy"
n++
}
if f&SelectUnique != 0 {
flags[n] = "unique"
n++
}
return "[" + strings.Join(flags[:n], "|") + "]"
} | [
"func",
"(",
"f",
"SelectFlag",
")",
"String",
"(",
")",
"string",
"{",
"var",
"flags",
"[",
"2",
"]",
"string",
"\n",
"var",
"n",
"int",
"\n",
"if",
"f",
"&",
"SelectCopy",
"!=",
"0",
"{",
"flags",
"[",
"n",
"]",
"=",
"\"",
"\"",
"\n",
"n",
... | // String represetns flag as string. | [
"String",
"represetns",
"flag",
"as",
"string",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/httphead.go#L66-L78 |
127,137 | gobwas/httphead | head.go | ParseResponseLine | func ParseResponseLine(line []byte) (r ResponseLine, ok bool) {
var (
proto []byte
status []byte
)
proto, status, r.Reason = split3(line, ' ')
if major, minor, ok := ParseVersion(proto); ok {
r.Version.Major = major
r.Version.Minor = minor
} else {
return r, false
}
if n, ok := IntFromASCII(status); o... | go | func ParseResponseLine(line []byte) (r ResponseLine, ok bool) {
var (
proto []byte
status []byte
)
proto, status, r.Reason = split3(line, ' ')
if major, minor, ok := ParseVersion(proto); ok {
r.Version.Major = major
r.Version.Minor = minor
} else {
return r, false
}
if n, ok := IntFromASCII(status); o... | [
"func",
"ParseResponseLine",
"(",
"line",
"[",
"]",
"byte",
")",
"(",
"r",
"ResponseLine",
",",
"ok",
"bool",
")",
"{",
"var",
"(",
"proto",
"[",
"]",
"byte",
"\n",
"status",
"[",
"]",
"byte",
"\n",
")",
"\n",
"proto",
",",
"status",
",",
"r",
".... | // ParseResponseLine parses first response line into ResponseLine struct. | [
"ParseResponseLine",
"parses",
"first",
"response",
"line",
"into",
"ResponseLine",
"struct",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L72-L93 |
127,138 | gobwas/httphead | head.go | ParseVersion | func ParseVersion(bts []byte) (major, minor int, ok bool) {
switch {
case bytes.Equal(bts, httpVersion11):
return 1, 1, true
case bytes.Equal(bts, httpVersion10):
return 1, 0, true
case len(bts) < 8:
return
case !bytes.Equal(bts[:5], httpVersionPrefix):
return
}
bts = bts[5:]
dot := bytes.IndexByte(bt... | go | func ParseVersion(bts []byte) (major, minor int, ok bool) {
switch {
case bytes.Equal(bts, httpVersion11):
return 1, 1, true
case bytes.Equal(bts, httpVersion10):
return 1, 0, true
case len(bts) < 8:
return
case !bytes.Equal(bts[:5], httpVersionPrefix):
return
}
bts = bts[5:]
dot := bytes.IndexByte(bt... | [
"func",
"ParseVersion",
"(",
"bts",
"[",
"]",
"byte",
")",
"(",
"major",
",",
"minor",
"int",
",",
"ok",
"bool",
")",
"{",
"switch",
"{",
"case",
"bytes",
".",
"Equal",
"(",
"bts",
",",
"httpVersion11",
")",
":",
"return",
"1",
",",
"1",
",",
"tr... | // ParseVersion parses major and minor version of HTTP protocol.
// It returns parsed values and true if parse is ok. | [
"ParseVersion",
"parses",
"major",
"and",
"minor",
"version",
"of",
"HTTP",
"protocol",
".",
"It",
"returns",
"parsed",
"values",
"and",
"true",
"if",
"parse",
"is",
"ok",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L103-L131 |
127,139 | gobwas/httphead | head.go | ParseHeaderLine | func ParseHeaderLine(line []byte) (k, v []byte, ok bool) {
colon := bytes.IndexByte(line, ':')
if colon == -1 {
return
}
k = trim(line[:colon])
for _, c := range k {
if !OctetTypes[c].IsToken() {
return nil, nil, false
}
}
v = trim(line[colon+1:])
return k, v, true
} | go | func ParseHeaderLine(line []byte) (k, v []byte, ok bool) {
colon := bytes.IndexByte(line, ':')
if colon == -1 {
return
}
k = trim(line[:colon])
for _, c := range k {
if !OctetTypes[c].IsToken() {
return nil, nil, false
}
}
v = trim(line[colon+1:])
return k, v, true
} | [
"func",
"ParseHeaderLine",
"(",
"line",
"[",
"]",
"byte",
")",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
",",
"ok",
"bool",
")",
"{",
"colon",
":=",
"bytes",
".",
"IndexByte",
"(",
"line",
",",
"':'",
")",
"\n",
"if",
"colon",
"==",
"-",
"1",
"{",
... | // ParseHeaderLine parses HTTP header as key-value pair. It returns parsed
// values and true if parse is ok. | [
"ParseHeaderLine",
"parses",
"HTTP",
"header",
"as",
"key",
"-",
"value",
"pair",
".",
"It",
"returns",
"parsed",
"values",
"and",
"true",
"if",
"parse",
"is",
"ok",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L180-L193 |
127,140 | gobwas/httphead | head.go | IntFromASCII | func IntFromASCII(bts []byte) (ret int, ok bool) {
// ASCII numbers all start with the high-order bits 0011.
// If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those
// bits and interpret them directly as an integer.
var n int
if n = len(bts); n < 1 {
return 0, false
}
for i := 0; i < n; ... | go | func IntFromASCII(bts []byte) (ret int, ok bool) {
// ASCII numbers all start with the high-order bits 0011.
// If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those
// bits and interpret them directly as an integer.
var n int
if n = len(bts); n < 1 {
return 0, false
}
for i := 0; i < n; ... | [
"func",
"IntFromASCII",
"(",
"bts",
"[",
"]",
"byte",
")",
"(",
"ret",
"int",
",",
"ok",
"bool",
")",
"{",
"// ASCII numbers all start with the high-order bits 0011.",
"// If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those",
"// bits and interpret them di... | // IntFromASCII converts ascii encoded decimal numeric value from HTTP entities
// to an integer. | [
"IntFromASCII",
"converts",
"ascii",
"encoded",
"decimal",
"numeric",
"value",
"from",
"HTTP",
"entities",
"to",
"an",
"integer",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L197-L212 |
127,141 | gobwas/httphead | option.go | Size | func (opt Option) Size() int {
return len(opt.Name) + opt.Parameters.bytes
} | go | func (opt Option) Size() int {
return len(opt.Name) + opt.Parameters.bytes
} | [
"func",
"(",
"opt",
"Option",
")",
"Size",
"(",
")",
"int",
"{",
"return",
"len",
"(",
"opt",
".",
"Name",
")",
"+",
"opt",
".",
"Parameters",
".",
"bytes",
"\n",
"}"
] | // Size returns number of bytes need to be allocated for use in opt.Copy. | [
"Size",
"returns",
"number",
"of",
"bytes",
"need",
"to",
"be",
"allocated",
"for",
"use",
"in",
"opt",
".",
"Copy",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L15-L17 |
127,142 | gobwas/httphead | option.go | String | func (opt Option) String() string {
return "{" + string(opt.Name) + " " + opt.Parameters.String() + "}"
} | go | func (opt Option) String() string {
return "{" + string(opt.Name) + " " + opt.Parameters.String() + "}"
} | [
"func",
"(",
"opt",
"Option",
")",
"String",
"(",
")",
"string",
"{",
"return",
"\"",
"\"",
"+",
"string",
"(",
"opt",
".",
"Name",
")",
"+",
"\"",
"\"",
"+",
"opt",
".",
"Parameters",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"}"
] | // String represents option as a string. | [
"String",
"represents",
"option",
"as",
"a",
"string",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L29-L31 |
127,143 | gobwas/httphead | option.go | NewOption | func NewOption(name string, params map[string]string) Option {
p := Parameters{}
for k, v := range params {
p.Set([]byte(k), []byte(v))
}
return Option{
Name: []byte(name),
Parameters: p,
}
} | go | func NewOption(name string, params map[string]string) Option {
p := Parameters{}
for k, v := range params {
p.Set([]byte(k), []byte(v))
}
return Option{
Name: []byte(name),
Parameters: p,
}
} | [
"func",
"NewOption",
"(",
"name",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"Option",
"{",
"p",
":=",
"Parameters",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"params",
"{",
"p",
".",
"Set",
"(",
"[",
"]",
"byte... | // NewOption creates named option with given parameters. | [
"NewOption",
"creates",
"named",
"option",
"with",
"given",
"parameters",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L34-L43 |
127,144 | gobwas/httphead | option.go | Equal | func (opt Option) Equal(b Option) bool {
if bytes.Equal(opt.Name, b.Name) {
return opt.Parameters.Equal(b.Parameters)
}
return false
} | go | func (opt Option) Equal(b Option) bool {
if bytes.Equal(opt.Name, b.Name) {
return opt.Parameters.Equal(b.Parameters)
}
return false
} | [
"func",
"(",
"opt",
"Option",
")",
"Equal",
"(",
"b",
"Option",
")",
"bool",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"opt",
".",
"Name",
",",
"b",
".",
"Name",
")",
"{",
"return",
"opt",
".",
"Parameters",
".",
"Equal",
"(",
"b",
".",
"Parameters"... | // Equal reports whether option is equal to b. | [
"Equal",
"reports",
"whether",
"option",
"is",
"equal",
"to",
"b",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L46-L51 |
127,145 | gobwas/httphead | option.go | Equal | func (p Parameters) Equal(b Parameters) bool {
switch {
case p.dyn == nil && b.dyn == nil:
case p.dyn != nil && b.dyn != nil:
default:
return false
}
ad, bd := p.data(), b.data()
if len(ad) != len(bd) {
return false
}
sort.Sort(pairs(ad))
sort.Sort(pairs(bd))
for i := 0; i < len(ad); i++ {
av, bv :=... | go | func (p Parameters) Equal(b Parameters) bool {
switch {
case p.dyn == nil && b.dyn == nil:
case p.dyn != nil && b.dyn != nil:
default:
return false
}
ad, bd := p.data(), b.data()
if len(ad) != len(bd) {
return false
}
sort.Sort(pairs(ad))
sort.Sort(pairs(bd))
for i := 0; i < len(ad); i++ {
av, bv :=... | [
"func",
"(",
"p",
"Parameters",
")",
"Equal",
"(",
"b",
"Parameters",
")",
"bool",
"{",
"switch",
"{",
"case",
"p",
".",
"dyn",
"==",
"nil",
"&&",
"b",
".",
"dyn",
"==",
"nil",
":",
"case",
"p",
".",
"dyn",
"!=",
"nil",
"&&",
"b",
".",
"dyn",
... | // Equal reports whether a equal to b. | [
"Equal",
"reports",
"whether",
"a",
"equal",
"to",
"b",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L62-L85 |
127,146 | gobwas/httphead | option.go | Get | func (p *Parameters) Get(key string) (value []byte, ok bool) {
for _, v := range p.data() {
if string(v.key) == key {
return v.value, true
}
}
return nil, false
} | go | func (p *Parameters) Get(key string) (value []byte, ok bool) {
for _, v := range p.data() {
if string(v.key) == key {
return v.value, true
}
}
return nil, false
} | [
"func",
"(",
"p",
"*",
"Parameters",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"value",
"[",
"]",
"byte",
",",
"ok",
"bool",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"p",
".",
"data",
"(",
")",
"{",
"if",
"string",
"(",
"v",
".",
"k... | // Get returns value by key and flag about existence such value. | [
"Get",
"returns",
"value",
"by",
"key",
"and",
"flag",
"about",
"existence",
"such",
"value",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L114-L121 |
127,147 | gobwas/httphead | option.go | Set | func (p *Parameters) Set(key, value []byte) {
p.bytes += len(key) + len(value)
if p.pos < len(p.arr) {
p.arr[p.pos] = pair{key, value}
p.pos++
return
}
if p.dyn == nil {
p.dyn = make([]pair, len(p.arr), len(p.arr)+1)
copy(p.dyn, p.arr[:])
}
p.dyn = append(p.dyn, pair{key, value})
} | go | func (p *Parameters) Set(key, value []byte) {
p.bytes += len(key) + len(value)
if p.pos < len(p.arr) {
p.arr[p.pos] = pair{key, value}
p.pos++
return
}
if p.dyn == nil {
p.dyn = make([]pair, len(p.arr), len(p.arr)+1)
copy(p.dyn, p.arr[:])
}
p.dyn = append(p.dyn, pair{key, value})
} | [
"func",
"(",
"p",
"*",
"Parameters",
")",
"Set",
"(",
"key",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"p",
".",
"bytes",
"+=",
"len",
"(",
"key",
")",
"+",
"len",
"(",
"value",
")",
"\n\n",
"if",
"p",
".",
"pos",
"<",
"len",
"(",
"p",
".",... | // Set sets value by key. | [
"Set",
"sets",
"value",
"by",
"key",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L124-L138 |
127,148 | gobwas/httphead | option.go | ForEach | func (p *Parameters) ForEach(cb func(k, v []byte) bool) {
for _, v := range p.data() {
if !cb(v.key, v.value) {
break
}
}
} | go | func (p *Parameters) ForEach(cb func(k, v []byte) bool) {
for _, v := range p.data() {
if !cb(v.key, v.value) {
break
}
}
} | [
"func",
"(",
"p",
"*",
"Parameters",
")",
"ForEach",
"(",
"cb",
"func",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
")",
"bool",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"p",
".",
"data",
"(",
")",
"{",
"if",
"!",
"cb",
"(",
"v",
".",
"ke... | // ForEach iterates over parameters key-value pairs and calls cb for each one. | [
"ForEach",
"iterates",
"over",
"parameters",
"key",
"-",
"value",
"pairs",
"and",
"calls",
"cb",
"for",
"each",
"one",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L141-L147 |
127,149 | gobwas/httphead | option.go | String | func (p *Parameters) String() (ret string) {
ret = "["
for i, v := range p.data() {
if i > 0 {
ret += " "
}
ret += string(v.key) + ":" + string(v.value)
}
return ret + "]"
} | go | func (p *Parameters) String() (ret string) {
ret = "["
for i, v := range p.data() {
if i > 0 {
ret += " "
}
ret += string(v.key) + ":" + string(v.value)
}
return ret + "]"
} | [
"func",
"(",
"p",
"*",
"Parameters",
")",
"String",
"(",
")",
"(",
"ret",
"string",
")",
"{",
"ret",
"=",
"\"",
"\"",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"p",
".",
"data",
"(",
")",
"{",
"if",
"i",
">",
"0",
"{",
"ret",
"+=",
"\"",
... | // String represents parameters as a string. | [
"String",
"represents",
"parameters",
"as",
"a",
"string",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L150-L159 |
127,150 | gobwas/httphead | cookie.go | Scan | func (c CookieScanner) Scan(data []byte, it func(name, value []byte) bool) bool {
lexer := &Scanner{data: data}
const (
statePair = iota
stateBefore
)
state := statePair
for lexer.Buffered() > 0 {
switch state {
case stateBefore:
// Pairs separated by ";" and space, according to the RFC6265:
// ... | go | func (c CookieScanner) Scan(data []byte, it func(name, value []byte) bool) bool {
lexer := &Scanner{data: data}
const (
statePair = iota
stateBefore
)
state := statePair
for lexer.Buffered() > 0 {
switch state {
case stateBefore:
// Pairs separated by ";" and space, according to the RFC6265:
// ... | [
"func",
"(",
"c",
"CookieScanner",
")",
"Scan",
"(",
"data",
"[",
"]",
"byte",
",",
"it",
"func",
"(",
"name",
",",
"value",
"[",
"]",
"byte",
")",
"bool",
")",
"bool",
"{",
"lexer",
":=",
"&",
"Scanner",
"{",
"data",
":",
"data",
"}",
"\n\n",
... | // Scan maps data to name and value pairs. Usually data represents value of the
// Cookie header. | [
"Scan",
"maps",
"data",
"to",
"name",
"and",
"value",
"pairs",
".",
"Usually",
"data",
"represents",
"value",
"of",
"the",
"Cookie",
"header",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/cookie.go#L49-L131 |
127,151 | gobwas/httphead | cookie.go | ValidCookieName | func ValidCookieName(name []byte) bool {
for _, c := range name {
if !OctetTypes[c].IsToken() {
return false
}
}
return true
} | go | func ValidCookieName(name []byte) bool {
for _, c := range name {
if !OctetTypes[c].IsToken() {
return false
}
}
return true
} | [
"func",
"ValidCookieName",
"(",
"name",
"[",
"]",
"byte",
")",
"bool",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"name",
"{",
"if",
"!",
"OctetTypes",
"[",
"c",
"]",
".",
"IsToken",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
... | // ValidCookieName reports wheter given bytes is a valid RFC2616 "token" bytes. | [
"ValidCookieName",
"reports",
"wheter",
"given",
"bytes",
"is",
"a",
"valid",
"RFC2616",
"token",
"bytes",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/cookie.go#L170-L177 |
127,152 | gobwas/httphead | lexer.go | Next | func (l *Scanner) Next() bool {
c, ok := l.nextChar()
if !ok {
return false
}
switch c {
case '"': // quoted-string;
return l.fetchQuotedString()
case '(': // comment;
return l.fetchComment()
case '\\', ')': // unexpected chars;
l.err = true
return false
default:
return l.fetchToken()
}
} | go | func (l *Scanner) Next() bool {
c, ok := l.nextChar()
if !ok {
return false
}
switch c {
case '"': // quoted-string;
return l.fetchQuotedString()
case '(': // comment;
return l.fetchComment()
case '\\', ')': // unexpected chars;
l.err = true
return false
default:
return l.fetchToken()
}
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"Next",
"(",
")",
"bool",
"{",
"c",
",",
"ok",
":=",
"l",
".",
"nextChar",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"c",
"{",
"case",
"'\"'",
":",
"// quoted-stri... | // Next scans for next token. It returns true on successful scanning, and false
// on error or EOF. | [
"Next",
"scans",
"for",
"next",
"token",
".",
"It",
"returns",
"true",
"on",
"successful",
"scanning",
"and",
"false",
"on",
"error",
"or",
"EOF",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L44-L63 |
127,153 | gobwas/httphead | lexer.go | FetchUntil | func (l *Scanner) FetchUntil(c byte) bool {
l.resetItem()
if l.pos == len(l.data) {
return false
}
return l.fetchOctet(c)
} | go | func (l *Scanner) FetchUntil(c byte) bool {
l.resetItem()
if l.pos == len(l.data) {
return false
}
return l.fetchOctet(c)
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"FetchUntil",
"(",
"c",
"byte",
")",
"bool",
"{",
"l",
".",
"resetItem",
"(",
")",
"\n",
"if",
"l",
".",
"pos",
"==",
"len",
"(",
"l",
".",
"data",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
... | // FetchUntil fetches ItemOctet from current scanner position to first
// occurence of the c or to the end of the underlying data. | [
"FetchUntil",
"fetches",
"ItemOctet",
"from",
"current",
"scanner",
"position",
"to",
"first",
"occurence",
"of",
"the",
"c",
"or",
"to",
"the",
"end",
"of",
"the",
"underlying",
"data",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L67-L73 |
127,154 | gobwas/httphead | lexer.go | Peek | func (l *Scanner) Peek() byte {
if l.pos == len(l.data) {
return 0
}
return l.data[l.pos]
} | go | func (l *Scanner) Peek() byte {
if l.pos == len(l.data) {
return 0
}
return l.data[l.pos]
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"Peek",
"(",
")",
"byte",
"{",
"if",
"l",
".",
"pos",
"==",
"len",
"(",
"l",
".",
"data",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"l",
".",
"data",
"[",
"l",
".",
"pos",
"]",
"\n",
"}"
] | // Peek reads byte at current position without advancing it. On end of data it
// returns 0. | [
"Peek",
"reads",
"byte",
"at",
"current",
"position",
"without",
"advancing",
"it",
".",
"On",
"end",
"of",
"data",
"it",
"returns",
"0",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L77-L82 |
127,155 | gobwas/httphead | lexer.go | Peek2 | func (l *Scanner) Peek2() (a, b byte) {
if l.pos == len(l.data) {
return 0, 0
}
if l.pos+1 == len(l.data) {
return l.data[l.pos], 0
}
return l.data[l.pos], l.data[l.pos+1]
} | go | func (l *Scanner) Peek2() (a, b byte) {
if l.pos == len(l.data) {
return 0, 0
}
if l.pos+1 == len(l.data) {
return l.data[l.pos], 0
}
return l.data[l.pos], l.data[l.pos+1]
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"Peek2",
"(",
")",
"(",
"a",
",",
"b",
"byte",
")",
"{",
"if",
"l",
".",
"pos",
"==",
"len",
"(",
"l",
".",
"data",
")",
"{",
"return",
"0",
",",
"0",
"\n",
"}",
"\n",
"if",
"l",
".",
"pos",
"+",
"... | // Peek2 reads two first bytes at current position without advancing it.
// If there not enough data it returs 0. | [
"Peek2",
"reads",
"two",
"first",
"bytes",
"at",
"current",
"position",
"without",
"advancing",
"it",
".",
"If",
"there",
"not",
"enough",
"data",
"it",
"returs",
"0",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L86-L94 |
127,156 | gobwas/httphead | lexer.go | Advance | func (l *Scanner) Advance(n int) bool {
l.pos += n
if l.pos > len(l.data) {
l.pos = len(l.data)
return false
}
return true
} | go | func (l *Scanner) Advance(n int) bool {
l.pos += n
if l.pos > len(l.data) {
l.pos = len(l.data)
return false
}
return true
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"Advance",
"(",
"n",
"int",
")",
"bool",
"{",
"l",
".",
"pos",
"+=",
"n",
"\n",
"if",
"l",
".",
"pos",
">",
"len",
"(",
"l",
".",
"data",
")",
"{",
"l",
".",
"pos",
"=",
"len",
"(",
"l",
".",
"data",... | // Advance moves current position index at n bytes. It returns true on
// successful move. | [
"Advance",
"moves",
"current",
"position",
"index",
"at",
"n",
"bytes",
".",
"It",
"returns",
"true",
"on",
"successful",
"move",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L103-L110 |
127,157 | gobwas/httphead | lexer.go | Skip | func (l *Scanner) Skip(c byte) {
if l.err {
return
}
// Reset scanner state.
l.resetItem()
if i := bytes.IndexByte(l.data[l.pos:], c); i == -1 {
// Reached the end of data.
l.pos = len(l.data)
} else {
l.pos += i + 1
}
} | go | func (l *Scanner) Skip(c byte) {
if l.err {
return
}
// Reset scanner state.
l.resetItem()
if i := bytes.IndexByte(l.data[l.pos:], c); i == -1 {
// Reached the end of data.
l.pos = len(l.data)
} else {
l.pos += i + 1
}
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"Skip",
"(",
"c",
"byte",
")",
"{",
"if",
"l",
".",
"err",
"{",
"return",
"\n",
"}",
"\n",
"// Reset scanner state.",
"l",
".",
"resetItem",
"(",
")",
"\n\n",
"if",
"i",
":=",
"bytes",
".",
"IndexByte",
"(",
... | // Skip skips all bytes until first occurence of c. | [
"Skip",
"skips",
"all",
"bytes",
"until",
"first",
"occurence",
"of",
"c",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L113-L126 |
127,158 | gobwas/httphead | lexer.go | SkipEscaped | func (l *Scanner) SkipEscaped(c byte) {
if l.err {
return
}
// Reset scanner state.
l.resetItem()
if i := ScanUntil(l.data[l.pos:], c); i == -1 {
// Reached the end of data.
l.pos = len(l.data)
} else {
l.pos += i + 1
}
} | go | func (l *Scanner) SkipEscaped(c byte) {
if l.err {
return
}
// Reset scanner state.
l.resetItem()
if i := ScanUntil(l.data[l.pos:], c); i == -1 {
// Reached the end of data.
l.pos = len(l.data)
} else {
l.pos += i + 1
}
} | [
"func",
"(",
"l",
"*",
"Scanner",
")",
"SkipEscaped",
"(",
"c",
"byte",
")",
"{",
"if",
"l",
".",
"err",
"{",
"return",
"\n",
"}",
"\n",
"// Reset scanner state.",
"l",
".",
"resetItem",
"(",
")",
"\n\n",
"if",
"i",
":=",
"ScanUntil",
"(",
"l",
"."... | // SkipEscaped skips all bytes until first occurence of non-escaped c. | [
"SkipEscaped",
"skips",
"all",
"bytes",
"until",
"first",
"occurence",
"of",
"non",
"-",
"escaped",
"c",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L129-L142 |
127,159 | gobwas/httphead | lexer.go | ScanUntil | func ScanUntil(data []byte, c byte) (n int) {
for {
i := bytes.IndexByte(data[n:], c)
if i == -1 {
return -1
}
n += i
if n == 0 || data[n-1] != '\\' {
break
}
n++
}
return
} | go | func ScanUntil(data []byte, c byte) (n int) {
for {
i := bytes.IndexByte(data[n:], c)
if i == -1 {
return -1
}
n += i
if n == 0 || data[n-1] != '\\' {
break
}
n++
}
return
} | [
"func",
"ScanUntil",
"(",
"data",
"[",
"]",
"byte",
",",
"c",
"byte",
")",
"(",
"n",
"int",
")",
"{",
"for",
"{",
"i",
":=",
"bytes",
".",
"IndexByte",
"(",
"data",
"[",
"n",
":",
"]",
",",
"c",
")",
"\n",
"if",
"i",
"==",
"-",
"1",
"{",
... | // ScanUntil scans for first non-escaped character c in given data.
// It returns index of matched c and -1 if c is not found. | [
"ScanUntil",
"scans",
"for",
"first",
"non",
"-",
"escaped",
"character",
"c",
"in",
"given",
"data",
".",
"It",
"returns",
"index",
"of",
"matched",
"c",
"and",
"-",
"1",
"if",
"c",
"is",
"not",
"found",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L236-L249 |
127,160 | gobwas/httphead | lexer.go | ScanPairGreedy | func ScanPairGreedy(data []byte, open, close byte) (n int) {
var m int
opened := 1
for {
i := bytes.IndexByte(data[n:], close)
if i == -1 {
return -1
}
n += i
// If found index is not escaped then it is the end.
if n == 0 || data[n-1] != '\\' {
opened--
}
for m < i {
j := bytes.IndexByte(da... | go | func ScanPairGreedy(data []byte, open, close byte) (n int) {
var m int
opened := 1
for {
i := bytes.IndexByte(data[n:], close)
if i == -1 {
return -1
}
n += i
// If found index is not escaped then it is the end.
if n == 0 || data[n-1] != '\\' {
opened--
}
for m < i {
j := bytes.IndexByte(da... | [
"func",
"ScanPairGreedy",
"(",
"data",
"[",
"]",
"byte",
",",
"open",
",",
"close",
"byte",
")",
"(",
"n",
"int",
")",
"{",
"var",
"m",
"int",
"\n",
"opened",
":=",
"1",
"\n",
"for",
"{",
"i",
":=",
"bytes",
".",
"IndexByte",
"(",
"data",
"[",
... | // ScanPairGreedy scans for complete pair of opening and closing chars in greedy manner.
// Note that first opening byte must not be present in data. | [
"ScanPairGreedy",
"scans",
"for",
"complete",
"pair",
"of",
"opening",
"and",
"closing",
"chars",
"in",
"greedy",
"manner",
".",
"Note",
"that",
"first",
"opening",
"byte",
"must",
"not",
"be",
"present",
"in",
"data",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L253-L284 |
127,161 | gobwas/httphead | lexer.go | RemoveByte | func RemoveByte(data []byte, c byte) []byte {
j := bytes.IndexByte(data, c)
if j == -1 {
return data
}
n := len(data) - 1
// If character is present, than allocate slice with n-1 capacity. That is,
// resulting bytes could be at most n-1 length.
result := make([]byte, n)
k := copy(result, data[:j])
for i ... | go | func RemoveByte(data []byte, c byte) []byte {
j := bytes.IndexByte(data, c)
if j == -1 {
return data
}
n := len(data) - 1
// If character is present, than allocate slice with n-1 capacity. That is,
// resulting bytes could be at most n-1 length.
result := make([]byte, n)
k := copy(result, data[:j])
for i ... | [
"func",
"RemoveByte",
"(",
"data",
"[",
"]",
"byte",
",",
"c",
"byte",
")",
"[",
"]",
"byte",
"{",
"j",
":=",
"bytes",
".",
"IndexByte",
"(",
"data",
",",
"c",
")",
"\n",
"if",
"j",
"==",
"-",
"1",
"{",
"return",
"data",
"\n",
"}",
"\n\n",
"n... | // RemoveByte returns data without c. If c is not present in data it returns
// the same slice. If not, it copies data without c. | [
"RemoveByte",
"returns",
"data",
"without",
"c",
".",
"If",
"c",
"is",
"not",
"present",
"in",
"data",
"it",
"returns",
"the",
"same",
"slice",
".",
"If",
"not",
"it",
"copies",
"data",
"without",
"c",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L288-L313 |
127,162 | gobwas/httphead | lexer.go | SkipSpace | func SkipSpace(p []byte) (n int) {
for len(p) > 0 {
switch {
case len(p) >= 3 &&
p[0] == '\r' &&
p[1] == '\n' &&
OctetTypes[p[2]].IsSpace():
p = p[3:]
n += 3
case OctetTypes[p[0]].IsSpace():
p = p[1:]
n++
default:
return
}
}
return
} | go | func SkipSpace(p []byte) (n int) {
for len(p) > 0 {
switch {
case len(p) >= 3 &&
p[0] == '\r' &&
p[1] == '\n' &&
OctetTypes[p[2]].IsSpace():
p = p[3:]
n += 3
case OctetTypes[p[0]].IsSpace():
p = p[1:]
n++
default:
return
}
}
return
} | [
"func",
"SkipSpace",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
")",
"{",
"for",
"len",
"(",
"p",
")",
">",
"0",
"{",
"switch",
"{",
"case",
"len",
"(",
"p",
")",
">=",
"3",
"&&",
"p",
"[",
"0",
"]",
"==",
"'\\r'",
"&&",
"p",
"[",
... | // SkipSpace skips spaces and lws-sequences from p.
// It returns number ob bytes skipped. | [
"SkipSpace",
"skips",
"spaces",
"and",
"lws",
"-",
"sequences",
"from",
"p",
".",
"It",
"returns",
"number",
"ob",
"bytes",
"skipped",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L317-L334 |
127,163 | gobwas/httphead | lexer.go | ScanToken | func ScanToken(p []byte) (n int, t ItemType) {
if len(p) == 0 {
return 0, ItemUndef
}
c := p[0]
switch {
case OctetTypes[c].IsSeparator():
return 1, ItemSeparator
case OctetTypes[c].IsToken():
for n = 1; n < len(p); n++ {
c := p[n]
if !OctetTypes[c].IsToken() {
break
}
}
return n, ItemTok... | go | func ScanToken(p []byte) (n int, t ItemType) {
if len(p) == 0 {
return 0, ItemUndef
}
c := p[0]
switch {
case OctetTypes[c].IsSeparator():
return 1, ItemSeparator
case OctetTypes[c].IsToken():
for n = 1; n < len(p); n++ {
c := p[n]
if !OctetTypes[c].IsToken() {
break
}
}
return n, ItemTok... | [
"func",
"ScanToken",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"t",
"ItemType",
")",
"{",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"0",
",",
"ItemUndef",
"\n",
"}",
"\n\n",
"c",
":=",
"p",
"[",
"0",
"]",
"\n",
"swi... | // ScanToken scan for next token in p. It returns length of the token and its
// type. It do not trim p. | [
"ScanToken",
"scan",
"for",
"next",
"token",
"in",
"p",
".",
"It",
"returns",
"length",
"of",
"the",
"token",
"and",
"its",
"type",
".",
"It",
"do",
"not",
"trim",
"p",
"."
] | 2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5 | https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L338-L360 |
127,164 | couchbase/vellum | levenshtein2/parametric_dfa.go | isPrefixSink | func (pdfa *ParametricDFA) isPrefixSink(state ParametricState, queryLen uint32) bool {
if state.isDeadEnd() {
return true
}
remOffset := queryLen - state.offset
if remOffset < pdfa.diameter {
stateDistances := pdfa.distance[pdfa.diameter*state.shapeID:]
prefixDistance := stateDistances[remOffset]
if prefix... | go | func (pdfa *ParametricDFA) isPrefixSink(state ParametricState, queryLen uint32) bool {
if state.isDeadEnd() {
return true
}
remOffset := queryLen - state.offset
if remOffset < pdfa.diameter {
stateDistances := pdfa.distance[pdfa.diameter*state.shapeID:]
prefixDistance := stateDistances[remOffset]
if prefix... | [
"func",
"(",
"pdfa",
"*",
"ParametricDFA",
")",
"isPrefixSink",
"(",
"state",
"ParametricState",
",",
"queryLen",
"uint32",
")",
"bool",
"{",
"if",
"state",
".",
"isDeadEnd",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"remOffset",
":=",
"queryLen"... | // Returns true iff whatever characters come afterward,
// we will never reach a shorter distance | [
"Returns",
"true",
"iff",
"whatever",
"characters",
"come",
"afterward",
"we",
"will",
"never",
"reach",
"a",
"shorter",
"distance"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/parametric_dfa.go#L118-L139 |
127,165 | couchbase/vellum | levenshtein/levenshtein.go | New | func New(query string, distance int) (*Levenshtein, error) {
lev := &dynamicLevenshtein{
query: query,
distance: uint(distance),
}
dfabuilder := newDfaBuilder(lev)
dfa, err := dfabuilder.build()
if err != nil {
return nil, err
}
return &Levenshtein{
prog: lev,
dfa: dfa,
}, nil
} | go | func New(query string, distance int) (*Levenshtein, error) {
lev := &dynamicLevenshtein{
query: query,
distance: uint(distance),
}
dfabuilder := newDfaBuilder(lev)
dfa, err := dfabuilder.build()
if err != nil {
return nil, err
}
return &Levenshtein{
prog: lev,
dfa: dfa,
}, nil
} | [
"func",
"New",
"(",
"query",
"string",
",",
"distance",
"int",
")",
"(",
"*",
"Levenshtein",
",",
"error",
")",
"{",
"lev",
":=",
"&",
"dynamicLevenshtein",
"{",
"query",
":",
"query",
",",
"distance",
":",
"uint",
"(",
"distance",
")",
",",
"}",
"\n... | // New creates a new Levenshtein automaton for the specified
// query string and edit distance. | [
"New",
"creates",
"a",
"new",
"Levenshtein",
"automaton",
"for",
"the",
"specified",
"query",
"string",
"and",
"edit",
"distance",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein/levenshtein.go#L39-L53 |
127,166 | couchbase/vellum | levenshtein/levenshtein.go | Accept | func (l *Levenshtein) Accept(s int, b byte) int {
if s < len(l.dfa.states) {
return l.dfa.states[s].next[b]
}
return 0
} | go | func (l *Levenshtein) Accept(s int, b byte) int {
if s < len(l.dfa.states) {
return l.dfa.states[s].next[b]
}
return 0
} | [
"func",
"(",
"l",
"*",
"Levenshtein",
")",
"Accept",
"(",
"s",
"int",
",",
"b",
"byte",
")",
"int",
"{",
"if",
"s",
"<",
"len",
"(",
"l",
".",
"dfa",
".",
"states",
")",
"{",
"return",
"l",
".",
"dfa",
".",
"states",
"[",
"s",
"]",
".",
"ne... | // Accept returns the new state, resulting from the transite byte b
// when currently in the state s. | [
"Accept",
"returns",
"the",
"new",
"state",
"resulting",
"from",
"the",
"transite",
"byte",
"b",
"when",
"currently",
"in",
"the",
"state",
"s",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein/levenshtein.go#L85-L90 |
127,167 | couchbase/vellum | builder.go | newBuilder | func newBuilder(w io.Writer, opts *BuilderOpts) (*Builder, error) {
if opts == nil {
opts = defaultBuilderOpts
}
builderNodePool := &builderNodePool{}
rv := &Builder{
unfinished: newUnfinishedNodes(builderNodePool),
registry: newRegistry(builderNodePool, opts.RegistryTableSize, opts.RegistryMRUSiz... | go | func newBuilder(w io.Writer, opts *BuilderOpts) (*Builder, error) {
if opts == nil {
opts = defaultBuilderOpts
}
builderNodePool := &builderNodePool{}
rv := &Builder{
unfinished: newUnfinishedNodes(builderNodePool),
registry: newRegistry(builderNodePool, opts.RegistryTableSize, opts.RegistryMRUSiz... | [
"func",
"newBuilder",
"(",
"w",
"io",
".",
"Writer",
",",
"opts",
"*",
"BuilderOpts",
")",
"(",
"*",
"Builder",
",",
"error",
")",
"{",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"defaultBuilderOpts",
"\n",
"}",
"\n",
"builderNodePool",
":=",
"&",
... | // NewBuilder returns a new Builder which will stream out the
// underlying representation to the provided Writer as the set is built. | [
"NewBuilder",
"returns",
"a",
"new",
"Builder",
"which",
"will",
"stream",
"out",
"the",
"underlying",
"representation",
"to",
"the",
"provided",
"Writer",
"as",
"the",
"set",
"is",
"built",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L49-L72 |
127,168 | couchbase/vellum | builder.go | Close | func (b *Builder) Close() error {
err := b.compileFrom(0)
if err != nil {
return err
}
root := b.unfinished.popRoot()
rootAddr, err := b.compile(root)
if err != nil {
return err
}
return b.encoder.finish(b.len, rootAddr)
} | go | func (b *Builder) Close() error {
err := b.compileFrom(0)
if err != nil {
return err
}
root := b.unfinished.popRoot()
rootAddr, err := b.compile(root)
if err != nil {
return err
}
return b.encoder.finish(b.len, rootAddr)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"b",
".",
"compileFrom",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"root",
":=",
"b",
".",
"unfinished",
".",
"popR... | // Close MUST be called after inserting all values. | [
"Close",
"MUST",
"be",
"called",
"after",
"inserting",
"all",
"values",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L124-L135 |
127,169 | couchbase/vellum | builder.go | get | func (u *unfinishedNodes) get() *builderNodeUnfinished {
if len(u.stack) < len(u.cache) {
return &u.cache[len(u.stack)]
}
// full now allocate a new one
return &builderNodeUnfinished{}
} | go | func (u *unfinishedNodes) get() *builderNodeUnfinished {
if len(u.stack) < len(u.cache) {
return &u.cache[len(u.stack)]
}
// full now allocate a new one
return &builderNodeUnfinished{}
} | [
"func",
"(",
"u",
"*",
"unfinishedNodes",
")",
"get",
"(",
")",
"*",
"builderNodeUnfinished",
"{",
"if",
"len",
"(",
"u",
".",
"stack",
")",
"<",
"len",
"(",
"u",
".",
"cache",
")",
"{",
"return",
"&",
"u",
".",
"cache",
"[",
"len",
"(",
"u",
"... | // get new builderNodeUnfinished, reusing cache if possible | [
"get",
"new",
"builderNodeUnfinished",
"reusing",
"cache",
"if",
"possible"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L208-L214 |
127,170 | couchbase/vellum | builder.go | put | func (u *unfinishedNodes) put() {
if len(u.stack) >= len(u.cache) {
return
// do nothing, not part of cache
}
u.cache[len(u.stack)] = builderNodeUnfinished{}
} | go | func (u *unfinishedNodes) put() {
if len(u.stack) >= len(u.cache) {
return
// do nothing, not part of cache
}
u.cache[len(u.stack)] = builderNodeUnfinished{}
} | [
"func",
"(",
"u",
"*",
"unfinishedNodes",
")",
"put",
"(",
")",
"{",
"if",
"len",
"(",
"u",
".",
"stack",
")",
">=",
"len",
"(",
"u",
".",
"cache",
")",
"{",
"return",
"\n",
"// do nothing, not part of cache",
"}",
"\n",
"u",
".",
"cache",
"[",
"le... | // return builderNodeUnfinished, clearing it for reuse | [
"return",
"builderNodeUnfinished",
"clearing",
"it",
"for",
"reuse"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L217-L223 |
127,171 | couchbase/vellum | builder.go | reset | func (n *builderNode) reset() {
n.final = false
n.finalOutput = 0
for i := range n.trans {
n.trans[i] = emptyTransition
}
n.trans = n.trans[:0]
n.next = nil
} | go | func (n *builderNode) reset() {
n.final = false
n.finalOutput = 0
for i := range n.trans {
n.trans[i] = emptyTransition
}
n.trans = n.trans[:0]
n.next = nil
} | [
"func",
"(",
"n",
"*",
"builderNode",
")",
"reset",
"(",
")",
"{",
"n",
".",
"final",
"=",
"false",
"\n",
"n",
".",
"finalOutput",
"=",
"0",
"\n",
"for",
"i",
":=",
"range",
"n",
".",
"trans",
"{",
"n",
".",
"trans",
"[",
"i",
"]",
"=",
"empt... | // reset resets the receiver builderNode to a re-usable state. | [
"reset",
"resets",
"the",
"receiver",
"builderNode",
"to",
"a",
"re",
"-",
"usable",
"state",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L361-L369 |
127,172 | couchbase/vellum | merge_iterator.go | NewMergeIterator | func NewMergeIterator(itrs []Iterator, f MergeFunc) (*MergeIterator, error) {
rv := &MergeIterator{
itrs: itrs,
f: f,
currKs: make([][]byte, len(itrs)),
currVs: make([]uint64, len(itrs)),
lowIdxs: make([]int, 0, len(itrs)),
mergeV: make([]uint64, 0, len(itrs)),
}
rv.init()
if rv.lowK == nil ... | go | func NewMergeIterator(itrs []Iterator, f MergeFunc) (*MergeIterator, error) {
rv := &MergeIterator{
itrs: itrs,
f: f,
currKs: make([][]byte, len(itrs)),
currVs: make([]uint64, len(itrs)),
lowIdxs: make([]int, 0, len(itrs)),
mergeV: make([]uint64, 0, len(itrs)),
}
rv.init()
if rv.lowK == nil ... | [
"func",
"NewMergeIterator",
"(",
"itrs",
"[",
"]",
"Iterator",
",",
"f",
"MergeFunc",
")",
"(",
"*",
"MergeIterator",
",",
"error",
")",
"{",
"rv",
":=",
"&",
"MergeIterator",
"{",
"itrs",
":",
"itrs",
",",
"f",
":",
"f",
",",
"currKs",
":",
"make",
... | // NewMergeIterator creates a new MergeIterator over the provided slice of
// Iterators and with the specified MergeFunc to resolve duplicate keys. | [
"NewMergeIterator",
"creates",
"a",
"new",
"MergeIterator",
"over",
"the",
"provided",
"slice",
"of",
"Iterators",
"and",
"with",
"the",
"specified",
"MergeFunc",
"to",
"resolve",
"duplicate",
"keys",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L47-L61 |
127,173 | couchbase/vellum | merge_iterator.go | Close | func (m *MergeIterator) Close() error {
var rv error
for i := range m.itrs {
// close all iterators, return first error if any
err := m.itrs[i].Close()
if rv == nil {
rv = err
}
}
return rv
} | go | func (m *MergeIterator) Close() error {
var rv error
for i := range m.itrs {
// close all iterators, return first error if any
err := m.itrs[i].Close()
if rv == nil {
rv = err
}
}
return rv
} | [
"func",
"(",
"m",
"*",
"MergeIterator",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"rv",
"error",
"\n",
"for",
"i",
":=",
"range",
"m",
".",
"itrs",
"{",
"// close all iterators, return first error if any",
"err",
":=",
"m",
".",
"itrs",
"[",
"i",
"]",... | // Close will attempt to close all the underlying Iterators. If any errors
// are encountered, the first will be returned. | [
"Close",
"will",
"attempt",
"to",
"close",
"all",
"the",
"underlying",
"Iterators",
".",
"If",
"any",
"errors",
"are",
"encountered",
"the",
"first",
"will",
"be",
"returned",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L147-L157 |
127,174 | couchbase/vellum | merge_iterator.go | MergeMin | func MergeMin(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
if v < rv {
rv = v
}
}
return rv
} | go | func MergeMin(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
if v < rv {
rv = v
}
}
return rv
} | [
"func",
"MergeMin",
"(",
"vals",
"[",
"]",
"uint64",
")",
"uint64",
"{",
"rv",
":=",
"vals",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vals",
"[",
"1",
":",
"]",
"{",
"if",
"v",
"<",
"rv",
"{",
"rv",
"=",
"v",
"\n",
"}",
... | // MergeMin chooses the minimum value | [
"MergeMin",
"chooses",
"the",
"minimum",
"value"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L160-L168 |
127,175 | couchbase/vellum | merge_iterator.go | MergeMax | func MergeMax(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
if v > rv {
rv = v
}
}
return rv
} | go | func MergeMax(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
if v > rv {
rv = v
}
}
return rv
} | [
"func",
"MergeMax",
"(",
"vals",
"[",
"]",
"uint64",
")",
"uint64",
"{",
"rv",
":=",
"vals",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vals",
"[",
"1",
":",
"]",
"{",
"if",
"v",
">",
"rv",
"{",
"rv",
"=",
"v",
"\n",
"}",
... | // MergeMax chooses the maximum value | [
"MergeMax",
"chooses",
"the",
"maximum",
"value"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L171-L179 |
127,176 | couchbase/vellum | merge_iterator.go | MergeSum | func MergeSum(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
rv += v
}
return rv
} | go | func MergeSum(vals []uint64) uint64 {
rv := vals[0]
for _, v := range vals[1:] {
rv += v
}
return rv
} | [
"func",
"MergeSum",
"(",
"vals",
"[",
"]",
"uint64",
")",
"uint64",
"{",
"rv",
":=",
"vals",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vals",
"[",
"1",
":",
"]",
"{",
"rv",
"+=",
"v",
"\n",
"}",
"\n",
"return",
"rv",
"\n",
... | // MergeSum sums the values | [
"MergeSum",
"sums",
"the",
"values"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L182-L188 |
127,177 | couchbase/vellum | levenshtein2/levenshtein.go | NewLevenshteinAutomatonBuilder | func NewLevenshteinAutomatonBuilder(maxDistance uint8,
transposition bool) (*LevenshteinAutomatonBuilder, error) {
lnfa := newLevenshtein(maxDistance, transposition)
pdfa, err := fromNfa(lnfa)
if err != nil {
return nil, err
}
return &LevenshteinAutomatonBuilder{pDfa: pdfa}, nil
} | go | func NewLevenshteinAutomatonBuilder(maxDistance uint8,
transposition bool) (*LevenshteinAutomatonBuilder, error) {
lnfa := newLevenshtein(maxDistance, transposition)
pdfa, err := fromNfa(lnfa)
if err != nil {
return nil, err
}
return &LevenshteinAutomatonBuilder{pDfa: pdfa}, nil
} | [
"func",
"NewLevenshteinAutomatonBuilder",
"(",
"maxDistance",
"uint8",
",",
"transposition",
"bool",
")",
"(",
"*",
"LevenshteinAutomatonBuilder",
",",
"error",
")",
"{",
"lnfa",
":=",
"newLevenshtein",
"(",
"maxDistance",
",",
"transposition",
")",
"\n\n",
"pdfa",
... | // NewLevenshteinAutomatonBuilder creates a
// reusable, threadsafe Levenshtein automaton builder.
// `maxDistance` - maximum distance considered by the automaton.
// `transposition` - assign a distance of 1 for transposition
//
// Building this automaton builder is computationally intensive.
// While it takes only a f... | [
"NewLevenshteinAutomatonBuilder",
"creates",
"a",
"reusable",
"threadsafe",
"Levenshtein",
"automaton",
"builder",
".",
"maxDistance",
"-",
"maximum",
"distance",
"considered",
"by",
"the",
"automaton",
".",
"transposition",
"-",
"assign",
"a",
"distance",
"of",
"1",
... | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/levenshtein.go#L41-L51 |
127,178 | couchbase/vellum | levenshtein2/levenshtein.go | BuildDfa | func (lab *LevenshteinAutomatonBuilder) BuildDfa(query string,
fuzziness uint8) (*DFA, error) {
return lab.pDfa.buildDfa(query, fuzziness, false)
} | go | func (lab *LevenshteinAutomatonBuilder) BuildDfa(query string,
fuzziness uint8) (*DFA, error) {
return lab.pDfa.buildDfa(query, fuzziness, false)
} | [
"func",
"(",
"lab",
"*",
"LevenshteinAutomatonBuilder",
")",
"BuildDfa",
"(",
"query",
"string",
",",
"fuzziness",
"uint8",
")",
"(",
"*",
"DFA",
",",
"error",
")",
"{",
"return",
"lab",
".",
"pDfa",
".",
"buildDfa",
"(",
"query",
",",
"fuzziness",
",",
... | // BuildDfa builds the levenshtein automaton for serving
// queries with a given edit distance. | [
"BuildDfa",
"builds",
"the",
"levenshtein",
"automaton",
"for",
"serving",
"queries",
"with",
"a",
"given",
"edit",
"distance",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/levenshtein.go#L55-L58 |
127,179 | couchbase/vellum | utf8/utf8.go | NewSequences | func NewSequences(start, end rune) (Sequences, error) {
rv, _, err := NewSequencesPrealloc(start, end, nil, nil, nil, nil)
return rv, err
} | go | func NewSequences(start, end rune) (Sequences, error) {
rv, _, err := NewSequencesPrealloc(start, end, nil, nil, nil, nil)
return rv, err
} | [
"func",
"NewSequences",
"(",
"start",
",",
"end",
"rune",
")",
"(",
"Sequences",
",",
"error",
")",
"{",
"rv",
",",
"_",
",",
"err",
":=",
"NewSequencesPrealloc",
"(",
"start",
",",
"end",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
... | // NewSequences constructs a collection of Sequence which describe the
// byte ranges covered between the start and end runes. | [
"NewSequences",
"constructs",
"a",
"collection",
"of",
"Sequence",
"which",
"describe",
"the",
"byte",
"ranges",
"covered",
"between",
"the",
"start",
"and",
"end",
"runes",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L27-L30 |
127,180 | couchbase/vellum | utf8/utf8.go | SequenceFromEncodedRange | func SequenceFromEncodedRange(start, end []byte) (Sequence, error) {
if len(start) != len(end) {
return nil, fmt.Errorf("byte slices must be the same length")
}
switch len(start) {
case 2:
return Sequence{
Range{start[0], end[0]},
Range{start[1], end[1]},
}, nil
case 3:
return Sequence{
Range{star... | go | func SequenceFromEncodedRange(start, end []byte) (Sequence, error) {
if len(start) != len(end) {
return nil, fmt.Errorf("byte slices must be the same length")
}
switch len(start) {
case 2:
return Sequence{
Range{start[0], end[0]},
Range{start[1], end[1]},
}, nil
case 3:
return Sequence{
Range{star... | [
"func",
"SequenceFromEncodedRange",
"(",
"start",
",",
"end",
"[",
"]",
"byte",
")",
"(",
"Sequence",
",",
"error",
")",
"{",
"if",
"len",
"(",
"start",
")",
"!=",
"len",
"(",
"end",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
... | // SequenceFromEncodedRange creates sequence from the encoded bytes | [
"SequenceFromEncodedRange",
"creates",
"sequence",
"from",
"the",
"encoded",
"bytes"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L118-L144 |
127,181 | couchbase/vellum | utf8/utf8.go | Matches | func (u Sequence) Matches(bytes []byte) bool {
if len(bytes) < len(u) {
return false
}
for i := 0; i < len(u); i++ {
if !u[i].matches(bytes[i]) {
return false
}
}
return true
} | go | func (u Sequence) Matches(bytes []byte) bool {
if len(bytes) < len(u) {
return false
}
for i := 0; i < len(u); i++ {
if !u[i].matches(bytes[i]) {
return false
}
}
return true
} | [
"func",
"(",
"u",
"Sequence",
")",
"Matches",
"(",
"bytes",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"bytes",
")",
"<",
"len",
"(",
"u",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
... | // Matches checks to see if the provided byte slice matches the Sequence | [
"Matches",
"checks",
"to",
"see",
"if",
"the",
"provided",
"byte",
"slice",
"matches",
"the",
"Sequence"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L147-L157 |
127,182 | couchbase/vellum | utf8/utf8.go | split | func (s *scalarRange) split() (scalarRange, scalarRange) {
if s.start < 0xe000 && s.end > 0xd7ff {
return scalarRange{
start: s.start,
end: 0xd7ff,
},
scalarRange{
start: 0xe000,
end: s.end,
}
}
return nilScalarRange, nilScalarRange
} | go | func (s *scalarRange) split() (scalarRange, scalarRange) {
if s.start < 0xe000 && s.end > 0xd7ff {
return scalarRange{
start: s.start,
end: 0xd7ff,
},
scalarRange{
start: 0xe000,
end: s.end,
}
}
return nilScalarRange, nilScalarRange
} | [
"func",
"(",
"s",
"*",
"scalarRange",
")",
"split",
"(",
")",
"(",
"scalarRange",
",",
"scalarRange",
")",
"{",
"if",
"s",
".",
"start",
"<",
"0xe000",
"&&",
"s",
".",
"end",
">",
"0xd7ff",
"{",
"return",
"scalarRange",
"{",
"start",
":",
"s",
".",... | // split this scalar range if it overlaps with a surrogate codepoint | [
"split",
"this",
"scalar",
"range",
"if",
"it",
"overlaps",
"with",
"a",
"surrogate",
"codepoint"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L208-L220 |
127,183 | couchbase/vellum | utf8/utf8.go | encode | func (s *scalarRange) encode(start, end []byte) (int, int) {
n := utf8.EncodeRune(start, s.start)
m := utf8.EncodeRune(end, s.end)
return n, m
} | go | func (s *scalarRange) encode(start, end []byte) (int, int) {
n := utf8.EncodeRune(start, s.start)
m := utf8.EncodeRune(end, s.end)
return n, m
} | [
"func",
"(",
"s",
"*",
"scalarRange",
")",
"encode",
"(",
"start",
",",
"end",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"int",
")",
"{",
"n",
":=",
"utf8",
".",
"EncodeRune",
"(",
"start",
",",
"s",
".",
"start",
")",
"\n",
"m",
":=",
"utf8",
... | // start and end MUST have capacity for utf8.UTFMax bytes | [
"start",
"and",
"end",
"MUST",
"have",
"capacity",
"for",
"utf8",
".",
"UTFMax",
"bytes"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L237-L241 |
127,184 | couchbase/vellum | fst_iterator.go | pointTo | func (i *FSTIterator) pointTo(key []byte) error {
// tried to seek before start
if bytes.Compare(key, i.startKeyInclusive) < 0 {
key = i.startKeyInclusive
}
// tried to see past end
if i.endKeyExclusive != nil &&
bytes.Compare(key, i.endKeyExclusive) > 0 {
key = i.endKeyExclusive
}
// reset any state, po... | go | func (i *FSTIterator) pointTo(key []byte) error {
// tried to seek before start
if bytes.Compare(key, i.startKeyInclusive) < 0 {
key = i.startKeyInclusive
}
// tried to see past end
if i.endKeyExclusive != nil &&
bytes.Compare(key, i.endKeyExclusive) > 0 {
key = i.endKeyExclusive
}
// reset any state, po... | [
"func",
"(",
"i",
"*",
"FSTIterator",
")",
"pointTo",
"(",
"key",
"[",
"]",
"byte",
")",
"error",
"{",
"// tried to seek before start",
"if",
"bytes",
".",
"Compare",
"(",
"key",
",",
"i",
".",
"startKeyInclusive",
")",
"<",
"0",
"{",
"key",
"=",
"i",
... | // pointTo attempts to point us to the specified location | [
"pointTo",
"attempts",
"to",
"point",
"us",
"to",
"the",
"specified",
"location"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst_iterator.go#L94-L163 |
127,185 | couchbase/vellum | regexp/regexp.go | NewWithLimit | func NewWithLimit(expr string, size uint) (*Regexp, error) {
parsed, err := syntax.Parse(expr, syntax.Perl)
if err != nil {
return nil, err
}
return NewParsedWithLimit(expr, parsed, size)
} | go | func NewWithLimit(expr string, size uint) (*Regexp, error) {
parsed, err := syntax.Parse(expr, syntax.Perl)
if err != nil {
return nil, err
}
return NewParsedWithLimit(expr, parsed, size)
} | [
"func",
"NewWithLimit",
"(",
"expr",
"string",
",",
"size",
"uint",
")",
"(",
"*",
"Regexp",
",",
"error",
")",
"{",
"parsed",
",",
"err",
":=",
"syntax",
".",
"Parse",
"(",
"expr",
",",
"syntax",
".",
"Perl",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // NewRegexpWithLimit creates a new Regular Expression automaton with
// the specified expression. The size of the compiled finite state
// automaton exceeds the user specified size, ErrCompiledTooBig will be
// returned. | [
"NewRegexpWithLimit",
"creates",
"a",
"new",
"Regular",
"Expression",
"automaton",
"with",
"the",
"specified",
"expression",
".",
"The",
"size",
"of",
"the",
"compiled",
"finite",
"state",
"automaton",
"exceeds",
"the",
"user",
"specified",
"size",
"ErrCompiledTooBi... | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/regexp/regexp.go#L59-L65 |
127,186 | couchbase/vellum | regexp/regexp.go | Accept | func (r *Regexp) Accept(s int, b byte) int {
if s < len(r.dfa.states) {
return r.dfa.states[s].next[b]
}
return 0
} | go | func (r *Regexp) Accept(s int, b byte) int {
if s < len(r.dfa.states) {
return r.dfa.states[s].next[b]
}
return 0
} | [
"func",
"(",
"r",
"*",
"Regexp",
")",
"Accept",
"(",
"s",
"int",
",",
"b",
"byte",
")",
"int",
"{",
"if",
"s",
"<",
"len",
"(",
"r",
".",
"dfa",
".",
"states",
")",
"{",
"return",
"r",
".",
"dfa",
".",
"states",
"[",
"s",
"]",
".",
"next",
... | // Accept returns the new state, resulting from the transition byte b
// when currently in the state s. | [
"Accept",
"returns",
"the",
"new",
"state",
"resulting",
"from",
"the",
"transition",
"byte",
"b",
"when",
"currently",
"in",
"the",
"state",
"s",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/regexp/regexp.go#L114-L119 |
127,187 | couchbase/vellum | fst.go | Contains | func (f *FST) Contains(val []byte) (bool, error) {
_, exists, err := f.Get(val)
return exists, err
} | go | func (f *FST) Contains(val []byte) (bool, error) {
_, exists, err := f.Get(val)
return exists, err
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"Contains",
"(",
"val",
"[",
"]",
"byte",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"exists",
",",
"err",
":=",
"f",
".",
"Get",
"(",
"val",
")",
"\n",
"return",
"exists",
",",
"err",
"\n",
"}"
] | // Contains returns true if this FST contains the specified key. | [
"Contains",
"returns",
"true",
"if",
"this",
"FST",
"contains",
"the",
"specified",
"key",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L58-L61 |
127,188 | couchbase/vellum | fst.go | IsMatch | func (f *FST) IsMatch(addr int) bool {
match, _ := f.IsMatchWithVal(addr)
return match
} | go | func (f *FST) IsMatch(addr int) bool {
match, _ := f.IsMatchWithVal(addr)
return match
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"IsMatch",
"(",
"addr",
"int",
")",
"bool",
"{",
"match",
",",
"_",
":=",
"f",
".",
"IsMatchWithVal",
"(",
"addr",
")",
"\n",
"return",
"match",
"\n",
"}"
] | // IsMatch returns if this state is a matching state in this Automaton | [
"IsMatch",
"returns",
"if",
"this",
"state",
"is",
"a",
"matching",
"state",
"in",
"this",
"Automaton"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L134-L137 |
127,189 | couchbase/vellum | fst.go | CanMatch | func (f *FST) CanMatch(addr int) bool {
if addr == noneAddr {
return false
}
return true
} | go | func (f *FST) CanMatch(addr int) bool {
if addr == noneAddr {
return false
}
return true
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"CanMatch",
"(",
"addr",
"int",
")",
"bool",
"{",
"if",
"addr",
"==",
"noneAddr",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // CanMatch returns if this state can ever transition to a matching state
// in this Automaton | [
"CanMatch",
"returns",
"if",
"this",
"state",
"can",
"ever",
"transition",
"to",
"a",
"matching",
"state",
"in",
"this",
"Automaton"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L141-L146 |
127,190 | couchbase/vellum | fst.go | Accept | func (f *FST) Accept(addr int, b byte) int {
next, _ := f.AcceptWithVal(addr, b)
return next
} | go | func (f *FST) Accept(addr int, b byte) int {
next, _ := f.AcceptWithVal(addr, b)
return next
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"Accept",
"(",
"addr",
"int",
",",
"b",
"byte",
")",
"int",
"{",
"next",
",",
"_",
":=",
"f",
".",
"AcceptWithVal",
"(",
"addr",
",",
"b",
")",
"\n",
"return",
"next",
"\n",
"}"
] | // Accept returns the next state for this Automaton on input of byte b | [
"Accept",
"returns",
"the",
"next",
"state",
"for",
"this",
"Automaton",
"on",
"input",
"of",
"byte",
"b"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L155-L158 |
127,191 | couchbase/vellum | fst.go | IsMatchWithVal | func (f *FST) IsMatchWithVal(addr int) (bool, uint64) {
s, err := f.decoder.stateAt(addr, nil)
if err != nil {
return false, 0
}
return s.Final(), s.FinalOutput()
} | go | func (f *FST) IsMatchWithVal(addr int) (bool, uint64) {
s, err := f.decoder.stateAt(addr, nil)
if err != nil {
return false, 0
}
return s.Final(), s.FinalOutput()
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"IsMatchWithVal",
"(",
"addr",
"int",
")",
"(",
"bool",
",",
"uint64",
")",
"{",
"s",
",",
"err",
":=",
"f",
".",
"decoder",
".",
"stateAt",
"(",
"addr",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // IsMatchWithVal returns if this state is a matching state in this Automaton
// and also returns the final output value for this state | [
"IsMatchWithVal",
"returns",
"if",
"this",
"state",
"is",
"a",
"matching",
"state",
"in",
"this",
"Automaton",
"and",
"also",
"returns",
"the",
"final",
"output",
"value",
"for",
"this",
"state"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L162-L168 |
127,192 | couchbase/vellum | fst.go | AcceptWithVal | func (f *FST) AcceptWithVal(addr int, b byte) (int, uint64) {
s, err := f.decoder.stateAt(addr, nil)
if err != nil {
return noneAddr, 0
}
_, next, output := s.TransitionFor(b)
return next, output
} | go | func (f *FST) AcceptWithVal(addr int, b byte) (int, uint64) {
s, err := f.decoder.stateAt(addr, nil)
if err != nil {
return noneAddr, 0
}
_, next, output := s.TransitionFor(b)
return next, output
} | [
"func",
"(",
"f",
"*",
"FST",
")",
"AcceptWithVal",
"(",
"addr",
"int",
",",
"b",
"byte",
")",
"(",
"int",
",",
"uint64",
")",
"{",
"s",
",",
"err",
":=",
"f",
".",
"decoder",
".",
"stateAt",
"(",
"addr",
",",
"nil",
")",
"\n",
"if",
"err",
"... | // AcceptWithVal returns the next state for this Automaton on input of byte b
// and also returns the output value for the transition | [
"AcceptWithVal",
"returns",
"the",
"next",
"state",
"for",
"this",
"Automaton",
"on",
"input",
"of",
"byte",
"b",
"and",
"also",
"returns",
"the",
"output",
"value",
"for",
"the",
"transition"
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L172-L179 |
127,193 | couchbase/vellum | fst.go | Debug | func (f *FST) Debug(callback func(int, interface{}) error) error {
addr := f.decoder.getRoot()
set := bitset.New(uint(addr))
stack := addrStack{addr}
stateNumber := 0
stack, addr = stack[:len(stack)-1], stack[len(stack)-1]
for addr != noneAddr {
if set.Test(uint(addr)) {
stack, addr = stack.Pop()
contin... | go | func (f *FST) Debug(callback func(int, interface{}) error) error {
addr := f.decoder.getRoot()
set := bitset.New(uint(addr))
stack := addrStack{addr}
stateNumber := 0
stack, addr = stack[:len(stack)-1], stack[len(stack)-1]
for addr != noneAddr {
if set.Test(uint(addr)) {
stack, addr = stack.Pop()
contin... | [
"func",
"(",
"f",
"*",
"FST",
")",
"Debug",
"(",
"callback",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"addr",
":=",
"f",
".",
"decoder",
".",
"getRoot",
"(",
")",
"\n",
"set",
":=",
"bitset",
".",
"New",
... | // Debug is only intended for debug purposes, it simply asks the underlying
// decoder visit each state, and pass it to the provided callback. | [
"Debug",
"is",
"only",
"intended",
"for",
"debug",
"purposes",
"it",
"simply",
"asks",
"the",
"underlying",
"decoder",
"visit",
"each",
"state",
"and",
"pass",
"it",
"to",
"the",
"provided",
"callback",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L196-L228 |
127,194 | couchbase/vellum | vellum.go | New | func New(w io.Writer, opts *BuilderOpts) (*Builder, error) {
return newBuilder(w, opts)
} | go | func New(w io.Writer, opts *BuilderOpts) (*Builder, error) {
return newBuilder(w, opts)
} | [
"func",
"New",
"(",
"w",
"io",
".",
"Writer",
",",
"opts",
"*",
"BuilderOpts",
")",
"(",
"*",
"Builder",
",",
"error",
")",
"{",
"return",
"newBuilder",
"(",
"w",
",",
"opts",
")",
"\n",
"}"
] | // New returns a new Builder which will stream out the
// underlying representation to the provided Writer as the set is built. | [
"New",
"returns",
"a",
"new",
"Builder",
"which",
"will",
"stream",
"out",
"the",
"underlying",
"representation",
"to",
"the",
"provided",
"Writer",
"as",
"the",
"set",
"is",
"built",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/vellum.go#L64-L66 |
127,195 | couchbase/vellum | vellum.go | Merge | func Merge(w io.Writer, opts *BuilderOpts, itrs []Iterator, f MergeFunc) error {
builder, err := New(w, opts)
if err != nil {
return err
}
itr, err := NewMergeIterator(itrs, f)
for err == nil {
k, v := itr.Current()
err = builder.Insert(k, v)
if err != nil {
return err
}
err = itr.Next()
}
if er... | go | func Merge(w io.Writer, opts *BuilderOpts, itrs []Iterator, f MergeFunc) error {
builder, err := New(w, opts)
if err != nil {
return err
}
itr, err := NewMergeIterator(itrs, f)
for err == nil {
k, v := itr.Current()
err = builder.Insert(k, v)
if err != nil {
return err
}
err = itr.Next()
}
if er... | [
"func",
"Merge",
"(",
"w",
"io",
".",
"Writer",
",",
"opts",
"*",
"BuilderOpts",
",",
"itrs",
"[",
"]",
"Iterator",
",",
"f",
"MergeFunc",
")",
"error",
"{",
"builder",
",",
"err",
":=",
"New",
"(",
"w",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",... | // Merge will iterate through the provided Iterators, merge duplicate keys
// with the provided MergeFunc, and build a new FST to the provided Writer. | [
"Merge",
"will",
"iterate",
"through",
"the",
"provided",
"Iterators",
"merge",
"duplicate",
"keys",
"with",
"the",
"provided",
"MergeFunc",
"and",
"build",
"a",
"new",
"FST",
"to",
"the",
"provided",
"Writer",
"."
] | 462e86d8716b36a1397b30ef77fb11105065a232 | https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/vellum.go#L80-L111 |
127,196 | go-chassis/go-archaius | core/config-manager/configurationmanager.go | NewConfigurationManager | func NewConfigurationManager(dispatcher core.Dispatcher) core.ConfigMgr {
configMgr := new(ConfigurationManager)
configMgr.dispatcher = dispatcher
configMgr.Sources = make(map[string]core.ConfigSource)
configMgr.ConfigurationMap = make(map[string]string)
//configMgr.logger = cLogger
return configMgr
} | go | func NewConfigurationManager(dispatcher core.Dispatcher) core.ConfigMgr {
configMgr := new(ConfigurationManager)
configMgr.dispatcher = dispatcher
configMgr.Sources = make(map[string]core.ConfigSource)
configMgr.ConfigurationMap = make(map[string]string)
//configMgr.logger = cLogger
return configMgr
} | [
"func",
"NewConfigurationManager",
"(",
"dispatcher",
"core",
".",
"Dispatcher",
")",
"core",
".",
"ConfigMgr",
"{",
"configMgr",
":=",
"new",
"(",
"ConfigurationManager",
")",
"\n",
"configMgr",
".",
"dispatcher",
"=",
"dispatcher",
"\n",
"configMgr",
".",
"Sou... | // NewConfigurationManager creates an object of ConfigurationManager | [
"NewConfigurationManager",
"creates",
"an",
"object",
"of",
"ConfigurationManager"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L53-L61 |
127,197 | go-chassis/go-archaius | core/config-manager/configurationmanager.go | Cleanup | func (configMgr *ConfigurationManager) Cleanup() {
// cleanup all dynamic handler
configMgr.sourceMapMux.Lock()
defer configMgr.sourceMapMux.Unlock()
for _, source := range configMgr.Sources {
if source.GetSourceName() == filesource.FileConfigSourceConst {
source.Cleanup()
delete(configMgr.Sources, source.G... | go | func (configMgr *ConfigurationManager) Cleanup() {
// cleanup all dynamic handler
configMgr.sourceMapMux.Lock()
defer configMgr.sourceMapMux.Unlock()
for _, source := range configMgr.Sources {
if source.GetSourceName() == filesource.FileConfigSourceConst {
source.Cleanup()
delete(configMgr.Sources, source.G... | [
"func",
"(",
"configMgr",
"*",
"ConfigurationManager",
")",
"Cleanup",
"(",
")",
"{",
"// cleanup all dynamic handler",
"configMgr",
".",
"sourceMapMux",
".",
"Lock",
"(",
")",
"\n",
"defer",
"configMgr",
".",
"sourceMapMux",
".",
"Unlock",
"(",
")",
"\n",
"fo... | // Cleanup close and cleanup config manager channel | [
"Cleanup",
"close",
"and",
"cleanup",
"config",
"manager",
"channel"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L64-L74 |
127,198 | go-chassis/go-archaius | core/config-manager/configurationmanager.go | Unmarshal | func (configMgr *ConfigurationManager) Unmarshal(obj interface{}) error {
rv := reflect.ValueOf(obj)
// only pointers are accepted
if rv.Kind() != reflect.Ptr || rv.IsNil() {
err := errors.New("invalid object supplied")
openlogging.GetLogger().Error("invalid object supplied: " + err.Error())
return err
}
re... | go | func (configMgr *ConfigurationManager) Unmarshal(obj interface{}) error {
rv := reflect.ValueOf(obj)
// only pointers are accepted
if rv.Kind() != reflect.Ptr || rv.IsNil() {
err := errors.New("invalid object supplied")
openlogging.GetLogger().Error("invalid object supplied: " + err.Error())
return err
}
re... | [
"func",
"(",
"configMgr",
"*",
"ConfigurationManager",
")",
"Unmarshal",
"(",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"obj",
")",
"\n",
"// only pointers are accepted",
"if",
"rv",
".",
"Kind",
"(",
")",... | // Unmarshal deserailize config into object | [
"Unmarshal",
"deserailize",
"config",
"into",
"object"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L77-L87 |
127,199 | go-chassis/go-archaius | core/config-manager/configurationmanager.go | AddSource | func (configMgr *ConfigurationManager) AddSource(source core.ConfigSource, priority int) error {
if source == nil || source.GetSourceName() == "" {
err := errors.New("nil or invalid source supplied")
openlogging.GetLogger().Error("nil or invalid source supplied: " + err.Error())
return err
}
configMgr.sourceM... | go | func (configMgr *ConfigurationManager) AddSource(source core.ConfigSource, priority int) error {
if source == nil || source.GetSourceName() == "" {
err := errors.New("nil or invalid source supplied")
openlogging.GetLogger().Error("nil or invalid source supplied: " + err.Error())
return err
}
configMgr.sourceM... | [
"func",
"(",
"configMgr",
"*",
"ConfigurationManager",
")",
"AddSource",
"(",
"source",
"core",
".",
"ConfigSource",
",",
"priority",
"int",
")",
"error",
"{",
"if",
"source",
"==",
"nil",
"||",
"source",
".",
"GetSourceName",
"(",
")",
"==",
"\"",
"\"",
... | // AddSource adds a source to configurationManager | [
"AddSource",
"adds",
"a",
"source",
"to",
"configurationManager"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L90-L121 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.