id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
16,500 | anacrolix/missinggo | resource/resource.go | Move | func Move(from, to Instance) (err error) {
rc, err := from.Get()
if err != nil {
return
}
defer rc.Close()
err = to.Put(rc)
if err != nil {
return
}
from.Delete()
return
} | go | func Move(from, to Instance) (err error) {
rc, err := from.Get()
if err != nil {
return
}
defer rc.Close()
err = to.Put(rc)
if err != nil {
return
}
from.Delete()
return
} | [
"func",
"Move",
"(",
"from",
",",
"to",
"Instance",
")",
"(",
"err",
"error",
")",
"{",
"rc",
",",
"err",
":=",
"from",
".",
"Get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"rc",
".",
"Close",
"(",
")... | // Move instance content, deleting the source if it succeeds. | [
"Move",
"instance",
"content",
"deleting",
"the",
"source",
"if",
"it",
"succeeds",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/resource/resource.go#L29-L41 |
16,501 | anacrolix/missinggo | section_read_seeker.go | NewSectionReadSeeker | func NewSectionReadSeeker(base io.ReadSeeker, off, size int64) (ret ReadSeekContexter) {
ret = §ionReadSeeker{
base: base,
off: off,
size: size,
}
seekOff, err := ret.Seek(0, io.SeekStart)
if err != nil {
panic(err)
}
if seekOff != 0 {
panic(seekOff)
}
return
} | go | func NewSectionReadSeeker(base io.ReadSeeker, off, size int64) (ret ReadSeekContexter) {
ret = §ionReadSeeker{
base: base,
off: off,
size: size,
}
seekOff, err := ret.Seek(0, io.SeekStart)
if err != nil {
panic(err)
}
if seekOff != 0 {
panic(seekOff)
}
return
} | [
"func",
"NewSectionReadSeeker",
"(",
"base",
"io",
".",
"ReadSeeker",
",",
"off",
",",
"size",
"int64",
")",
"(",
"ret",
"ReadSeekContexter",
")",
"{",
"ret",
"=",
"&",
"sectionReadSeeker",
"{",
"base",
":",
"base",
",",
"off",
":",
"off",
",",
"size",
... | // Returns a ReadSeeker on a section of another ReadSeeker. | [
"Returns",
"a",
"ReadSeeker",
"on",
"a",
"section",
"of",
"another",
"ReadSeeker",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/section_read_seeker.go#L20-L34 |
16,502 | anacrolix/missinggo | copy.go | CopyExact | func CopyExact(dest interface{}, src interface{}) {
dV := reflect.ValueOf(dest)
sV := reflect.ValueOf(src)
if dV.Kind() == reflect.Ptr {
dV = dV.Elem()
}
if dV.Kind() == reflect.Array && !dV.CanAddr() {
panic(fmt.Sprintf("dest not addressable: %T", dest))
}
if sV.Kind() == reflect.Ptr {
sV = sV.Elem()
}
if sV.Kind() == reflect.String {
sV = sV.Convert(reflect.SliceOf(dV.Type().Elem()))
}
if !sV.IsValid() {
panic("invalid source, probably nil")
}
if dV.Len() != sV.Len() {
panic(fmt.Sprintf("dest len (%d) != src len (%d)", dV.Len(), sV.Len()))
}
if dV.Len() != reflect.Copy(dV, sV) {
panic("dammit")
}
} | go | func CopyExact(dest interface{}, src interface{}) {
dV := reflect.ValueOf(dest)
sV := reflect.ValueOf(src)
if dV.Kind() == reflect.Ptr {
dV = dV.Elem()
}
if dV.Kind() == reflect.Array && !dV.CanAddr() {
panic(fmt.Sprintf("dest not addressable: %T", dest))
}
if sV.Kind() == reflect.Ptr {
sV = sV.Elem()
}
if sV.Kind() == reflect.String {
sV = sV.Convert(reflect.SliceOf(dV.Type().Elem()))
}
if !sV.IsValid() {
panic("invalid source, probably nil")
}
if dV.Len() != sV.Len() {
panic(fmt.Sprintf("dest len (%d) != src len (%d)", dV.Len(), sV.Len()))
}
if dV.Len() != reflect.Copy(dV, sV) {
panic("dammit")
}
} | [
"func",
"CopyExact",
"(",
"dest",
"interface",
"{",
"}",
",",
"src",
"interface",
"{",
"}",
")",
"{",
"dV",
":=",
"reflect",
".",
"ValueOf",
"(",
"dest",
")",
"\n",
"sV",
":=",
"reflect",
".",
"ValueOf",
"(",
"src",
")",
"\n",
"if",
"dV",
".",
"K... | // Copy elements from src to dst. Panics if the length of src and dst are
// different. | [
"Copy",
"elements",
"from",
"src",
"to",
"dst",
".",
"Panics",
"if",
"the",
"length",
"of",
"src",
"and",
"dst",
"are",
"different",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/copy.go#L10-L34 |
16,503 | anacrolix/missinggo | limitlen.go | LimitLen | func LimitLen(b []byte, max ...interface{}) []byte {
return b[:MinInt(len(b), max...)]
} | go | func LimitLen(b []byte, max ...interface{}) []byte {
return b[:MinInt(len(b), max...)]
} | [
"func",
"LimitLen",
"(",
"b",
"[",
"]",
"byte",
",",
"max",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"b",
"[",
":",
"MinInt",
"(",
"len",
"(",
"b",
")",
",",
"max",
"...",
")",
"]",
"\n",
"}"
] | // Sets an upper bound on the len of b. max can be any type that will cast to
// int64. | [
"Sets",
"an",
"upper",
"bound",
"on",
"the",
"len",
"of",
"b",
".",
"max",
"can",
"be",
"any",
"type",
"that",
"will",
"cast",
"to",
"int64",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/limitlen.go#L5-L7 |
16,504 | anacrolix/missinggo | flag.go | AddCondToFlags | func AddCondToFlags(cond *sync.Cond, flags ...*Flag) {
for _, f := range flags {
f.addCond(cond)
}
} | go | func AddCondToFlags(cond *sync.Cond, flags ...*Flag) {
for _, f := range flags {
f.addCond(cond)
}
} | [
"func",
"AddCondToFlags",
"(",
"cond",
"*",
"sync",
".",
"Cond",
",",
"flags",
"...",
"*",
"Flag",
")",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"flags",
"{",
"f",
".",
"addCond",
"(",
"cond",
")",
"\n",
"}",
"\n",
"}"
] | // Adds the sync.Cond to all the given Flag's. | [
"Adds",
"the",
"sync",
".",
"Cond",
"to",
"all",
"the",
"given",
"Flag",
"s",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/flag.go#L37-L41 |
16,505 | anacrolix/missinggo | tls.go | BestNamedCertificate | func BestNamedCertificate(c *tls.Config, clientHello *tls.ClientHelloInfo) (*tls.Certificate, bool) {
name := strings.ToLower(clientHello.ServerName)
for len(name) > 0 && name[len(name)-1] == '.' {
name = name[:len(name)-1]
}
if cert, ok := c.NameToCertificate[name]; ok {
return cert, true
}
// try replacing labels in the name with wildcards until we get a
// match.
labels := strings.Split(name, ".")
for i := range labels {
labels[i] = "*"
candidate := strings.Join(labels, ".")
if cert, ok := c.NameToCertificate[candidate]; ok {
return cert, true
}
}
return nil, false
} | go | func BestNamedCertificate(c *tls.Config, clientHello *tls.ClientHelloInfo) (*tls.Certificate, bool) {
name := strings.ToLower(clientHello.ServerName)
for len(name) > 0 && name[len(name)-1] == '.' {
name = name[:len(name)-1]
}
if cert, ok := c.NameToCertificate[name]; ok {
return cert, true
}
// try replacing labels in the name with wildcards until we get a
// match.
labels := strings.Split(name, ".")
for i := range labels {
labels[i] = "*"
candidate := strings.Join(labels, ".")
if cert, ok := c.NameToCertificate[candidate]; ok {
return cert, true
}
}
return nil, false
} | [
"func",
"BestNamedCertificate",
"(",
"c",
"*",
"tls",
".",
"Config",
",",
"clientHello",
"*",
"tls",
".",
"ClientHelloInfo",
")",
"(",
"*",
"tls",
".",
"Certificate",
",",
"bool",
")",
"{",
"name",
":=",
"strings",
".",
"ToLower",
"(",
"clientHello",
"."... | // Select the best named certificate per the usual behaviour if
// c.GetCertificate is nil, and c.NameToCertificate is not. | [
"Select",
"the",
"best",
"named",
"certificate",
"per",
"the",
"usual",
"behaviour",
"if",
"c",
".",
"GetCertificate",
"is",
"nil",
"and",
"c",
".",
"NameToCertificate",
"is",
"not",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/tls.go#L10-L32 |
16,506 | anacrolix/missinggo | httptoo/gzip.go | GzipHandler | func GzipHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") || w.Header().Get("Content-Encoding") != "" || w.Header().Get("Vary") != "" {
h.ServeHTTP(w, r)
return
}
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
gz := gzip.NewWriter(w)
defer gz.Close()
h.ServeHTTP(&gzipResponseWriter{
Writer: gz,
ResponseWriter: w,
}, r)
})
} | go | func GzipHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") || w.Header().Get("Content-Encoding") != "" || w.Header().Get("Vary") != "" {
h.ServeHTTP(w, r)
return
}
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
gz := gzip.NewWriter(w)
defer gz.Close()
h.ServeHTTP(&gzipResponseWriter{
Writer: gz,
ResponseWriter: w,
}, r)
})
} | [
"func",
"GzipHandler",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"!",
"string... | // Gzips response body if the request says it'll allow it. | [
"Gzips",
"response",
"body",
"if",
"the",
"request",
"says",
"it",
"ll",
"allow",
"it",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/gzip.go#L34-L49 |
16,507 | anacrolix/missinggo | conntrack/instance.go | wakeOne | func (i *Instance) wakeOne() {
i.waitersByPriority.Iter(func(key interface{}) bool {
value := i.waitersByPriority.Get(key).(entryHandleSet)
for eh := range value {
i.wakeEntry(eh.e)
break
}
return false
})
} | go | func (i *Instance) wakeOne() {
i.waitersByPriority.Iter(func(key interface{}) bool {
value := i.waitersByPriority.Get(key).(entryHandleSet)
for eh := range value {
i.wakeEntry(eh.e)
break
}
return false
})
} | [
"func",
"(",
"i",
"*",
"Instance",
")",
"wakeOne",
"(",
")",
"{",
"i",
".",
"waitersByPriority",
".",
"Iter",
"(",
"func",
"(",
"key",
"interface",
"{",
"}",
")",
"bool",
"{",
"value",
":=",
"i",
".",
"waitersByPriority",
".",
"Get",
"(",
"key",
")... | // Wakes the highest priority waiter. | [
"Wakes",
"the",
"highest",
"priority",
"waiter",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/conntrack/instance.go#L97-L106 |
16,508 | anacrolix/missinggo | conntrack/instance.go | wakeEntry | func (i *Instance) wakeEntry(e Entry) {
if _, ok := i.entries[e]; ok {
panic(e)
}
i.entries[e] = make(handles, len(i.waitersByEntry[e]))
for eh := range i.waitersByEntry[e] {
i.entries[e][eh] = struct{}{}
i.deleteWaiter(eh)
eh.wake.Unlock()
}
if i.waitersByEntry[e] != nil {
panic(i.waitersByEntry[e])
}
} | go | func (i *Instance) wakeEntry(e Entry) {
if _, ok := i.entries[e]; ok {
panic(e)
}
i.entries[e] = make(handles, len(i.waitersByEntry[e]))
for eh := range i.waitersByEntry[e] {
i.entries[e][eh] = struct{}{}
i.deleteWaiter(eh)
eh.wake.Unlock()
}
if i.waitersByEntry[e] != nil {
panic(i.waitersByEntry[e])
}
} | [
"func",
"(",
"i",
"*",
"Instance",
")",
"wakeEntry",
"(",
"e",
"Entry",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"i",
".",
"entries",
"[",
"e",
"]",
";",
"ok",
"{",
"panic",
"(",
"e",
")",
"\n",
"}",
"\n",
"i",
".",
"entries",
"[",
"e",
"]",
... | // Wakes all waiters on an entry. Note that the entry is also woken
// immediately, the waiters are all let through. | [
"Wakes",
"all",
"waiters",
"on",
"an",
"entry",
".",
"Note",
"that",
"the",
"entry",
"is",
"also",
"woken",
"immediately",
"the",
"waiters",
"are",
"all",
"let",
"through",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/conntrack/instance.go#L151-L164 |
16,509 | anacrolix/missinggo | conntrack/instance.go | Wait | func (i *Instance) Wait(ctx context.Context, e Entry, reason string, p priority) (eh *EntryHandle) {
eh = &EntryHandle{
reason: reason,
e: e,
i: i,
priority: p,
created: time.Now(),
}
i.mu.Lock()
hs, ok := i.entries[eh.e]
if ok {
hs[eh] = struct{}{}
i.mu.Unlock()
expvars.Add("waits for existing entry", 1)
return
}
if i.noMaxEntries || len(i.entries) < i.maxEntries {
i.entries[eh.e] = handles{
eh: struct{}{},
}
i.mu.Unlock()
expvars.Add("waits with space in table", 1)
return
}
// Lock the mutex, so that a following Lock will block until it's unlocked by a wake event.
eh.wake.Lock()
i.addWaiter(eh)
i.mu.Unlock()
expvars.Add("waits that blocked", 1)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
<-ctx.Done()
i.mu.Lock()
if _, ok := i.waiters[eh]; ok {
i.deleteWaiter(eh)
eh.wake.Unlock()
}
i.mu.Unlock()
}()
// Blocks until woken by an Unlock.
eh.wake.Lock()
i.mu.Lock()
if _, ok := i.entries[eh.e][eh]; !ok {
eh = nil
}
i.mu.Unlock()
return
} | go | func (i *Instance) Wait(ctx context.Context, e Entry, reason string, p priority) (eh *EntryHandle) {
eh = &EntryHandle{
reason: reason,
e: e,
i: i,
priority: p,
created: time.Now(),
}
i.mu.Lock()
hs, ok := i.entries[eh.e]
if ok {
hs[eh] = struct{}{}
i.mu.Unlock()
expvars.Add("waits for existing entry", 1)
return
}
if i.noMaxEntries || len(i.entries) < i.maxEntries {
i.entries[eh.e] = handles{
eh: struct{}{},
}
i.mu.Unlock()
expvars.Add("waits with space in table", 1)
return
}
// Lock the mutex, so that a following Lock will block until it's unlocked by a wake event.
eh.wake.Lock()
i.addWaiter(eh)
i.mu.Unlock()
expvars.Add("waits that blocked", 1)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
<-ctx.Done()
i.mu.Lock()
if _, ok := i.waiters[eh]; ok {
i.deleteWaiter(eh)
eh.wake.Unlock()
}
i.mu.Unlock()
}()
// Blocks until woken by an Unlock.
eh.wake.Lock()
i.mu.Lock()
if _, ok := i.entries[eh.e][eh]; !ok {
eh = nil
}
i.mu.Unlock()
return
} | [
"func",
"(",
"i",
"*",
"Instance",
")",
"Wait",
"(",
"ctx",
"context",
".",
"Context",
",",
"e",
"Entry",
",",
"reason",
"string",
",",
"p",
"priority",
")",
"(",
"eh",
"*",
"EntryHandle",
")",
"{",
"eh",
"=",
"&",
"EntryHandle",
"{",
"reason",
":"... | // Nil returns are due to context completion. | [
"Nil",
"returns",
"are",
"due",
"to",
"context",
"completion",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/conntrack/instance.go#L171-L219 |
16,510 | anacrolix/missinggo | httptoo/reverse_proxy.go | RedirectedRequest | func RedirectedRequest(r *http.Request, newUrl string) (ret *http.Request, err error) {
u, err := url.Parse(newUrl)
if err != nil {
return
}
ret = new(http.Request)
*ret = *r
ret.Header = nil
err = deepCopy(&ret.Header, r.Header)
if err != nil {
return
}
ret.URL = u
ret.RequestURI = ""
return
} | go | func RedirectedRequest(r *http.Request, newUrl string) (ret *http.Request, err error) {
u, err := url.Parse(newUrl)
if err != nil {
return
}
ret = new(http.Request)
*ret = *r
ret.Header = nil
err = deepCopy(&ret.Header, r.Header)
if err != nil {
return
}
ret.URL = u
ret.RequestURI = ""
return
} | [
"func",
"RedirectedRequest",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"newUrl",
"string",
")",
"(",
"ret",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"newUrl",
")",
"\n",
"if",
... | // Takes a request, and alters its destination fields, for proxying. | [
"Takes",
"a",
"request",
"and",
"alters",
"its",
"destination",
"fields",
"for",
"proxying",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/reverse_proxy.go#L36-L51 |
16,511 | anacrolix/missinggo | path.go | PathSplitExt | func PathSplitExt(p string) (ret struct {
Root, Ext string
}) {
ret.Ext = path.Ext(p)
ret.Root = p[:len(p)-len(ret.Ext)]
return
} | go | func PathSplitExt(p string) (ret struct {
Root, Ext string
}) {
ret.Ext = path.Ext(p)
ret.Root = p[:len(p)-len(ret.Ext)]
return
} | [
"func",
"PathSplitExt",
"(",
"p",
"string",
")",
"(",
"ret",
"struct",
"{",
"Root",
",",
"Ext",
"string",
"\n",
"}",
")",
"{",
"ret",
".",
"Ext",
"=",
"path",
".",
"Ext",
"(",
"p",
")",
"\n",
"ret",
".",
"Root",
"=",
"p",
"[",
":",
"len",
"("... | // Splits the pathname p into Root and Ext, such that Root+Ext==p. | [
"Splits",
"the",
"pathname",
"p",
"into",
"Root",
"and",
"Ext",
"such",
"that",
"Root",
"+",
"Ext",
"==",
"p",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/path.go#L9-L15 |
16,512 | anacrolix/missinggo | selfcert.go | NewSelfSignedCertificate | func NewSelfSignedCertificate() (cert tls.Certificate, err error) {
cert.PrivateKey, err = rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return
}
notBefore := time.Now()
notAfter := notBefore.Add(365 * 24 * time.Hour)
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Fatalf("failed to generate serial number: %s", err)
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
},
NotBefore: notBefore,
NotAfter: notAfter,
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(cert.PrivateKey), cert.PrivateKey)
if err != nil {
log.Fatalf("Failed to create certificate: %s", err)
}
cert.Certificate = [][]byte{derBytes}
return
} | go | func NewSelfSignedCertificate() (cert tls.Certificate, err error) {
cert.PrivateKey, err = rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return
}
notBefore := time.Now()
notAfter := notBefore.Add(365 * 24 * time.Hour)
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Fatalf("failed to generate serial number: %s", err)
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
},
NotBefore: notBefore,
NotAfter: notAfter,
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(cert.PrivateKey), cert.PrivateKey)
if err != nil {
log.Fatalf("Failed to create certificate: %s", err)
}
cert.Certificate = [][]byte{derBytes}
return
} | [
"func",
"NewSelfSignedCertificate",
"(",
")",
"(",
"cert",
"tls",
".",
"Certificate",
",",
"err",
"error",
")",
"{",
"cert",
".",
"PrivateKey",
",",
"err",
"=",
"rsa",
".",
"GenerateKey",
"(",
"rand",
".",
"Reader",
",",
"2048",
")",
"\n",
"if",
"err",... | // Creates a self-signed certificate in memory for use with tls.Config. | [
"Creates",
"a",
"self",
"-",
"signed",
"certificate",
"in",
"memory",
"for",
"use",
"with",
"tls",
".",
"Config",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/selfcert.go#L27-L60 |
16,513 | anacrolix/missinggo | timer.go | StoppedFuncTimer | func StoppedFuncTimer(f func()) (t *time.Timer) {
t = time.AfterFunc(math.MaxInt64, f)
if !t.Stop() {
panic("timer already fired")
}
return
} | go | func StoppedFuncTimer(f func()) (t *time.Timer) {
t = time.AfterFunc(math.MaxInt64, f)
if !t.Stop() {
panic("timer already fired")
}
return
} | [
"func",
"StoppedFuncTimer",
"(",
"f",
"func",
"(",
")",
")",
"(",
"t",
"*",
"time",
".",
"Timer",
")",
"{",
"t",
"=",
"time",
".",
"AfterFunc",
"(",
"math",
".",
"MaxInt64",
",",
"f",
")",
"\n",
"if",
"!",
"t",
".",
"Stop",
"(",
")",
"{",
"pa... | // Returns a time.Timer that calls f. The timer is initially stopped. | [
"Returns",
"a",
"time",
".",
"Timer",
"that",
"calls",
"f",
".",
"The",
"timer",
"is",
"initially",
"stopped",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/timer.go#L9-L15 |
16,514 | anacrolix/missinggo | iter/groupby.go | GroupBy | func GroupBy(input Iterator, keyFunc func(interface{}) interface{}) Iterator {
if keyFunc == nil {
keyFunc = func(a interface{}) interface{} { return a }
}
return &groupBy{
input: input,
keyFunc: keyFunc,
groupKey: uniqueKey,
curKey: uniqueKey,
}
} | go | func GroupBy(input Iterator, keyFunc func(interface{}) interface{}) Iterator {
if keyFunc == nil {
keyFunc = func(a interface{}) interface{} { return a }
}
return &groupBy{
input: input,
keyFunc: keyFunc,
groupKey: uniqueKey,
curKey: uniqueKey,
}
} | [
"func",
"GroupBy",
"(",
"input",
"Iterator",
",",
"keyFunc",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Iterator",
"{",
"if",
"keyFunc",
"==",
"nil",
"{",
"keyFunc",
"=",
"func",
"(",
"a",
"interface",
"{",
"}",
")",
"inter... | // Group by returns an iterator of iterators over the values of the input
// iterator that consecutively return the same value when input to the key
// function. Note that repeated calls to each value of the GroupBy Iterator
// does not return a new iterator over the values for that key. | [
"Group",
"by",
"returns",
"an",
"iterator",
"of",
"iterators",
"over",
"the",
"values",
"of",
"the",
"input",
"iterator",
"that",
"consecutively",
"return",
"the",
"same",
"value",
"when",
"input",
"to",
"the",
"key",
"function",
".",
"Note",
"that",
"repeat... | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/iter/groupby.go#L95-L105 |
16,515 | anacrolix/missinggo | httptoo/client.go | ClientTLSConfig | func ClientTLSConfig(cl *http.Client) *tls.Config {
if cl.Transport == nil {
cl.Transport = http.DefaultTransport
}
tr := cl.Transport.(*http.Transport)
if tr.TLSClientConfig == nil {
tr.TLSClientConfig = &tls.Config{}
}
return tr.TLSClientConfig
} | go | func ClientTLSConfig(cl *http.Client) *tls.Config {
if cl.Transport == nil {
cl.Transport = http.DefaultTransport
}
tr := cl.Transport.(*http.Transport)
if tr.TLSClientConfig == nil {
tr.TLSClientConfig = &tls.Config{}
}
return tr.TLSClientConfig
} | [
"func",
"ClientTLSConfig",
"(",
"cl",
"*",
"http",
".",
"Client",
")",
"*",
"tls",
".",
"Config",
"{",
"if",
"cl",
".",
"Transport",
"==",
"nil",
"{",
"cl",
".",
"Transport",
"=",
"http",
".",
"DefaultTransport",
"\n",
"}",
"\n",
"tr",
":=",
"cl",
... | // Returns the http.Client's TLS Config, traversing and generating any
// defaults along the way to get it. | [
"Returns",
"the",
"http",
".",
"Client",
"s",
"TLS",
"Config",
"traversing",
"and",
"generating",
"any",
"defaults",
"along",
"the",
"way",
"to",
"get",
"it",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/client.go#L10-L19 |
16,516 | anacrolix/missinggo | prioritybitmap/prioritybitmap.go | Set | func (me *PriorityBitmap) Set(bit int, priority int) bool {
if p, ok := me.priorities[bit]; ok && p == priority {
return false
}
if oldPriority, deleted := me.deleteBit(bit); deleted && oldPriority == priority {
panic("should have already returned")
}
if me.priorities == nil {
me.priorities = make(map[int]int)
}
me.priorities[bit] = priority
if me.om == nil {
me.om = orderedmap.New(bitLess)
}
_v, ok := me.om.GetOk(priority)
if !ok {
// No other bits with this priority, set it to a lone int.
me.om.Set(priority, bit)
return true
}
switch v := _v.(type) {
case int:
newV := bitSets.Get().(map[int]struct{})
newV[v] = struct{}{}
newV[bit] = struct{}{}
me.om.Set(priority, newV)
case map[int]struct{}:
v[bit] = struct{}{}
default:
panic(v)
}
return true
} | go | func (me *PriorityBitmap) Set(bit int, priority int) bool {
if p, ok := me.priorities[bit]; ok && p == priority {
return false
}
if oldPriority, deleted := me.deleteBit(bit); deleted && oldPriority == priority {
panic("should have already returned")
}
if me.priorities == nil {
me.priorities = make(map[int]int)
}
me.priorities[bit] = priority
if me.om == nil {
me.om = orderedmap.New(bitLess)
}
_v, ok := me.om.GetOk(priority)
if !ok {
// No other bits with this priority, set it to a lone int.
me.om.Set(priority, bit)
return true
}
switch v := _v.(type) {
case int:
newV := bitSets.Get().(map[int]struct{})
newV[v] = struct{}{}
newV[bit] = struct{}{}
me.om.Set(priority, newV)
case map[int]struct{}:
v[bit] = struct{}{}
default:
panic(v)
}
return true
} | [
"func",
"(",
"me",
"*",
"PriorityBitmap",
")",
"Set",
"(",
"bit",
"int",
",",
"priority",
"int",
")",
"bool",
"{",
"if",
"p",
",",
"ok",
":=",
"me",
".",
"priorities",
"[",
"bit",
"]",
";",
"ok",
"&&",
"p",
"==",
"priority",
"{",
"return",
"false... | // Returns true if the priority is changed, or the bit wasn't present. | [
"Returns",
"true",
"if",
"the",
"priority",
"is",
"changed",
"or",
"the",
"bit",
"wasn",
"t",
"present",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/prioritybitmap/prioritybitmap.go#L85-L117 |
16,517 | anacrolix/missinggo | prioritybitmap/prioritybitmap.go | GetPriority | func (me *PriorityBitmap) GetPriority(bit int) (prio int, ok bool) {
prio, ok = me.priorities[bit]
return
} | go | func (me *PriorityBitmap) GetPriority(bit int) (prio int, ok bool) {
prio, ok = me.priorities[bit]
return
} | [
"func",
"(",
"me",
"*",
"PriorityBitmap",
")",
"GetPriority",
"(",
"bit",
"int",
")",
"(",
"prio",
"int",
",",
"ok",
"bool",
")",
"{",
"prio",
",",
"ok",
"=",
"me",
".",
"priorities",
"[",
"bit",
"]",
"\n",
"return",
"\n",
"}"
] | // ok is false if the bit is not set. | [
"ok",
"is",
"false",
"if",
"the",
"bit",
"is",
"not",
"set",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/prioritybitmap/prioritybitmap.go#L176-L179 |
16,518 | anacrolix/missinggo | filecache/cache.go | WalkItems | func (me *Cache) WalkItems(cb func(ItemInfo)) {
me.mu.Lock()
defer me.mu.Unlock()
for k, ii := range me.items {
cb(ItemInfo{
Path: k,
Accessed: ii.Accessed,
Size: ii.Size,
})
}
} | go | func (me *Cache) WalkItems(cb func(ItemInfo)) {
me.mu.Lock()
defer me.mu.Unlock()
for k, ii := range me.items {
cb(ItemInfo{
Path: k,
Accessed: ii.Accessed,
Size: ii.Size,
})
}
} | [
"func",
"(",
"me",
"*",
"Cache",
")",
"WalkItems",
"(",
"cb",
"func",
"(",
"ItemInfo",
")",
")",
"{",
"me",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"me",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"k",
",",
"ii",
":=",
"range",... | // Calls the function for every item known to be in the cache. | [
"Calls",
"the",
"function",
"for",
"every",
"item",
"known",
"to",
"be",
"in",
"the",
"cache",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/filecache/cache.go#L43-L53 |
16,519 | anacrolix/missinggo | filecache/cache.go | SetCapacity | func (me *Cache) SetCapacity(capacity int64) {
me.mu.Lock()
defer me.mu.Unlock()
me.capacity = capacity
} | go | func (me *Cache) SetCapacity(capacity int64) {
me.mu.Lock()
defer me.mu.Unlock()
me.capacity = capacity
} | [
"func",
"(",
"me",
"*",
"Cache",
")",
"SetCapacity",
"(",
"capacity",
"int64",
")",
"{",
"me",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"me",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"me",
".",
"capacity",
"=",
"capacity",
"\n",
"}"
] | // Setting a negative capacity means unlimited. | [
"Setting",
"a",
"negative",
"capacity",
"means",
"unlimited",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/filecache/cache.go#L65-L69 |
16,520 | anacrolix/missinggo | filecache/cache.go | sanitizePath | func sanitizePath(p string) (ret key) {
if p == "" {
return
}
ret = key(path.Clean("/" + p))
if ret[0] == '/' {
ret = ret[1:]
}
return
} | go | func sanitizePath(p string) (ret key) {
if p == "" {
return
}
ret = key(path.Clean("/" + p))
if ret[0] == '/' {
ret = ret[1:]
}
return
} | [
"func",
"sanitizePath",
"(",
"p",
"string",
")",
"(",
"ret",
"key",
")",
"{",
"if",
"p",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"ret",
"=",
"key",
"(",
"path",
".",
"Clean",
"(",
"\"",
"\"",
"+",
"p",
")",
")",
"\n",
"if",
"ret",
... | // An empty return path is an error. | [
"An",
"empty",
"return",
"path",
"is",
"an",
"error",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/filecache/cache.go#L86-L95 |
16,521 | anacrolix/missinggo | filecache/cache.go | pruneEmptyDirs | func pruneEmptyDirs(root string, leaf string) (err error) {
rootInfo, err := os.Stat(root)
if err != nil {
return
}
for {
var leafInfo os.FileInfo
leafInfo, err = os.Stat(leaf)
if os.IsNotExist(err) {
goto parent
}
if err != nil {
return
}
if !leafInfo.IsDir() {
return
}
if os.SameFile(rootInfo, leafInfo) {
return
}
if os.Remove(leaf) != nil {
return
}
parent:
leaf = filepath.Dir(leaf)
}
} | go | func pruneEmptyDirs(root string, leaf string) (err error) {
rootInfo, err := os.Stat(root)
if err != nil {
return
}
for {
var leafInfo os.FileInfo
leafInfo, err = os.Stat(leaf)
if os.IsNotExist(err) {
goto parent
}
if err != nil {
return
}
if !leafInfo.IsDir() {
return
}
if os.SameFile(rootInfo, leafInfo) {
return
}
if os.Remove(leaf) != nil {
return
}
parent:
leaf = filepath.Dir(leaf)
}
} | [
"func",
"pruneEmptyDirs",
"(",
"root",
"string",
",",
"leaf",
"string",
")",
"(",
"err",
"error",
")",
"{",
"rootInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
... | // Leaf is a descendent of root. | [
"Leaf",
"is",
"a",
"descendent",
"of",
"root",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/filecache/cache.go#L98-L124 |
16,522 | anacrolix/missinggo | httpfile/defaultfs.go | GetLength | func GetLength(url string) (ret int64, err error) {
return DefaultFS.GetLength(url)
} | go | func GetLength(url string) (ret int64, err error) {
return DefaultFS.GetLength(url)
} | [
"func",
"GetLength",
"(",
"url",
"string",
")",
"(",
"ret",
"int64",
",",
"err",
"error",
")",
"{",
"return",
"DefaultFS",
".",
"GetLength",
"(",
"url",
")",
"\n",
"}"
] | // Returns the length of the resource in bytes. | [
"Returns",
"the",
"length",
"of",
"the",
"resource",
"in",
"bytes",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httpfile/defaultfs.go#L12-L14 |
16,523 | anacrolix/missinggo | slices/sort.go | Sort | func Sort(sl interface{}, less interface{}) interface{} {
sorter := sorter{
sl: reflect.ValueOf(sl),
less: reflect.ValueOf(less),
}
sort.Sort(&sorter)
return sorter.sl.Interface()
} | go | func Sort(sl interface{}, less interface{}) interface{} {
sorter := sorter{
sl: reflect.ValueOf(sl),
less: reflect.ValueOf(less),
}
sort.Sort(&sorter)
return sorter.sl.Interface()
} | [
"func",
"Sort",
"(",
"sl",
"interface",
"{",
"}",
",",
"less",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"sorter",
":=",
"sorter",
"{",
"sl",
":",
"reflect",
".",
"ValueOf",
"(",
"sl",
")",
",",
"less",
":",
"reflect",
".",
"ValueOf",... | // Sorts the slice in place. Returns sl for convenience. | [
"Sorts",
"the",
"slice",
"in",
"place",
".",
"Returns",
"sl",
"for",
"convenience",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/slices/sort.go#L10-L17 |
16,524 | anacrolix/missinggo | iter/iterutils.go | DeleteIndex | func (me *seq) DeleteIndex(index int) {
me.i[index] = me.Index(me.Len() - 1)
me.i = me.i[:me.Len()-1]
} | go | func (me *seq) DeleteIndex(index int) {
me.i[index] = me.Index(me.Len() - 1)
me.i = me.i[:me.Len()-1]
} | [
"func",
"(",
"me",
"*",
"seq",
")",
"DeleteIndex",
"(",
"index",
"int",
")",
"{",
"me",
".",
"i",
"[",
"index",
"]",
"=",
"me",
".",
"Index",
"(",
"me",
".",
"Len",
"(",
")",
"-",
"1",
")",
"\n",
"me",
".",
"i",
"=",
"me",
".",
"i",
"[",
... | // Remove the nth value from the sequence. | [
"Remove",
"the",
"nth",
"value",
"from",
"the",
"sequence",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/iter/iterutils.go#L27-L30 |
16,525 | anacrolix/missinggo | event.go | C | func (me *Event) C() <-chan struct{} {
if me.ch == nil {
me.ch = make(chan struct{})
}
return me.ch
} | go | func (me *Event) C() <-chan struct{} {
if me.ch == nil {
me.ch = make(chan struct{})
}
return me.ch
} | [
"func",
"(",
"me",
"*",
"Event",
")",
"C",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"if",
"me",
".",
"ch",
"==",
"nil",
"{",
"me",
".",
"ch",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"return",
"me",
".",
... | // Returns a chan that is closed when the event is true. | [
"Returns",
"a",
"chan",
"that",
"is",
"closed",
"when",
"the",
"event",
"is",
"true",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/event.go#L21-L26 |
16,526 | anacrolix/missinggo | addr.go | AddrPort | func AddrPort(addr net.Addr) int {
switch raw := addr.(type) {
case *net.UDPAddr:
return raw.Port
case *net.TCPAddr:
return raw.Port
default:
_, port, err := net.SplitHostPort(addr.String())
if err != nil {
panic(err)
}
i64, err := strconv.ParseInt(port, 0, 0)
if err != nil {
panic(err)
}
return int(i64)
}
} | go | func AddrPort(addr net.Addr) int {
switch raw := addr.(type) {
case *net.UDPAddr:
return raw.Port
case *net.TCPAddr:
return raw.Port
default:
_, port, err := net.SplitHostPort(addr.String())
if err != nil {
panic(err)
}
i64, err := strconv.ParseInt(port, 0, 0)
if err != nil {
panic(err)
}
return int(i64)
}
} | [
"func",
"AddrPort",
"(",
"addr",
"net",
".",
"Addr",
")",
"int",
"{",
"switch",
"raw",
":=",
"addr",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"UDPAddr",
":",
"return",
"raw",
".",
"Port",
"\n",
"case",
"*",
"net",
".",
"TCPAddr",
":",... | // Extracts the port as an integer from an address string. | [
"Extracts",
"the",
"port",
"as",
"an",
"integer",
"from",
"an",
"address",
"string",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/addr.go#L9-L26 |
16,527 | anacrolix/missinggo | bitmap/bitmap.go | Len | func (me *Bitmap) Len() int {
if me.RB == nil {
return 0
}
return int(me.RB.GetCardinality())
} | go | func (me *Bitmap) Len() int {
if me.RB == nil {
return 0
}
return int(me.RB.GetCardinality())
} | [
"func",
"(",
"me",
"*",
"Bitmap",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"me",
".",
"RB",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"int",
"(",
"me",
".",
"RB",
".",
"GetCardinality",
"(",
")",
")",
"\n",
"}"
] | // The number of set bits in the bitmap. Also known as cardinality. | [
"The",
"number",
"of",
"set",
"bits",
"in",
"the",
"bitmap",
".",
"Also",
"known",
"as",
"cardinality",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/bitmap/bitmap.go#L31-L36 |
16,528 | anacrolix/missinggo | bitmap/bitmap.go | IterTyped | func (me Bitmap) IterTyped(f func(int) bool) bool {
if me.RB == nil {
return true
}
it := me.RB.Iterator()
for it.HasNext() {
if !f(int(it.Next())) {
return false
}
}
return true
} | go | func (me Bitmap) IterTyped(f func(int) bool) bool {
if me.RB == nil {
return true
}
it := me.RB.Iterator()
for it.HasNext() {
if !f(int(it.Next())) {
return false
}
}
return true
} | [
"func",
"(",
"me",
"Bitmap",
")",
"IterTyped",
"(",
"f",
"func",
"(",
"int",
")",
"bool",
")",
"bool",
"{",
"if",
"me",
".",
"RB",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"it",
":=",
"me",
".",
"RB",
".",
"Iterator",
"(",
")",
"\... | // Returns true if all values were traversed without early termination. | [
"Returns",
"true",
"if",
"all",
"values",
"were",
"traversed",
"without",
"early",
"termination",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/bitmap/bitmap.go#L62-L73 |
16,529 | anacrolix/missinggo | url.go | URLOpaquePath | func URLOpaquePath(u *url.URL) string {
if u.Opaque != "" {
return u.Opaque
}
return u.Path
} | go | func URLOpaquePath(u *url.URL) string {
if u.Opaque != "" {
return u.Opaque
}
return u.Path
} | [
"func",
"URLOpaquePath",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"string",
"{",
"if",
"u",
".",
"Opaque",
"!=",
"\"",
"\"",
"{",
"return",
"u",
".",
"Opaque",
"\n",
"}",
"\n",
"return",
"u",
".",
"Path",
"\n",
"}"
] | // Returns URL opaque as an unrooted path. | [
"Returns",
"URL",
"opaque",
"as",
"an",
"unrooted",
"path",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/url.go#L9-L14 |
16,530 | anacrolix/missinggo | cmd/filecache/main.go | parseContentRangeFirstByte | func parseContentRangeFirstByte(s string) int64 {
matches := regexp.MustCompile(`(\d+)-`).FindStringSubmatch(s)
if matches == nil {
return 0
}
ret, _ := strconv.ParseInt(matches[1], 0, 64)
return ret
} | go | func parseContentRangeFirstByte(s string) int64 {
matches := regexp.MustCompile(`(\d+)-`).FindStringSubmatch(s)
if matches == nil {
return 0
}
ret, _ := strconv.ParseInt(matches[1], 0, 64)
return ret
} | [
"func",
"parseContentRangeFirstByte",
"(",
"s",
"string",
")",
"int64",
"{",
"matches",
":=",
"regexp",
".",
"MustCompile",
"(",
"`(\\d+)-`",
")",
".",
"FindStringSubmatch",
"(",
"s",
")",
"\n",
"if",
"matches",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
... | // Parses out the first byte from a Content-Range header. Returns 0 if it
// isn't found, which is what is implied if there is no header. | [
"Parses",
"out",
"the",
"first",
"byte",
"from",
"a",
"Content",
"-",
"Range",
"header",
".",
"Returns",
"0",
"if",
"it",
"isn",
"t",
"found",
"which",
"is",
"what",
"is",
"implied",
"if",
"there",
"is",
"no",
"header",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/cmd/filecache/main.go#L44-L51 |
16,531 | anacrolix/missinggo | reqctx/value.go | SetRequestOnce | func (me contextValue) SetRequestOnce(r *http.Request, val interface{}) *http.Request {
expect.Nil(me.Get(r.Context()))
return r.WithContext(context.WithValue(r.Context(), me.key, val))
} | go | func (me contextValue) SetRequestOnce(r *http.Request, val interface{}) *http.Request {
expect.Nil(me.Get(r.Context()))
return r.WithContext(context.WithValue(r.Context(), me.key, val))
} | [
"func",
"(",
"me",
"contextValue",
")",
"SetRequestOnce",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"val",
"interface",
"{",
"}",
")",
"*",
"http",
".",
"Request",
"{",
"expect",
".",
"Nil",
"(",
"me",
".",
"Get",
"(",
"r",
".",
"Context",
"(",
... | // Sets the value on the Request. It must not have been already set. | [
"Sets",
"the",
"value",
"on",
"the",
"Request",
".",
"It",
"must",
"not",
"have",
"been",
"already",
"set",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/reqctx/value.go#L23-L26 |
16,532 | anacrolix/missinggo | reqctx/value.go | SetMiddleware | func (me contextValue) SetMiddleware(val interface{}) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r = me.SetRequestOnce(r, val)
h.ServeHTTP(w, r)
})
}
} | go | func (me contextValue) SetMiddleware(val interface{}) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r = me.SetRequestOnce(r, val)
h.ServeHTTP(w, r)
})
}
} | [
"func",
"(",
"me",
"contextValue",
")",
"SetMiddleware",
"(",
"val",
"interface",
"{",
"}",
")",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"func",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"... | // Returns a middleware that sets the value in the Request's Context. | [
"Returns",
"a",
"middleware",
"that",
"sets",
"the",
"value",
"in",
"the",
"Request",
"s",
"Context",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/reqctx/value.go#L29-L36 |
16,533 | anacrolix/missinggo | futures/funcs.go | AsCompleted | func AsCompleted(fs ...*F) <-chan *F {
ret := make(chan *F, len(fs))
var wg sync.WaitGroup
for _, f := range fs {
wg.Add(1)
go func(f *F) {
defer wg.Done()
<-f.Done()
ret <- f
}(f)
}
go func() {
wg.Wait()
close(ret)
}()
return ret
} | go | func AsCompleted(fs ...*F) <-chan *F {
ret := make(chan *F, len(fs))
var wg sync.WaitGroup
for _, f := range fs {
wg.Add(1)
go func(f *F) {
defer wg.Done()
<-f.Done()
ret <- f
}(f)
}
go func() {
wg.Wait()
close(ret)
}()
return ret
} | [
"func",
"AsCompleted",
"(",
"fs",
"...",
"*",
"F",
")",
"<-",
"chan",
"*",
"F",
"{",
"ret",
":=",
"make",
"(",
"chan",
"*",
"F",
",",
"len",
"(",
"fs",
")",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"_",
",",
"f",
":=",
... | // Sends each future as it completes on the returned chan, closing it when
// everything has been sent. | [
"Sends",
"each",
"future",
"as",
"it",
"completes",
"on",
"the",
"returned",
"chan",
"closing",
"it",
"when",
"everything",
"has",
"been",
"sent",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/futures/funcs.go#L15-L31 |
16,534 | anacrolix/missinggo | httptoo/request.go | RequestIsForLocalhost | func RequestIsForLocalhost(r *http.Request) bool {
hostHost := missinggo.SplitHostMaybePort(r.Host).Host
if ip := net.ParseIP(hostHost); ip != nil {
return ip.IsLoopback()
}
return hostHost == "localhost"
} | go | func RequestIsForLocalhost(r *http.Request) bool {
hostHost := missinggo.SplitHostMaybePort(r.Host).Host
if ip := net.ParseIP(hostHost); ip != nil {
return ip.IsLoopback()
}
return hostHost == "localhost"
} | [
"func",
"RequestIsForLocalhost",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"hostHost",
":=",
"missinggo",
".",
"SplitHostMaybePort",
"(",
"r",
".",
"Host",
")",
".",
"Host",
"\n",
"if",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"hostHost",
... | // Request is intended for localhost, either with a localhost name, or
// loopback IP. | [
"Request",
"is",
"intended",
"for",
"localhost",
"either",
"with",
"a",
"localhost",
"name",
"or",
"loopback",
"IP",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/request.go#L12-L18 |
16,535 | anacrolix/missinggo | httptoo/request.go | RequestIsFromLocalhost | func RequestIsFromLocalhost(r *http.Request) bool {
return net.ParseIP(missinggo.SplitHostMaybePort(r.RemoteAddr).Host).IsLoopback()
} | go | func RequestIsFromLocalhost(r *http.Request) bool {
return net.ParseIP(missinggo.SplitHostMaybePort(r.RemoteAddr).Host).IsLoopback()
} | [
"func",
"RequestIsFromLocalhost",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"return",
"net",
".",
"ParseIP",
"(",
"missinggo",
".",
"SplitHostMaybePort",
"(",
"r",
".",
"RemoteAddr",
")",
".",
"Host",
")",
".",
"IsLoopback",
"(",
")",
"\n"... | // Request originated from a loopback IP. | [
"Request",
"originated",
"from",
"a",
"loopback",
"IP",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/request.go#L21-L23 |
16,536 | anacrolix/missinggo | chans/drain.go | Drain | func Drain(ch interface{}) {
chValue := reflect.ValueOf(ch)
for {
_, ok := chValue.Recv()
if !ok {
break
}
}
} | go | func Drain(ch interface{}) {
chValue := reflect.ValueOf(ch)
for {
_, ok := chValue.Recv()
if !ok {
break
}
}
} | [
"func",
"Drain",
"(",
"ch",
"interface",
"{",
"}",
")",
"{",
"chValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"ch",
")",
"\n",
"for",
"{",
"_",
",",
"ok",
":=",
"chValue",
".",
"Recv",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"break",
"\n",
"}",
... | // Receives from any channel until it's closed. | [
"Receives",
"from",
"any",
"channel",
"until",
"it",
"s",
"closed",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/chans/drain.go#L8-L16 |
16,537 | anacrolix/missinggo | httpfile/misc.go | instanceLength | func instanceLength(r *http.Response) (l int64, err error) {
switch r.StatusCode {
case http.StatusOK:
l, err = strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
return
case http.StatusPartialContent:
cr, parseOk := httptoo.ParseBytesContentRange(r.Header.Get("Content-Range"))
l = cr.Length
if !parseOk {
err = errors.New("error parsing Content-Range")
}
return
default:
err = errors.New("unhandled status code")
return
}
} | go | func instanceLength(r *http.Response) (l int64, err error) {
switch r.StatusCode {
case http.StatusOK:
l, err = strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
return
case http.StatusPartialContent:
cr, parseOk := httptoo.ParseBytesContentRange(r.Header.Get("Content-Range"))
l = cr.Length
if !parseOk {
err = errors.New("error parsing Content-Range")
}
return
default:
err = errors.New("unhandled status code")
return
}
} | [
"func",
"instanceLength",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"(",
"l",
"int64",
",",
"err",
"error",
")",
"{",
"switch",
"r",
".",
"StatusCode",
"{",
"case",
"http",
".",
"StatusOK",
":",
"l",
",",
"err",
"=",
"strconv",
".",
"ParseInt",
... | // ok is false if the response just doesn't specify anything we handle. | [
"ok",
"is",
"false",
"if",
"the",
"response",
"just",
"doesn",
"t",
"specify",
"anything",
"we",
"handle",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httpfile/misc.go#L17-L33 |
16,538 | anacrolix/missinggo | httptoo/url.go | RequestedURL | func RequestedURL(r *http.Request) (ret *url.URL) {
ret = CopyURL(r.URL)
ret.Host = r.Host
ret.Scheme = OriginatingProtocol(r)
return
} | go | func RequestedURL(r *http.Request) (ret *url.URL) {
ret = CopyURL(r.URL)
ret.Host = r.Host
ret.Scheme = OriginatingProtocol(r)
return
} | [
"func",
"RequestedURL",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"ret",
"*",
"url",
".",
"URL",
")",
"{",
"ret",
"=",
"CopyURL",
"(",
"r",
".",
"URL",
")",
"\n",
"ret",
".",
"Host",
"=",
"r",
".",
"Host",
"\n",
"ret",
".",
"Scheme",
"... | // Reconstructs the URL that would have produced the given Request.
// Request.URLs are not fully populated in http.Server handlers. | [
"Reconstructs",
"the",
"URL",
"that",
"would",
"have",
"produced",
"the",
"given",
"Request",
".",
"Request",
".",
"URLs",
"are",
"not",
"fully",
"populated",
"in",
"http",
".",
"Server",
"handlers",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/url.go#L23-L28 |
16,539 | anacrolix/missinggo | httptoo/httptoo.go | NukeCookie | func NukeCookie(w http.ResponseWriter, r *http.Request, name, path string) {
parts := strings.Split(missinggo.SplitHostMaybePort(r.Host).Host, ".")
for i := range iter.N(len(parts) + 1) { // Include the empty domain.
http.SetCookie(w, &http.Cookie{
Name: name,
MaxAge: -1,
Path: path,
Domain: strings.Join(parts[i:], "."),
})
}
} | go | func NukeCookie(w http.ResponseWriter, r *http.Request, name, path string) {
parts := strings.Split(missinggo.SplitHostMaybePort(r.Host).Host, ".")
for i := range iter.N(len(parts) + 1) { // Include the empty domain.
http.SetCookie(w, &http.Cookie{
Name: name,
MaxAge: -1,
Path: path,
Domain: strings.Join(parts[i:], "."),
})
}
} | [
"func",
"NukeCookie",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"name",
",",
"path",
"string",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"missinggo",
".",
"SplitHostMaybePort",
"(",
"r",
".",
"Hos... | // Clears the named cookie for every domain that leads to the current one. | [
"Clears",
"the",
"named",
"cookie",
"for",
"every",
"domain",
"that",
"leads",
"to",
"the",
"current",
"one",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/httptoo.go#L24-L34 |
16,540 | anacrolix/missinggo | httptoo/inproc_roundtrip.go | CloseNotify | func (me *responseWriter) CloseNotify() <-chan bool {
ret := make(chan bool, 1)
go func() {
<-me.bodyClosed.C()
ret <- true
}()
return ret
} | go | func (me *responseWriter) CloseNotify() <-chan bool {
ret := make(chan bool, 1)
go func() {
<-me.bodyClosed.C()
ret <- true
}()
return ret
} | [
"func",
"(",
"me",
"*",
"responseWriter",
")",
"CloseNotify",
"(",
")",
"<-",
"chan",
"bool",
"{",
"ret",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"<-",
"me",
".",
"bodyClosed",
".",
"C",
"(",
")",
"\... | // Use Request.Context.Done instead. | [
"Use",
"Request",
".",
"Context",
".",
"Done",
"instead",
"."
] | 3d85a149c8127dad7dd81d6d92df99407e67e874 | https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/httptoo/inproc_roundtrip.go#L27-L34 |
16,541 | morikuni/aec | sgr.go | NewRGB3Bit | func NewRGB3Bit(r, g, b uint8) RGB3Bit {
return RGB3Bit((r >> 7) | ((g >> 6) & 0x2) | ((b >> 5) & 0x4))
} | go | func NewRGB3Bit(r, g, b uint8) RGB3Bit {
return RGB3Bit((r >> 7) | ((g >> 6) & 0x2) | ((b >> 5) & 0x4))
} | [
"func",
"NewRGB3Bit",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"RGB3Bit",
"{",
"return",
"RGB3Bit",
"(",
"(",
"r",
">>",
"7",
")",
"|",
"(",
"(",
"g",
">>",
"6",
")",
"&",
"0x2",
")",
"|",
"(",
"(",
"b",
">>",
"5",
")",
"&",
"0x4",
")"... | // NewRGB3Bit create a RGB3Bit from given RGB. | [
"NewRGB3Bit",
"create",
"a",
"RGB3Bit",
"from",
"given",
"RGB",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/sgr.go#L18-L20 |
16,542 | morikuni/aec | sgr.go | NewRGB8Bit | func NewRGB8Bit(r, g, b uint8) RGB8Bit {
return RGB8Bit(16 + 36*(r/43) + 6*(g/43) + b/43)
} | go | func NewRGB8Bit(r, g, b uint8) RGB8Bit {
return RGB8Bit(16 + 36*(r/43) + 6*(g/43) + b/43)
} | [
"func",
"NewRGB8Bit",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"RGB8Bit",
"{",
"return",
"RGB8Bit",
"(",
"16",
"+",
"36",
"*",
"(",
"r",
"/",
"43",
")",
"+",
"6",
"*",
"(",
"g",
"/",
"43",
")",
"+",
"b",
"/",
"43",
")",
"\n",
"}"
] | // NewRGB8Bit create a RGB8Bit from given RGB. | [
"NewRGB8Bit",
"create",
"a",
"RGB8Bit",
"from",
"given",
"RGB",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/sgr.go#L23-L25 |
16,543 | morikuni/aec | sgr.go | FullColorB | func FullColorB(r, g, b uint8) ANSI {
return newAnsi(fmt.Sprintf(esc+"48;2;%d;%d;%dm", r, g, b))
} | go | func FullColorB(r, g, b uint8) ANSI {
return newAnsi(fmt.Sprintf(esc+"48;2;%d;%d;%dm", r, g, b))
} | [
"func",
"FullColorB",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"ANSI",
"{",
"return",
"newAnsi",
"(",
"fmt",
".",
"Sprintf",
"(",
"esc",
"+",
"\"",
"\"",
",",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // FullColorB set the foreground color of text. | [
"FullColorB",
"set",
"the",
"foreground",
"color",
"of",
"text",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/sgr.go#L53-L55 |
16,544 | morikuni/aec | ansi.go | Apply | func Apply(s string, ansi ...ANSI) string {
if len(ansi) == 0 {
return s
}
return concat(ansi).Apply(s)
} | go | func Apply(s string, ansi ...ANSI) string {
if len(ansi) == 0 {
return s
}
return concat(ansi).Apply(s)
} | [
"func",
"Apply",
"(",
"s",
"string",
",",
"ansi",
"...",
"ANSI",
")",
"string",
"{",
"if",
"len",
"(",
"ansi",
")",
"==",
"0",
"{",
"return",
"s",
"\n",
"}",
"\n",
"return",
"concat",
"(",
"ansi",
")",
".",
"Apply",
"(",
"s",
")",
"\n",
"}"
] | // Apply wraps given string in ANSIs. | [
"Apply",
"wraps",
"given",
"string",
"in",
"ANSIs",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/ansi.go#L46-L51 |
16,545 | morikuni/aec | builder.go | With | func (builder *Builder) With(a ...ANSI) *Builder {
return NewBuilder(builder.ANSI.With(a...))
} | go | func (builder *Builder) With(a ...ANSI) *Builder {
return NewBuilder(builder.ANSI.With(a...))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"With",
"(",
"a",
"...",
"ANSI",
")",
"*",
"Builder",
"{",
"return",
"NewBuilder",
"(",
"builder",
".",
"ANSI",
".",
"With",
"(",
"a",
"...",
")",
")",
"\n",
"}"
] | // With is a syntax for With. | [
"With",
"is",
"a",
"syntax",
"for",
"With",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L17-L19 |
16,546 | morikuni/aec | builder.go | Up | func (builder *Builder) Up(n uint) *Builder {
return builder.With(Up(n))
} | go | func (builder *Builder) Up(n uint) *Builder {
return builder.With(Up(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Up",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Up",
"(",
"n",
")",
")",
"\n",
"}"
] | // Up is a syntax for Up. | [
"Up",
"is",
"a",
"syntax",
"for",
"Up",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L22-L24 |
16,547 | morikuni/aec | builder.go | Down | func (builder *Builder) Down(n uint) *Builder {
return builder.With(Down(n))
} | go | func (builder *Builder) Down(n uint) *Builder {
return builder.With(Down(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Down",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Down",
"(",
"n",
")",
")",
"\n",
"}"
] | // Down is a syntax for Down. | [
"Down",
"is",
"a",
"syntax",
"for",
"Down",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L27-L29 |
16,548 | morikuni/aec | builder.go | Right | func (builder *Builder) Right(n uint) *Builder {
return builder.With(Right(n))
} | go | func (builder *Builder) Right(n uint) *Builder {
return builder.With(Right(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Right",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Right",
"(",
"n",
")",
")",
"\n",
"}"
] | // Right is a syntax for Right. | [
"Right",
"is",
"a",
"syntax",
"for",
"Right",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L32-L34 |
16,549 | morikuni/aec | builder.go | Left | func (builder *Builder) Left(n uint) *Builder {
return builder.With(Left(n))
} | go | func (builder *Builder) Left(n uint) *Builder {
return builder.With(Left(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Left",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Left",
"(",
"n",
")",
")",
"\n",
"}"
] | // Left is a syntax for Left. | [
"Left",
"is",
"a",
"syntax",
"for",
"Left",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L37-L39 |
16,550 | morikuni/aec | builder.go | NextLine | func (builder *Builder) NextLine(n uint) *Builder {
return builder.With(NextLine(n))
} | go | func (builder *Builder) NextLine(n uint) *Builder {
return builder.With(NextLine(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"NextLine",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"NextLine",
"(",
"n",
")",
")",
"\n",
"}"
] | // NextLine is a syntax for NextLine. | [
"NextLine",
"is",
"a",
"syntax",
"for",
"NextLine",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L42-L44 |
16,551 | morikuni/aec | builder.go | PreviousLine | func (builder *Builder) PreviousLine(n uint) *Builder {
return builder.With(PreviousLine(n))
} | go | func (builder *Builder) PreviousLine(n uint) *Builder {
return builder.With(PreviousLine(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"PreviousLine",
"(",
"n",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"PreviousLine",
"(",
"n",
")",
")",
"\n",
"}"
] | // PreviousLine is a syntax for PreviousLine. | [
"PreviousLine",
"is",
"a",
"syntax",
"for",
"PreviousLine",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L47-L49 |
16,552 | morikuni/aec | builder.go | Column | func (builder *Builder) Column(col uint) *Builder {
return builder.With(Column(col))
} | go | func (builder *Builder) Column(col uint) *Builder {
return builder.With(Column(col))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Column",
"(",
"col",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Column",
"(",
"col",
")",
")",
"\n",
"}"
] | // Column is a syntax for Column. | [
"Column",
"is",
"a",
"syntax",
"for",
"Column",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L52-L54 |
16,553 | morikuni/aec | builder.go | Position | func (builder *Builder) Position(row, col uint) *Builder {
return builder.With(Position(row, col))
} | go | func (builder *Builder) Position(row, col uint) *Builder {
return builder.With(Position(row, col))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Position",
"(",
"row",
",",
"col",
"uint",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Position",
"(",
"row",
",",
"col",
")",
")",
"\n",
"}"
] | // Position is a syntax for Position. | [
"Position",
"is",
"a",
"syntax",
"for",
"Position",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L57-L59 |
16,554 | morikuni/aec | builder.go | EraseDisplay | func (builder *Builder) EraseDisplay(m EraseMode) *Builder {
return builder.With(EraseDisplay(m))
} | go | func (builder *Builder) EraseDisplay(m EraseMode) *Builder {
return builder.With(EraseDisplay(m))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"EraseDisplay",
"(",
"m",
"EraseMode",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"EraseDisplay",
"(",
"m",
")",
")",
"\n",
"}"
] | // EraseDisplay is a syntax for EraseDisplay. | [
"EraseDisplay",
"is",
"a",
"syntax",
"for",
"EraseDisplay",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L62-L64 |
16,555 | morikuni/aec | builder.go | EraseLine | func (builder *Builder) EraseLine(m EraseMode) *Builder {
return builder.With(EraseLine(m))
} | go | func (builder *Builder) EraseLine(m EraseMode) *Builder {
return builder.With(EraseLine(m))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"EraseLine",
"(",
"m",
"EraseMode",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"EraseLine",
"(",
"m",
")",
")",
"\n",
"}"
] | // EraseLine is a syntax for EraseLine. | [
"EraseLine",
"is",
"a",
"syntax",
"for",
"EraseLine",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L67-L69 |
16,556 | morikuni/aec | builder.go | ScrollUp | func (builder *Builder) ScrollUp(n int) *Builder {
return builder.With(ScrollUp(n))
} | go | func (builder *Builder) ScrollUp(n int) *Builder {
return builder.With(ScrollUp(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"ScrollUp",
"(",
"n",
"int",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"ScrollUp",
"(",
"n",
")",
")",
"\n",
"}"
] | // ScrollUp is a syntax for ScrollUp. | [
"ScrollUp",
"is",
"a",
"syntax",
"for",
"ScrollUp",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L72-L74 |
16,557 | morikuni/aec | builder.go | ScrollDown | func (builder *Builder) ScrollDown(n int) *Builder {
return builder.With(ScrollDown(n))
} | go | func (builder *Builder) ScrollDown(n int) *Builder {
return builder.With(ScrollDown(n))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"ScrollDown",
"(",
"n",
"int",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"ScrollDown",
"(",
"n",
")",
")",
"\n",
"}"
] | // ScrollDown is a syntax for ScrollDown. | [
"ScrollDown",
"is",
"a",
"syntax",
"for",
"ScrollDown",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L77-L79 |
16,558 | morikuni/aec | builder.go | Color3BitF | func (builder *Builder) Color3BitF(c RGB3Bit) *Builder {
return builder.With(Color3BitF(c))
} | go | func (builder *Builder) Color3BitF(c RGB3Bit) *Builder {
return builder.With(Color3BitF(c))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Color3BitF",
"(",
"c",
"RGB3Bit",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Color3BitF",
"(",
"c",
")",
")",
"\n",
"}"
] | // Color3BitF is a syntax for Color3BitF. | [
"Color3BitF",
"is",
"a",
"syntax",
"for",
"Color3BitF",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L337-L339 |
16,559 | morikuni/aec | builder.go | Color3BitB | func (builder *Builder) Color3BitB(c RGB3Bit) *Builder {
return builder.With(Color3BitB(c))
} | go | func (builder *Builder) Color3BitB(c RGB3Bit) *Builder {
return builder.With(Color3BitB(c))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Color3BitB",
"(",
"c",
"RGB3Bit",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Color3BitB",
"(",
"c",
")",
")",
"\n",
"}"
] | // Color3BitB is a syntax for Color3BitB. | [
"Color3BitB",
"is",
"a",
"syntax",
"for",
"Color3BitB",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L342-L344 |
16,560 | morikuni/aec | builder.go | Color8BitF | func (builder *Builder) Color8BitF(c RGB8Bit) *Builder {
return builder.With(Color8BitF(c))
} | go | func (builder *Builder) Color8BitF(c RGB8Bit) *Builder {
return builder.With(Color8BitF(c))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Color8BitF",
"(",
"c",
"RGB8Bit",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Color8BitF",
"(",
"c",
")",
")",
"\n",
"}"
] | // Color8BitF is a syntax for Color8BitF. | [
"Color8BitF",
"is",
"a",
"syntax",
"for",
"Color8BitF",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L347-L349 |
16,561 | morikuni/aec | builder.go | Color8BitB | func (builder *Builder) Color8BitB(c RGB8Bit) *Builder {
return builder.With(Color8BitB(c))
} | go | func (builder *Builder) Color8BitB(c RGB8Bit) *Builder {
return builder.With(Color8BitB(c))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Color8BitB",
"(",
"c",
"RGB8Bit",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"Color8BitB",
"(",
"c",
")",
")",
"\n",
"}"
] | // Color8BitB is a syntax for Color8BitB. | [
"Color8BitB",
"is",
"a",
"syntax",
"for",
"Color8BitB",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L352-L354 |
16,562 | morikuni/aec | builder.go | FullColorF | func (builder *Builder) FullColorF(r, g, b uint8) *Builder {
return builder.With(FullColorF(r, g, b))
} | go | func (builder *Builder) FullColorF(r, g, b uint8) *Builder {
return builder.With(FullColorF(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"FullColorF",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"FullColorF",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // FullColorF is a syntax for FullColorF. | [
"FullColorF",
"is",
"a",
"syntax",
"for",
"FullColorF",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L357-L359 |
16,563 | morikuni/aec | builder.go | FullColorB | func (builder *Builder) FullColorB(r, g, b uint8) *Builder {
return builder.With(FullColorB(r, g, b))
} | go | func (builder *Builder) FullColorB(r, g, b uint8) *Builder {
return builder.With(FullColorB(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"FullColorB",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"With",
"(",
"FullColorB",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // FullColorB is a syntax for FullColorB. | [
"FullColorB",
"is",
"a",
"syntax",
"for",
"FullColorB",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L362-L364 |
16,564 | morikuni/aec | builder.go | RGB3BitF | func (builder *Builder) RGB3BitF(r, g, b uint8) *Builder {
return builder.Color3BitF(NewRGB3Bit(r, g, b))
} | go | func (builder *Builder) RGB3BitF(r, g, b uint8) *Builder {
return builder.Color3BitF(NewRGB3Bit(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"RGB3BitF",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"Color3BitF",
"(",
"NewRGB3Bit",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // RGB3BitF is a syntax for Color3BitF with NewRGB3Bit. | [
"RGB3BitF",
"is",
"a",
"syntax",
"for",
"Color3BitF",
"with",
"NewRGB3Bit",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L367-L369 |
16,565 | morikuni/aec | builder.go | RGB3BitB | func (builder *Builder) RGB3BitB(r, g, b uint8) *Builder {
return builder.Color3BitB(NewRGB3Bit(r, g, b))
} | go | func (builder *Builder) RGB3BitB(r, g, b uint8) *Builder {
return builder.Color3BitB(NewRGB3Bit(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"RGB3BitB",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"Color3BitB",
"(",
"NewRGB3Bit",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // RGB3BitB is a syntax for Color3BitB with NewRGB3Bit. | [
"RGB3BitB",
"is",
"a",
"syntax",
"for",
"Color3BitB",
"with",
"NewRGB3Bit",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L372-L374 |
16,566 | morikuni/aec | builder.go | RGB8BitF | func (builder *Builder) RGB8BitF(r, g, b uint8) *Builder {
return builder.Color8BitF(NewRGB8Bit(r, g, b))
} | go | func (builder *Builder) RGB8BitF(r, g, b uint8) *Builder {
return builder.Color8BitF(NewRGB8Bit(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"RGB8BitF",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"Color8BitF",
"(",
"NewRGB8Bit",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // RGB8BitF is a syntax for Color8BitF with NewRGB8Bit. | [
"RGB8BitF",
"is",
"a",
"syntax",
"for",
"Color8BitF",
"with",
"NewRGB8Bit",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L377-L379 |
16,567 | morikuni/aec | builder.go | RGB8BitB | func (builder *Builder) RGB8BitB(r, g, b uint8) *Builder {
return builder.Color8BitB(NewRGB8Bit(r, g, b))
} | go | func (builder *Builder) RGB8BitB(r, g, b uint8) *Builder {
return builder.Color8BitB(NewRGB8Bit(r, g, b))
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"RGB8BitB",
"(",
"r",
",",
"g",
",",
"b",
"uint8",
")",
"*",
"Builder",
"{",
"return",
"builder",
".",
"Color8BitB",
"(",
"NewRGB8Bit",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
"\n",
"}"
] | // RGB8BitB is a syntax for Color8BitB with NewRGB8Bit. | [
"RGB8BitB",
"is",
"a",
"syntax",
"for",
"Color8BitB",
"with",
"NewRGB8Bit",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/builder.go#L382-L384 |
16,568 | morikuni/aec | aec.go | Up | func Up(n uint) ANSI {
if n == 0 {
return empty
}
return newAnsi(fmt.Sprintf(esc+"%dA", n))
} | go | func Up(n uint) ANSI {
if n == 0 {
return empty
}
return newAnsi(fmt.Sprintf(esc+"%dA", n))
} | [
"func",
"Up",
"(",
"n",
"uint",
")",
"ANSI",
"{",
"if",
"n",
"==",
"0",
"{",
"return",
"empty",
"\n",
"}",
"\n",
"return",
"newAnsi",
"(",
"fmt",
".",
"Sprintf",
"(",
"esc",
"+",
"\"",
"\"",
",",
"n",
")",
")",
"\n",
"}"
] | // Up moves up the cursor. | [
"Up",
"moves",
"up",
"the",
"cursor",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/aec.go#L38-L43 |
16,569 | morikuni/aec | aec.go | Position | func Position(row, col uint) ANSI {
return newAnsi(fmt.Sprintf(esc+"%d;%dH", row, col))
} | go | func Position(row, col uint) ANSI {
return newAnsi(fmt.Sprintf(esc+"%d;%dH", row, col))
} | [
"func",
"Position",
"(",
"row",
",",
"col",
"uint",
")",
"ANSI",
"{",
"return",
"newAnsi",
"(",
"fmt",
".",
"Sprintf",
"(",
"esc",
"+",
"\"",
"\"",
",",
"row",
",",
"col",
")",
")",
"\n",
"}"
] | // Position set the cursor position to a given absolute position. | [
"Position",
"set",
"the",
"cursor",
"position",
"to",
"a",
"given",
"absolute",
"position",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/aec.go#L91-L93 |
16,570 | morikuni/aec | aec.go | ScrollDown | func ScrollDown(n int) ANSI {
if n == 0 {
return empty
}
return newAnsi(fmt.Sprintf(esc+"%dT", n))
} | go | func ScrollDown(n int) ANSI {
if n == 0 {
return empty
}
return newAnsi(fmt.Sprintf(esc+"%dT", n))
} | [
"func",
"ScrollDown",
"(",
"n",
"int",
")",
"ANSI",
"{",
"if",
"n",
"==",
"0",
"{",
"return",
"empty",
"\n",
"}",
"\n",
"return",
"newAnsi",
"(",
"fmt",
".",
"Sprintf",
"(",
"esc",
"+",
"\"",
"\"",
",",
"n",
")",
")",
"\n",
"}"
] | // ScrollDown scrolls down the page. | [
"ScrollDown",
"scrolls",
"down",
"the",
"page",
"."
] | 39771216ff4c63d11f5e604076f9c45e8be1067b | https://github.com/morikuni/aec/blob/39771216ff4c63d11f5e604076f9c45e8be1067b/aec.go#L114-L119 |
16,571 | dgryski/go-minhash | bottomk.go | NewBottomK | func NewBottomK(h Hash64, k int) *BottomK {
return &BottomK{
size: k,
h: h,
minimums: &intHeap{},
}
} | go | func NewBottomK(h Hash64, k int) *BottomK {
return &BottomK{
size: k,
h: h,
minimums: &intHeap{},
}
} | [
"func",
"NewBottomK",
"(",
"h",
"Hash64",
",",
"k",
"int",
")",
"*",
"BottomK",
"{",
"return",
"&",
"BottomK",
"{",
"size",
":",
"k",
",",
"h",
":",
"h",
",",
"minimums",
":",
"&",
"intHeap",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewBottomK returns a new BottomK implementation. | [
"NewBottomK",
"returns",
"a",
"new",
"BottomK",
"implementation",
"."
] | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/bottomk.go#L56-L62 |
16,572 | dgryski/go-minhash | bottomk.go | Signature | func (m *BottomK) Signature() []uint64 {
mins := make(intHeap, len(*m.minimums))
copy(mins, *m.minimums)
sort.Sort(mins)
return mins
} | go | func (m *BottomK) Signature() []uint64 {
mins := make(intHeap, len(*m.minimums))
copy(mins, *m.minimums)
sort.Sort(mins)
return mins
} | [
"func",
"(",
"m",
"*",
"BottomK",
")",
"Signature",
"(",
")",
"[",
"]",
"uint64",
"{",
"mins",
":=",
"make",
"(",
"intHeap",
",",
"len",
"(",
"*",
"m",
".",
"minimums",
")",
")",
"\n",
"copy",
"(",
"mins",
",",
"*",
"m",
".",
"minimums",
")",
... | // Signature returns a signature for the set. | [
"Signature",
"returns",
"a",
"signature",
"for",
"the",
"set",
"."
] | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/bottomk.go#L107-L112 |
16,573 | dgryski/go-minhash | minwise.go | NewMinWise | func NewMinWise(h1, h2 Hash64, size int) *MinWise {
minimums := make([]uint64, size)
for i := range minimums {
minimums[i] = math.MaxUint64
}
return &MinWise{
h1: h1,
h2: h2,
minimums: minimums,
}
} | go | func NewMinWise(h1, h2 Hash64, size int) *MinWise {
minimums := make([]uint64, size)
for i := range minimums {
minimums[i] = math.MaxUint64
}
return &MinWise{
h1: h1,
h2: h2,
minimums: minimums,
}
} | [
"func",
"NewMinWise",
"(",
"h1",
",",
"h2",
"Hash64",
",",
"size",
"int",
")",
"*",
"MinWise",
"{",
"minimums",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"size",
")",
"\n",
"for",
"i",
":=",
"range",
"minimums",
"{",
"minimums",
"[",
"i",
"]",
... | // NewMinWise returns a new MinWise Hashing implementation | [
"NewMinWise",
"returns",
"a",
"new",
"MinWise",
"Hashing",
"implementation"
] | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/minwise.go#L15-L27 |
16,574 | dgryski/go-minhash | minwise.go | NewMinWiseFromSignatures | func NewMinWiseFromSignatures(h1, h2 Hash64, signatures []uint64) *MinWise {
minimums := make([]uint64, len(signatures))
copy(minimums, signatures)
return &MinWise{
h1: h1,
h2: h2,
minimums: signatures,
}
} | go | func NewMinWiseFromSignatures(h1, h2 Hash64, signatures []uint64) *MinWise {
minimums := make([]uint64, len(signatures))
copy(minimums, signatures)
return &MinWise{
h1: h1,
h2: h2,
minimums: signatures,
}
} | [
"func",
"NewMinWiseFromSignatures",
"(",
"h1",
",",
"h2",
"Hash64",
",",
"signatures",
"[",
"]",
"uint64",
")",
"*",
"MinWise",
"{",
"minimums",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"signatures",
")",
")",
"\n",
"copy",
"(",
"minimum... | // NewMinWiseFromSignatures returns a new MinWise Hashing implementation
// using a user-provided set of signatures | [
"NewMinWiseFromSignatures",
"returns",
"a",
"new",
"MinWise",
"Hashing",
"implementation",
"using",
"a",
"user",
"-",
"provided",
"set",
"of",
"signatures"
] | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/minwise.go#L31-L40 |
16,575 | dgryski/go-minhash | minwise.go | SignatureBbit | func (m *MinWise) SignatureBbit(b uint) []uint64 {
var sig []uint64 // full signature
var w uint64 // current word
bits := uint(64) // bits free in current word
mask := uint64(1<<b) - 1
for _, v := range m.minimums {
if bits >= b {
w <<= b
w |= v & mask
bits -= b
} else {
sig = append(sig, w)
w = 0
bits = 64
}
}
if bits != 64 {
sig = append(sig, w)
}
return sig
} | go | func (m *MinWise) SignatureBbit(b uint) []uint64 {
var sig []uint64 // full signature
var w uint64 // current word
bits := uint(64) // bits free in current word
mask := uint64(1<<b) - 1
for _, v := range m.minimums {
if bits >= b {
w <<= b
w |= v & mask
bits -= b
} else {
sig = append(sig, w)
w = 0
bits = 64
}
}
if bits != 64 {
sig = append(sig, w)
}
return sig
} | [
"func",
"(",
"m",
"*",
"MinWise",
")",
"SignatureBbit",
"(",
"b",
"uint",
")",
"[",
"]",
"uint64",
"{",
"var",
"sig",
"[",
"]",
"uint64",
"// full signature",
"\n",
"var",
"w",
"uint64",
"// current word",
"\n",
"bits",
":=",
"uint",
"(",
"64",
")",
... | // SignatureBbit returns a b-bit reduction of the signature. This will result in unused bits at the high-end of the words if b does not divide 64 evenly. | [
"SignatureBbit",
"returns",
"a",
"b",
"-",
"bit",
"reduction",
"of",
"the",
"signature",
".",
"This",
"will",
"result",
"in",
"unused",
"bits",
"at",
"the",
"high",
"-",
"end",
"of",
"the",
"words",
"if",
"b",
"does",
"not",
"divide",
"64",
"evenly",
"... | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/minwise.go#L105-L130 |
16,576 | dgryski/go-minhash | minwise.go | SimilarityBbit | func SimilarityBbit(sig1, sig2 []uint64, b uint) float64 {
if len(sig1) != len(sig2) {
panic("signature size mismatch")
}
intersect := 0
count := 0
mask := uint64(1<<b) - 1
for i := range sig1 {
w1 := sig1[i]
w2 := sig2[i]
bits := uint(64)
for bits >= b {
v1 := (w1 & mask)
v2 := (w2 & mask)
count++
if v1 == v2 {
intersect++
}
bits -= b
w1 >>= b
w2 >>= b
}
}
return float64(intersect) / float64(count)
} | go | func SimilarityBbit(sig1, sig2 []uint64, b uint) float64 {
if len(sig1) != len(sig2) {
panic("signature size mismatch")
}
intersect := 0
count := 0
mask := uint64(1<<b) - 1
for i := range sig1 {
w1 := sig1[i]
w2 := sig2[i]
bits := uint(64)
for bits >= b {
v1 := (w1 & mask)
v2 := (w2 & mask)
count++
if v1 == v2 {
intersect++
}
bits -= b
w1 >>= b
w2 >>= b
}
}
return float64(intersect) / float64(count)
} | [
"func",
"SimilarityBbit",
"(",
"sig1",
",",
"sig2",
"[",
"]",
"uint64",
",",
"b",
"uint",
")",
"float64",
"{",
"if",
"len",
"(",
"sig1",
")",
"!=",
"len",
"(",
"sig2",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"intersect",
":=",... | // SimilarityBbit computes an estimate for the similarity between two b-bit signatures | [
"SimilarityBbit",
"computes",
"an",
"estimate",
"for",
"the",
"similarity",
"between",
"two",
"b",
"-",
"bit",
"signatures"
] | ad340ca0307647c228c227cb844358a2c94d7f80 | https://github.com/dgryski/go-minhash/blob/ad340ca0307647c228c227cb844358a2c94d7f80/minwise.go#L133-L166 |
16,577 | pilosa/pdk | mapper.go | NewCollapsingMapper | func NewCollapsingMapper() *CollapsingMapper {
return &CollapsingMapper{
Translator: NewMapTranslator(),
ColTranslator: NewNexterFieldTranslator(),
Framer: &DashField{},
Nexter: NewNexter(),
}
} | go | func NewCollapsingMapper() *CollapsingMapper {
return &CollapsingMapper{
Translator: NewMapTranslator(),
ColTranslator: NewNexterFieldTranslator(),
Framer: &DashField{},
Nexter: NewNexter(),
}
} | [
"func",
"NewCollapsingMapper",
"(",
")",
"*",
"CollapsingMapper",
"{",
"return",
"&",
"CollapsingMapper",
"{",
"Translator",
":",
"NewMapTranslator",
"(",
")",
",",
"ColTranslator",
":",
"NewNexterFieldTranslator",
"(",
")",
",",
"Framer",
":",
"&",
"DashField",
... | // NewCollapsingMapper returns a CollapsingMapper with basic implementations of
// its components. In order to track mapping of Pilosa columns to records, you
// must replace the ColTranslator with something other than a
// NexterFieldTranslator which just allocates ids and does not store a mapping. | [
"NewCollapsingMapper",
"returns",
"a",
"CollapsingMapper",
"with",
"basic",
"implementations",
"of",
"its",
"components",
".",
"In",
"order",
"to",
"track",
"mapping",
"of",
"Pilosa",
"columns",
"to",
"records",
"you",
"must",
"replace",
"the",
"ColTranslator",
"w... | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/mapper.go#L56-L63 |
16,578 | pilosa/pdk | mapper.go | Map | func (m *CollapsingMapper) Map(e *Entity) (PilosaRecord, error) {
pr := PilosaRecord{}
if m.ColTranslator != nil {
col, err := m.ColTranslator.GetID(string(e.Subject))
if err != nil {
return pr, errors.Wrap(err, "getting column id from subject")
}
pr.Col = col
} else if m.Nexter != nil {
pr.Col = m.Nexter.Next()
} else {
pr.Col = string(e.Subject)
}
return pr, m.mapObj(e, &pr, []string{})
} | go | func (m *CollapsingMapper) Map(e *Entity) (PilosaRecord, error) {
pr := PilosaRecord{}
if m.ColTranslator != nil {
col, err := m.ColTranslator.GetID(string(e.Subject))
if err != nil {
return pr, errors.Wrap(err, "getting column id from subject")
}
pr.Col = col
} else if m.Nexter != nil {
pr.Col = m.Nexter.Next()
} else {
pr.Col = string(e.Subject)
}
return pr, m.mapObj(e, &pr, []string{})
} | [
"func",
"(",
"m",
"*",
"CollapsingMapper",
")",
"Map",
"(",
"e",
"*",
"Entity",
")",
"(",
"PilosaRecord",
",",
"error",
")",
"{",
"pr",
":=",
"PilosaRecord",
"{",
"}",
"\n",
"if",
"m",
".",
"ColTranslator",
"!=",
"nil",
"{",
"col",
",",
"err",
":="... | // Map implements the RecordMapper interface. | [
"Map",
"implements",
"the",
"RecordMapper",
"interface",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/mapper.go#L66-L80 |
16,579 | pilosa/pdk | mapper.go | AddVal | func (pr *PilosaRecord) AddVal(field string, value int64) {
pr.Vals = append(pr.Vals, Val{Field: field, Value: value})
} | go | func (pr *PilosaRecord) AddVal(field string, value int64) {
pr.Vals = append(pr.Vals, Val{Field: field, Value: value})
} | [
"func",
"(",
"pr",
"*",
"PilosaRecord",
")",
"AddVal",
"(",
"field",
"string",
",",
"value",
"int64",
")",
"{",
"pr",
".",
"Vals",
"=",
"append",
"(",
"pr",
".",
"Vals",
",",
"Val",
"{",
"Field",
":",
"field",
",",
"Value",
":",
"value",
"}",
")"... | // AddVal adds a new value to be range encoded into the given field to the
// PilosaRecord. | [
"AddVal",
"adds",
"a",
"new",
"value",
"to",
"be",
"range",
"encoded",
"into",
"the",
"given",
"field",
"to",
"the",
"PilosaRecord",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/mapper.go#L212-L214 |
16,580 | pilosa/pdk | mapper.go | AddRow | func (pr *PilosaRecord) AddRow(field string, idOrKey uint64OrString) {
pr.Rows = append(pr.Rows, Row{Field: field, ID: idOrKey})
} | go | func (pr *PilosaRecord) AddRow(field string, idOrKey uint64OrString) {
pr.Rows = append(pr.Rows, Row{Field: field, ID: idOrKey})
} | [
"func",
"(",
"pr",
"*",
"PilosaRecord",
")",
"AddRow",
"(",
"field",
"string",
",",
"idOrKey",
"uint64OrString",
")",
"{",
"pr",
".",
"Rows",
"=",
"append",
"(",
"pr",
".",
"Rows",
",",
"Row",
"{",
"Field",
":",
"field",
",",
"ID",
":",
"idOrKey",
... | // AddRow adds a new column to be set to the PilosaRecord. | [
"AddRow",
"adds",
"a",
"new",
"column",
"to",
"be",
"set",
"to",
"the",
"PilosaRecord",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/mapper.go#L217-L219 |
16,581 | pilosa/pdk | mapper.go | AddRowTime | func (pr *PilosaRecord) AddRowTime(field string, id uint64, ts time.Time) {
pr.Rows = append(pr.Rows, Row{Field: field, ID: id, Time: ts})
} | go | func (pr *PilosaRecord) AddRowTime(field string, id uint64, ts time.Time) {
pr.Rows = append(pr.Rows, Row{Field: field, ID: id, Time: ts})
} | [
"func",
"(",
"pr",
"*",
"PilosaRecord",
")",
"AddRowTime",
"(",
"field",
"string",
",",
"id",
"uint64",
",",
"ts",
"time",
".",
"Time",
")",
"{",
"pr",
".",
"Rows",
"=",
"append",
"(",
"pr",
".",
"Rows",
",",
"Row",
"{",
"Field",
":",
"field",
",... | // AddRowTime adds a new column to be set with a timestamp to the PilosaRecord. | [
"AddRowTime",
"adds",
"a",
"new",
"column",
"to",
"be",
"set",
"with",
"a",
"timestamp",
"to",
"the",
"PilosaRecord",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/mapper.go#L222-L224 |
16,582 | pilosa/pdk | cmd/taxi.go | NewTaxiCommand | func NewTaxiCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
TaxiMain = taxi.NewMain()
taxiCommand := &cobra.Command{
Use: "taxi",
Short: "Import taxi data to Pilosa.",
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()
err := TaxiMain.Run()
if err != nil {
return err
}
dt := time.Since(start)
log.Println("Done: ", dt)
fmt.Printf("{\"duration\": %f}\n", dt.Seconds())
return nil
},
}
flags := taxiCommand.Flags()
flags.IntVarP(&TaxiMain.Concurrency, "concurrency", "c", 8, "Number of goroutines fetching and parsing")
flags.IntVarP(&TaxiMain.FetchConcurrency, "fetch-concurrency", "e", 8, "Number of goroutines fetching and parsing")
flags.IntVarP(&TaxiMain.BufferSize, "buffer-size", "b", 1000000, "Size of buffer for importers - heavily affects memory usage")
flags.BoolVarP(&TaxiMain.UseReadAll, "use-read-all", "", false, "Setting to true uses much more memory, but ensures that an entire file can be read before beginning to parse it.")
flags.StringVarP(&TaxiMain.PilosaHost, "pilosa", "p", "localhost:10101", "Pilosa host")
flags.StringVarP(&TaxiMain.Index, "index", "i", TaxiMain.Index, "Pilosa db to write to")
flags.StringVarP(&TaxiMain.URLFile, "url-file", "f", "usecase/taxi/urls-short.txt", "File to get raw data urls from. Urls may be http or local files.")
return taxiCommand
} | go | func NewTaxiCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
TaxiMain = taxi.NewMain()
taxiCommand := &cobra.Command{
Use: "taxi",
Short: "Import taxi data to Pilosa.",
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()
err := TaxiMain.Run()
if err != nil {
return err
}
dt := time.Since(start)
log.Println("Done: ", dt)
fmt.Printf("{\"duration\": %f}\n", dt.Seconds())
return nil
},
}
flags := taxiCommand.Flags()
flags.IntVarP(&TaxiMain.Concurrency, "concurrency", "c", 8, "Number of goroutines fetching and parsing")
flags.IntVarP(&TaxiMain.FetchConcurrency, "fetch-concurrency", "e", 8, "Number of goroutines fetching and parsing")
flags.IntVarP(&TaxiMain.BufferSize, "buffer-size", "b", 1000000, "Size of buffer for importers - heavily affects memory usage")
flags.BoolVarP(&TaxiMain.UseReadAll, "use-read-all", "", false, "Setting to true uses much more memory, but ensures that an entire file can be read before beginning to parse it.")
flags.StringVarP(&TaxiMain.PilosaHost, "pilosa", "p", "localhost:10101", "Pilosa host")
flags.StringVarP(&TaxiMain.Index, "index", "i", TaxiMain.Index, "Pilosa db to write to")
flags.StringVarP(&TaxiMain.URLFile, "url-file", "f", "usecase/taxi/urls-short.txt", "File to get raw data urls from. Urls may be http or local files.")
return taxiCommand
} | [
"func",
"NewTaxiCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"cobra",
".",
"Command",
"{",
"TaxiMain",
"=",
"taxi",
".",
"NewMain",
"(",
")",
"\n",
"taxiCommand",
":=",
"&",
"cobra",
".",
"... | // NewTaxiCommand wraps taxi.Main with cobra.Command for use from a CLI. | [
"NewTaxiCommand",
"wraps",
"taxi",
".",
"Main",
"with",
"cobra",
".",
"Command",
"for",
"use",
"from",
"a",
"CLI",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/cmd/taxi.go#L49-L76 |
16,583 | pilosa/pdk | fake/source.go | NewSource | func NewSource(seed int64, concurrency int, max uint64) *Source {
if max == 0 {
max = math.MaxUint64
}
var n uint64
s := &Source{
events: make(chan *Event, 1000),
closed: make(chan struct{}),
n: &n,
max: max,
}
for i := 0; i < concurrency; i++ {
s.wg.Add(1)
go func(i int) {
defer s.wg.Done()
// seed is multiplied by 10 because NewEventGenerator uses several
// seeds internally (incrementing it by 1) and we'd prefer to avoid
// re-using seeds between different generators.
g := NewEventGenerator(seed * 10 * int64(i))
for {
select {
case s.events <- g.Event():
case <-s.closed:
return
}
}
}(i)
}
return s
} | go | func NewSource(seed int64, concurrency int, max uint64) *Source {
if max == 0 {
max = math.MaxUint64
}
var n uint64
s := &Source{
events: make(chan *Event, 1000),
closed: make(chan struct{}),
n: &n,
max: max,
}
for i := 0; i < concurrency; i++ {
s.wg.Add(1)
go func(i int) {
defer s.wg.Done()
// seed is multiplied by 10 because NewEventGenerator uses several
// seeds internally (incrementing it by 1) and we'd prefer to avoid
// re-using seeds between different generators.
g := NewEventGenerator(seed * 10 * int64(i))
for {
select {
case s.events <- g.Event():
case <-s.closed:
return
}
}
}(i)
}
return s
} | [
"func",
"NewSource",
"(",
"seed",
"int64",
",",
"concurrency",
"int",
",",
"max",
"uint64",
")",
"*",
"Source",
"{",
"if",
"max",
"==",
"0",
"{",
"max",
"=",
"math",
".",
"MaxUint64",
"\n",
"}",
"\n",
"var",
"n",
"uint64",
"\n",
"s",
":=",
"&",
"... | // NewSource creates a new Source with the given random seed. Using the same
// seed should give the same series of events on a given version of Go. | [
"NewSource",
"creates",
"a",
"new",
"Source",
"with",
"the",
"given",
"random",
"seed",
".",
"Using",
"the",
"same",
"seed",
"should",
"give",
"the",
"same",
"series",
"of",
"events",
"on",
"a",
"given",
"version",
"of",
"Go",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/fake/source.go#L21-L50 |
16,584 | pilosa/pdk | fake/source.go | Record | func (s *Source) Record() (interface{}, error) {
next := atomic.AddUint64(s.n, 1)
if next > s.max {
close(s.closed)
s.wg.Wait()
return nil, io.EOF
}
return <-s.events, nil
} | go | func (s *Source) Record() (interface{}, error) {
next := atomic.AddUint64(s.n, 1)
if next > s.max {
close(s.closed)
s.wg.Wait()
return nil, io.EOF
}
return <-s.events, nil
} | [
"func",
"(",
"s",
"*",
"Source",
")",
"Record",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"next",
":=",
"atomic",
".",
"AddUint64",
"(",
"s",
".",
"n",
",",
"1",
")",
"\n",
"if",
"next",
">",
"s",
".",
"max",
"{",
"close",... | // Record implements pdk.Source and returns a randomly generated fake.Event. | [
"Record",
"implements",
"pdk",
".",
"Source",
"and",
"returns",
"a",
"randomly",
"generated",
"fake",
".",
"Event",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/fake/source.go#L53-L61 |
16,585 | pilosa/pdk | cmd/root.go | NewRootCommand | func NewRootCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
setupVersionBuild()
rc := &cobra.Command{
Use: "pdk",
Short: "pdk - Pilosa Dev Kit and Examples",
Long: `A collection of libraries and worked examples
for getting data into and out of Pilosa.
Complete documentation is available at http://pilosa.com/docs/pdk
Version: ` + Version + `
Build Time: ` + BuildTime + "\n",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
v := viper.New()
return setAllConfig(v, cmd.Flags(), "PDK")
},
}
for _, subcomFn := range subcommandFns {
rc.AddCommand(subcomFn(stdin, stdout, stderr))
}
rc.SetOutput(stderr)
return rc
} | go | func NewRootCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
setupVersionBuild()
rc := &cobra.Command{
Use: "pdk",
Short: "pdk - Pilosa Dev Kit and Examples",
Long: `A collection of libraries and worked examples
for getting data into and out of Pilosa.
Complete documentation is available at http://pilosa.com/docs/pdk
Version: ` + Version + `
Build Time: ` + BuildTime + "\n",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
v := viper.New()
return setAllConfig(v, cmd.Flags(), "PDK")
},
}
for _, subcomFn := range subcommandFns {
rc.AddCommand(subcomFn(stdin, stdout, stderr))
}
rc.SetOutput(stderr)
return rc
} | [
"func",
"NewRootCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"cobra",
".",
"Command",
"{",
"setupVersionBuild",
"(",
")",
"\n",
"rc",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\... | // NewRootCommand reads the map of subcommandFns and creates a top level cobra
// command with each of them as subcommands. | [
"NewRootCommand",
"reads",
"the",
"map",
"of",
"subcommandFns",
"and",
"creates",
"a",
"top",
"level",
"cobra",
"command",
"with",
"each",
"of",
"them",
"as",
"subcommands",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/cmd/root.go#L65-L86 |
16,586 | pilosa/pdk | cmd/ssb.go | NewSSBCommand | func NewSSBCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
var err error
SSBMain, err = ssb.NewMain()
ssbCommand := &cobra.Command{
Use: "ssb",
Short: "Run star schema benchmark.",
RunE: func(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
start := time.Now()
err = SSBMain.Run()
if err != nil {
return err
}
log.Println("Done: ", time.Since(start))
select {}
},
}
if err != nil {
return ssbCommand
}
flags := ssbCommand.Flags()
flags.StringVarP(&SSBMain.Dir, "data-dir", "d", "ssb1", "Directory containing ssb data files.")
flags.StringSliceVarP(&SSBMain.Hosts, "pilosa-hosts", "p", []string{"localhost:10101"}, "Pilosa cluster.")
flags.IntVarP(&SSBMain.MapConcurrency, "map-concurrency", "m", 1, "Number of goroutines mapping parsed records.")
flags.IntVarP(&SSBMain.RecordBuf, "record-buffer", "r", 1000000, "Channel buffer size for parsed records.")
return ssbCommand
} | go | func NewSSBCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
var err error
SSBMain, err = ssb.NewMain()
ssbCommand := &cobra.Command{
Use: "ssb",
Short: "Run star schema benchmark.",
RunE: func(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
start := time.Now()
err = SSBMain.Run()
if err != nil {
return err
}
log.Println("Done: ", time.Since(start))
select {}
},
}
if err != nil {
return ssbCommand
}
flags := ssbCommand.Flags()
flags.StringVarP(&SSBMain.Dir, "data-dir", "d", "ssb1", "Directory containing ssb data files.")
flags.StringSliceVarP(&SSBMain.Hosts, "pilosa-hosts", "p", []string{"localhost:10101"}, "Pilosa cluster.")
flags.IntVarP(&SSBMain.MapConcurrency, "map-concurrency", "m", 1, "Number of goroutines mapping parsed records.")
flags.IntVarP(&SSBMain.RecordBuf, "record-buffer", "r", 1000000, "Channel buffer size for parsed records.")
return ssbCommand
} | [
"func",
"NewSSBCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"err",
"error",
"\n",
"SSBMain",
",",
"err",
"=",
"ssb",
".",
"NewMain",
"(",
")",
"\n",
"... | // NewSSBCommand wraps ssb.Main with cobra.Command for use from a CLI. | [
"NewSSBCommand",
"wraps",
"ssb",
".",
"Main",
"with",
"cobra",
".",
"Command",
"for",
"use",
"from",
"a",
"CLI",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/cmd/ssb.go#L48-L77 |
16,587 | pilosa/pdk | cmd/kafkagen.go | NewKafkagenCommand | func NewKafkagenCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
KafkagenMain = kafkagen.NewMain()
command, err := cobrafy.Command(KafkagenMain)
if err != nil {
panic(err)
}
command.Use = "kafkagen"
command.Short = "Put fake data into kafka."
return command
} | go | func NewKafkagenCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
KafkagenMain = kafkagen.NewMain()
command, err := cobrafy.Command(KafkagenMain)
if err != nil {
panic(err)
}
command.Use = "kafkagen"
command.Short = "Put fake data into kafka."
return command
} | [
"func",
"NewKafkagenCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"cobra",
".",
"Command",
"{",
"KafkagenMain",
"=",
"kafkagen",
".",
"NewMain",
"(",
")",
"\n",
"command",
",",
"err",
":=",
"c... | // NewKafkagenCommand returns a new cobra command wrapping KafkagenMain. | [
"NewKafkagenCommand",
"returns",
"a",
"new",
"cobra",
"command",
"wrapping",
"KafkagenMain",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/cmd/kafkagen.go#L48-L57 |
16,588 | pilosa/pdk | http/source.go | WithListener | func WithListener(l net.Listener) JSONSourceOption {
return func(j *JSONSource) {
j.listener = l
j.addr = l.Addr().String()
}
} | go | func WithListener(l net.Listener) JSONSourceOption {
return func(j *JSONSource) {
j.listener = l
j.addr = l.Addr().String()
}
} | [
"func",
"WithListener",
"(",
"l",
"net",
".",
"Listener",
")",
"JSONSourceOption",
"{",
"return",
"func",
"(",
"j",
"*",
"JSONSource",
")",
"{",
"j",
".",
"listener",
"=",
"l",
"\n",
"j",
".",
"addr",
"=",
"l",
".",
"Addr",
"(",
")",
".",
"String",... | // WithListener is an option for JSONSource which causes it to use the given
// listener. It will infer the address from the listener. | [
"WithListener",
"is",
"an",
"option",
"for",
"JSONSource",
"which",
"causes",
"it",
"to",
"use",
"the",
"given",
"listener",
".",
"It",
"will",
"infer",
"the",
"address",
"from",
"the",
"listener",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/http/source.go#L65-L70 |
16,589 | pilosa/pdk | http/source.go | NewJSONSource | func NewJSONSource(opts ...JSONSourceOption) (*JSONSource, error) {
j := &JSONSource{
records: make(chan record, 3),
}
for _, opt := range opts {
opt(j)
}
if j.listener == nil {
var err error
j.listener, err = net.Listen("tcp", j.addr)
if err != nil {
return nil, err
}
}
j.listener = tcpKeepAliveListener{j.listener.(*net.TCPListener)}
j.server = &http.Server{
Addr: j.addr,
Handler: j,
}
go func() {
err := j.server.Serve(j.listener)
if err != nil {
j.records <- record{err: errors.Wrap(err, "starting server")}
close(j.records)
}
}()
return j, nil
} | go | func NewJSONSource(opts ...JSONSourceOption) (*JSONSource, error) {
j := &JSONSource{
records: make(chan record, 3),
}
for _, opt := range opts {
opt(j)
}
if j.listener == nil {
var err error
j.listener, err = net.Listen("tcp", j.addr)
if err != nil {
return nil, err
}
}
j.listener = tcpKeepAliveListener{j.listener.(*net.TCPListener)}
j.server = &http.Server{
Addr: j.addr,
Handler: j,
}
go func() {
err := j.server.Serve(j.listener)
if err != nil {
j.records <- record{err: errors.Wrap(err, "starting server")}
close(j.records)
}
}()
return j, nil
} | [
"func",
"NewJSONSource",
"(",
"opts",
"...",
"JSONSourceOption",
")",
"(",
"*",
"JSONSource",
",",
"error",
")",
"{",
"j",
":=",
"&",
"JSONSource",
"{",
"records",
":",
"make",
"(",
"chan",
"record",
",",
"3",
")",
",",
"}",
"\n",
"for",
"_",
",",
... | // NewJSONSource creates a JSONSource - it takes JSONSourceOptions which modify
// its behavior. | [
"NewJSONSource",
"creates",
"a",
"JSONSource",
"-",
"it",
"takes",
"JSONSourceOptions",
"which",
"modify",
"its",
"behavior",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/http/source.go#L88-L117 |
16,590 | pilosa/pdk | http/source.go | Addr | func (j *JSONSource) Addr() string {
if j.listener != nil {
return j.listener.Addr().String()
}
return j.addr
} | go | func (j *JSONSource) Addr() string {
if j.listener != nil {
return j.listener.Addr().String()
}
return j.addr
} | [
"func",
"(",
"j",
"*",
"JSONSource",
")",
"Addr",
"(",
")",
"string",
"{",
"if",
"j",
".",
"listener",
"!=",
"nil",
"{",
"return",
"j",
".",
"listener",
".",
"Addr",
"(",
")",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"j",
".",
"addr"... | // Addr gets the address that the JSONSource is listening on. | [
"Addr",
"gets",
"the",
"address",
"that",
"the",
"JSONSource",
"is",
"listening",
"on",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/http/source.go#L120-L125 |
16,591 | pilosa/pdk | http/source.go | ServeHTTP | func (j *JSONSource) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
err := errors.Errorf("unsupported method: %v, request: %#v", r.Method, r)
log.Println(err)
http.Error(w, err.Error(), http.StatusMethodNotAllowed)
return
}
jsource := json.NewSource(r.Body)
for {
stuff, err := jsource.Record()
if err == io.EOF {
return
}
if err != nil {
err := errors.Wrap(err, "decoding json")
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
j.records <- record{data: stuff}
}
} | go | func (j *JSONSource) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
err := errors.Errorf("unsupported method: %v, request: %#v", r.Method, r)
log.Println(err)
http.Error(w, err.Error(), http.StatusMethodNotAllowed)
return
}
jsource := json.NewSource(r.Body)
for {
stuff, err := jsource.Record()
if err == io.EOF {
return
}
if err != nil {
err := errors.Wrap(err, "decoding json")
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
j.records <- record{data: stuff}
}
} | [
"func",
"(",
"j",
"*",
"JSONSource",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"Method",
"!=",
"http",
".",
"MethodPost",
"{",
"err",
":=",
"errors",
".",
"Errorf",
"... | // ServeHTTP implements http.Handler for JSONSource | [
"ServeHTTP",
"implements",
"http",
".",
"Handler",
"for",
"JSONSource"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/http/source.go#L143-L164 |
16,592 | pilosa/pdk | framer.go | Field | func (d *DashField) Field(path []string) (string, error) {
np := d.clean(path)
return strings.ToLower(strings.Join(np, "-")), nil
} | go | func (d *DashField) Field(path []string) (string, error) {
np := d.clean(path)
return strings.ToLower(strings.Join(np, "-")), nil
} | [
"func",
"(",
"d",
"*",
"DashField",
")",
"Field",
"(",
"path",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"np",
":=",
"d",
".",
"clean",
"(",
"path",
")",
"\n",
"return",
"strings",
".",
"ToLower",
"(",
"strings",
".",
"Join"... | // Field gets a field from a path by joining the path elements with dashes. | [
"Field",
"gets",
"a",
"field",
"from",
"a",
"path",
"by",
"joining",
"the",
"path",
"elements",
"with",
"dashes",
"."
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/framer.go#L86-L89 |
16,593 | pilosa/pdk | map.go | ID | func (m CustomMapper) ID(fields ...interface{}) (rowIDs []int64, err error) {
return m.Mapper.ID(m.Func(fields...))
} | go | func (m CustomMapper) ID(fields ...interface{}) (rowIDs []int64, err error) {
return m.Mapper.ID(m.Func(fields...))
} | [
"func",
"(",
"m",
"CustomMapper",
")",
"ID",
"(",
"fields",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"return",
"m",
".",
"Mapper",
".",
"ID",
"(",
"m",
".",
"Func",
"(",
"fields",
"...",
... | // ID maps a set of fields using a custom function | [
"ID",
"maps",
"a",
"set",
"of",
"fields",
"using",
"a",
"custom",
"function"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L201-L203 |
16,594 | pilosa/pdk | map.go | ID | func (m TimeOfDayMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
daySeconds := int64(t.Second() + t.Minute()*60 + t.Hour()*3600)
return []int64{int64(float64(daySeconds*m.Res) / 86400)}, nil // TODO eliminate extraneous casts
} | go | func (m TimeOfDayMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
daySeconds := int64(t.Second() + t.Minute()*60 + t.Hour()*3600)
return []int64{int64(float64(daySeconds*m.Res) / 86400)}, nil // TODO eliminate extraneous casts
} | [
"func",
"(",
"m",
"TimeOfDayMapper",
")",
"ID",
"(",
"ti",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"t",
":=",
"ti",
"[",
"0",
"]",
".",
"(",
"time",
".",
"Time",
")",
"\n",
"daySeconds... | // ID maps a timestamp to a time of day bucket | [
"ID",
"maps",
"a",
"timestamp",
"to",
"a",
"time",
"of",
"day",
"bucket"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L206-L210 |
16,595 | pilosa/pdk | map.go | ID | func (m DayOfWeekMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
return []int64{int64(t.Weekday())}, nil
} | go | func (m DayOfWeekMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
return []int64{int64(t.Weekday())}, nil
} | [
"func",
"(",
"m",
"DayOfWeekMapper",
")",
"ID",
"(",
"ti",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"t",
":=",
"ti",
"[",
"0",
"]",
".",
"(",
"time",
".",
"Time",
")",
"\n",
"return",
... | // ID maps a timestamp to a day of week bucket | [
"ID",
"maps",
"a",
"timestamp",
"to",
"a",
"day",
"of",
"week",
"bucket"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L213-L216 |
16,596 | pilosa/pdk | map.go | ID | func (m YearMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
return []int64{int64(t.Year())}, nil
} | go | func (m YearMapper) ID(ti ...interface{}) (rowIDs []int64, err error) {
t := ti[0].(time.Time)
return []int64{int64(t.Year())}, nil
} | [
"func",
"(",
"m",
"YearMapper",
")",
"ID",
"(",
"ti",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"t",
":=",
"ti",
"[",
"0",
"]",
".",
"(",
"time",
".",
"Time",
")",
"\n",
"return",
"[",... | // ID maps a timestamp to a year bucket | [
"ID",
"maps",
"a",
"timestamp",
"to",
"a",
"year",
"bucket"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L231-L234 |
16,597 | pilosa/pdk | map.go | ID | func (m IntMapper) ID(ii ...interface{}) (rowIDs []int64, err error) {
i := ii[0].(int64)
externalID := m.Res
if i < m.Min || i > m.Max {
if m.allowExternal {
return []int64{externalID}, nil
}
return []int64{0}, fmt.Errorf("int %v out of range", i)
}
return []int64{i - m.Min}, nil
} | go | func (m IntMapper) ID(ii ...interface{}) (rowIDs []int64, err error) {
i := ii[0].(int64)
externalID := m.Res
if i < m.Min || i > m.Max {
if m.allowExternal {
return []int64{externalID}, nil
}
return []int64{0}, fmt.Errorf("int %v out of range", i)
}
return []int64{i - m.Min}, nil
} | [
"func",
"(",
"m",
"IntMapper",
")",
"ID",
"(",
"ii",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"i",
":=",
"ii",
"[",
"0",
"]",
".",
"(",
"int64",
")",
"\n",
"externalID",
":=",
"m",
".... | // ID maps an int range to a rowID range | [
"ID",
"maps",
"an",
"int",
"range",
"to",
"a",
"rowID",
"range"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L242-L252 |
16,598 | pilosa/pdk | map.go | ID | func (m SparseIntMapper) ID(ii ...interface{}) (rowIDs []int64, err error) {
i := ii[0].(int64)
if _, ok := m.Map[i]; !ok {
m.Map[i] = int64(len(m.Map))
}
return []int64{m.Map[i]}, nil
} | go | func (m SparseIntMapper) ID(ii ...interface{}) (rowIDs []int64, err error) {
i := ii[0].(int64)
if _, ok := m.Map[i]; !ok {
m.Map[i] = int64(len(m.Map))
}
return []int64{m.Map[i]}, nil
} | [
"func",
"(",
"m",
"SparseIntMapper",
")",
"ID",
"(",
"ii",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"i",
":=",
"ii",
"[",
"0",
"]",
".",
"(",
"int64",
")",
"\n",
"if",
"_",
",",
"ok",... | // ID maps arbitrary ints to a rowID range | [
"ID",
"maps",
"arbitrary",
"ints",
"to",
"a",
"rowID",
"range"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L261-L267 |
16,599 | pilosa/pdk | map.go | ID | func (m LinearFloatMapper) ID(fi ...interface{}) (rowIDs []int64, err error) {
f := fi[0].(float64)
externalID := int64(m.Res)
// bounds check
if f < m.Min || f > m.Max {
if m.allowExternal {
return []int64{externalID}, nil
}
return []int64{0}, fmt.Errorf("float %v out of range", f)
}
// compute bin
rowID := int64(m.Res * (f - m.Min) / (m.Max - m.Min))
return []int64{rowID}, nil
} | go | func (m LinearFloatMapper) ID(fi ...interface{}) (rowIDs []int64, err error) {
f := fi[0].(float64)
externalID := int64(m.Res)
// bounds check
if f < m.Min || f > m.Max {
if m.allowExternal {
return []int64{externalID}, nil
}
return []int64{0}, fmt.Errorf("float %v out of range", f)
}
// compute bin
rowID := int64(m.Res * (f - m.Min) / (m.Max - m.Min))
return []int64{rowID}, nil
} | [
"func",
"(",
"m",
"LinearFloatMapper",
")",
"ID",
"(",
"fi",
"...",
"interface",
"{",
"}",
")",
"(",
"rowIDs",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"f",
":=",
"fi",
"[",
"0",
"]",
".",
"(",
"float64",
")",
"\n",
"externalID",
":=",
... | // ID maps floats to regularly spaced buckets | [
"ID",
"maps",
"floats",
"to",
"regularly",
"spaced",
"buckets"
] | bba49352d71e5c23dc4a2c0d3ea08d8560678e1a | https://github.com/pilosa/pdk/blob/bba49352d71e5c23dc4a2c0d3ea08d8560678e1a/map.go#L270-L285 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.