_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q21900 | NewMockMath | train | func NewMockMath(ctrl *gomock.Controller) *MockMath {
mock := &MockMath{ctrl: ctrl}
mock.recorder = &MockMathMockRecorder{mock}
return mock
} | go | {
"resource": ""
} |
q21901 | Sum | train | func (m *MockMath) Sum(arg0, arg1 int) int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Sum", arg0, arg1)
ret0, _ := ret[0].(int)
return ret0
} | go | {
"resource": ""
} |
q21902 | Sum | train | func (mr *MockMathMockRecorder) Sum(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1)
} | go | {
"resource": ""
} |
q21903 | run | train | func run(program string) (*model.Package, error) {
f, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}
filename := f.Name()
defer os.Remove(filename)
if err := f.Close(); err != nil {
return nil, err
}
// Run the program.
cmd := exec.Command(program, "-output", filename)
cmd.Stdout = os.... | go | {
"resource": ""
} |
q21904 | runInDir | train | func runInDir(program []byte, dir string) (*model.Package, error) {
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_")
if err != nil {
return nil, err
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
log.Printf("failed to ... | go | {
"resource": ""
} |
q21905 | Remember | train | func Remember(index Index, keys []string, values []interface{}) {
for i, k := range keys {
index.Put(k, values[i])
}
err := index.NillableRet()
if err != nil {
log.Fatalf("Woah! %v", err)
}
if len(keys) > 0 && keys[0] == "a" {
index.Ellip("%d", 0, 1, 1, 2, 3)
index.Ellip("%d", 1, 3, 6, 10, 15)
index.Ell... | go | {
"resource": ""
} |
q21906 | MinTimes | train | func (c *Call) MinTimes(n int) *Call {
c.minCalls = n
if c.maxCalls == 1 {
c.maxCalls = 1e8
}
return c
} | go | {
"resource": ""
} |
q21907 | MaxTimes | train | func (c *Call) MaxTimes(n int) *Call {
c.maxCalls = n
if c.minCalls == 1 {
c.minCalls = 0
}
return c
} | go | {
"resource": ""
} |
q21908 | Return | train | func (c *Call) Return(rets ...interface{}) *Call {
c.t.Helper()
mt := c.methodType
if len(rets) != mt.NumOut() {
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
}
for i, ret := range rets {
if got, want := reflect.Typ... | go | {
"resource": ""
} |
q21909 | Times | train | func (c *Call) Times(n int) *Call {
c.minCalls, c.maxCalls = n, n
return c
} | go | {
"resource": ""
} |
q21910 | SetArg | train | func (c *Call) SetArg(n int, value interface{}) *Call {
c.t.Helper()
mt := c.methodType
// TODO: This will break on variadic methods.
// We will need to check those at invocation time.
if n < 0 || n >= mt.NumIn() {
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
n, mt.NumIn(), c.origin)
... | go | {
"resource": ""
} |
q21911 | isPreReq | train | func (c *Call) isPreReq(other *Call) bool {
for _, preReq := range c.preReqs {
if other == preReq || preReq.isPreReq(other) {
return true
}
}
return false
} | go | {
"resource": ""
} |
q21912 | After | train | func (c *Call) After(preReq *Call) *Call {
c.t.Helper()
if c == preReq {
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
}
if preReq.isPreReq(c) {
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
}
c.preReqs = append(c.preReqs, preReq)
return c
} | go | {
"resource": ""
} |
q21913 | dropPrereqs | train | func (c *Call) dropPrereqs() (preReqs []*Call) {
preReqs = c.preReqs
c.preReqs = nil
return
} | go | {
"resource": ""
} |
q21914 | InOrder | train | func InOrder(calls ...*Call) {
for i := 1; i < len(calls); i++ {
calls[i].After(calls[i-1])
}
} | go | {
"resource": ""
} |
q21915 | sanitize | train | func sanitize(s string) string {
t := ""
for _, r := range s {
if t == "" {
if unicode.IsLetter(r) || r == '_' {
t += string(r)
continue
}
} else {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
t += string(r)
continue
}
}
t += "_"
}
if t == "_" {
t = "x"
}
return... | go | {
"resource": ""
} |
q21916 | mockName | train | func (g *generator) mockName(typeName string) string {
if mockName, ok := g.mockNames[typeName]; ok {
return mockName
}
return "Mock" + typeName
} | go | {
"resource": ""
} |
q21917 | GenerateMockMethod | train | func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride string) error {
argNames := g.getArgNames(m)
argTypes := g.getArgTypes(m, pkgOverride)
argString := makeArgString(argNames, argTypes)
rets := make([]string, len(m.Out))
for i, p := range m.Out {
rets[i] = p.Type.String(g.packag... | go | {
"resource": ""
} |
q21918 | Output | train | func (g *generator) Output() []byte {
src, err := format.Source(g.buf.Bytes())
if err != nil {
log.Fatalf("Failed to format generated source code: %s\n%s", err, g.buf.String())
}
return src
} | go | {
"resource": ""
} |
q21919 | Add | train | func (cs callSet) Add(call *Call) {
key := callSetKey{call.receiver, call.method}
m := cs.expected
if call.exhausted() {
m = cs.exhausted
}
m[key] = append(m[key], call)
} | go | {
"resource": ""
} |
q21920 | Remove | train | func (cs callSet) Remove(call *Call) {
key := callSetKey{call.receiver, call.method}
calls := cs.expected[key]
for i, c := range calls {
if c == call {
// maintain order for remaining calls
cs.expected[key] = append(calls[:i], calls[i+1:]...)
cs.exhausted[key] = append(cs.exhausted[key], call)
break
... | go | {
"resource": ""
} |
q21921 | FindMatch | train | func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {
key := callSetKey{receiver, method}
// Search through the expected calls.
expected := cs.expected[key]
var callsErrors bytes.Buffer
for _, call := range expected {
err := call.matches(args)
if err != nil {
... | go | {
"resource": ""
} |
q21922 | Failures | train | func (cs callSet) Failures() []*Call {
failures := make([]*Call, 0, len(cs.expected))
for _, calls := range cs.expected {
for _, call := range calls {
if !call.satisfied() {
failures = append(failures, call)
}
}
}
return failures
} | go | {
"resource": ""
} |
q21923 | NewMockIndex | train | func NewMockIndex(ctrl *gomock.Controller) *MockIndex {
mock := &MockIndex{ctrl: ctrl}
mock.recorder = &MockIndexMockRecorder{mock}
return mock
} | go | {
"resource": ""
} |
q21924 | Anon | train | func (m *MockIndex) Anon(arg0 string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Anon", arg0)
} | go | {
"resource": ""
} |
q21925 | Anon | train | func (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Anon", reflect.TypeOf((*MockIndex)(nil).Anon), arg0)
} | go | {
"resource": ""
} |
q21926 | Chan | train | func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Chan", arg0, arg1)
} | go | {
"resource": ""
} |
q21927 | ConcreteRet | train | func (m *MockIndex) ConcreteRet() chan<- bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ConcreteRet")
ret0, _ := ret[0].(chan<- bool)
return ret0
} | go | {
"resource": ""
} |
q21928 | Ellip | train | func (mr *MockIndexMockRecorder) Ellip(arg0 interface{}, arg1 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ellip", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...)
} | go | {
"resource": ""
} |
q21929 | EllipOnly | train | func (m *MockIndex) EllipOnly(arg0 ...string) {
m.ctrl.T.Helper()
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
m.ctrl.Call(m, "EllipOnly", varargs...)
} | go | {
"resource": ""
} |
q21930 | ForeignFour | train | func (m *MockIndex) ForeignFour(arg0 imp4.Imp4) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignFour", arg0)
} | go | {
"resource": ""
} |
q21931 | ForeignOne | train | func (m *MockIndex) ForeignOne(arg0 imp1.Imp1) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignOne", arg0)
} | go | {
"resource": ""
} |
q21932 | ForeignThree | train | func (m *MockIndex) ForeignThree(arg0 imp3.Imp3) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignThree", arg0)
} | go | {
"resource": ""
} |
q21933 | ForeignTwo | train | func (m *MockIndex) ForeignTwo(arg0 imp2.Imp2) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignTwo", arg0)
} | go | {
"resource": ""
} |
q21934 | Func | train | func (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Func", arg0)
} | go | {
"resource": ""
} |
q21935 | GetTwo | train | func (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTwo", arg0, arg1)
ret0, _ := ret[0].(interface{})
ret1, _ := ret[1].(interface{})
return ret0, ret1
} | go | {
"resource": ""
} |
q21936 | Map | train | func (m *MockIndex) Map(arg0 map[int]hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Map", arg0)
} | go | {
"resource": ""
} |
q21937 | NillableRet | train | func (m *MockIndex) NillableRet() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NillableRet")
ret0, _ := ret[0].(error)
return ret0
} | go | {
"resource": ""
} |
q21938 | Other | train | func (m *MockIndex) Other() hash.Hash {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Other")
ret0, _ := ret[0].(hash.Hash)
return ret0
} | go | {
"resource": ""
} |
q21939 | Ptr | train | func (m *MockIndex) Ptr(arg0 *int) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Ptr", arg0)
} | go | {
"resource": ""
} |
q21940 | Slice | train | func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slice", arg0, arg1)
ret0, _ := ret[0].([3]int)
return ret0
} | go | {
"resource": ""
} |
q21941 | Struct | train | func (m *MockIndex) Struct(arg0 struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Struct", arg0)
} | go | {
"resource": ""
} |
q21942 | StructChan | train | func (m *MockIndex) StructChan(arg0 chan struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StructChan", arg0)
} | go | {
"resource": ""
} |
q21943 | Summary | train | func (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Summary", arg0, arg1)
} | go | {
"resource": ""
} |
q21944 | Templates | train | func (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Templates", arg0, arg1)
} | go | {
"resource": ""
} |
q21945 | NewMockEmbed | train | func NewMockEmbed(ctrl *gomock.Controller) *MockEmbed {
mock := &MockEmbed{ctrl: ctrl}
mock.recorder = &MockEmbedMockRecorder{mock}
return mock
} | go | {
"resource": ""
} |
q21946 | ForeignEmbeddedMethod | train | func (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ForeignEmbeddedMethod")
ret0, _ := ret[0].(*bufio.Reader)
return ret0
} | go | {
"resource": ""
} |
q21947 | ForeignEmbeddedMethod | train | func (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignEmbeddedMethod", reflect.TypeOf((*MockEmbed)(nil).ForeignEmbeddedMethod))
} | go | {
"resource": ""
} |
q21948 | ImplicitPackage | train | func (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ImplicitPackage", arg0, arg1, arg2, arg3, arg4)
} | go | {
"resource": ""
} |
q21949 | ImplicitPackage | train | func (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4)
} | go | {
"resource": ""
} |
q21950 | RegularMethod | train | func (m *MockEmbed) RegularMethod() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegularMethod")
} | go | {
"resource": ""
} |
q21951 | NewMockEmbedded | train | func NewMockEmbedded(ctrl *gomock.Controller) *MockEmbedded {
mock := &MockEmbedded{ctrl: ctrl}
mock.recorder = &MockEmbeddedMockRecorder{mock}
return mock
} | go | {
"resource": ""
} |
q21952 | EmbeddedMethod | train | func (mr *MockEmbeddedMockRecorder) EmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedMethod", reflect.TypeOf((*MockEmbedded)(nil).EmbeddedMethod))
} | go | {
"resource": ""
} |
q21953 | NewMockMatcher | train | func NewMockMatcher(ctrl *gomock.Controller) *MockMatcher {
mock := &MockMatcher{ctrl: ctrl}
mock.recorder = &MockMatcherMockRecorder{mock}
return mock
} | go | {
"resource": ""
} |
q21954 | Matches | train | func (m *MockMatcher) Matches(arg0 interface{}) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Matches", arg0)
ret0, _ := ret[0].(bool)
return ret0
} | go | {
"resource": ""
} |
q21955 | Matches | train | func (mr *MockMatcherMockRecorder) Matches(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0)
} | go | {
"resource": ""
} |
q21956 | String | train | func (m *MockMatcher) String() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "String")
ret0, _ := ret[0].(string)
return ret0
} | go | {
"resource": ""
} |
q21957 | parseFile | train | func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {
allImports, dotImports := importsOfFile(file)
// Don't stomp imports provided by -imports. Those should take precedence.
for pkg, path := range allImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
}
}
... | go | {
"resource": ""
} |
q21958 | parsePackage | train | func (p *fileParser) parsePackage(path string) error {
var pkgs map[string]*ast.Package
if imp, err := build.Import(path, p.srcDir, build.FindOnly); err != nil {
return err
} else if pkgs, err = parser.ParseDir(p.fileSet, imp.Dir, nil, 0); err != nil {
return err
}
for _, pkg := range pkgs {
file := ast.Merg... | go | {
"resource": ""
} |
q21959 | importsOfFile | train | func importsOfFile(file *ast.File) (normalImports map[string]string, dotImports []string) {
normalImports = make(map[string]string)
dotImports = make([]string, 0)
for _, is := range file.Imports {
var pkgName string
importPath := is.Path.Value[1 : len(is.Path.Value)-1] // remove quotes
if is.Name != nil {
... | go | {
"resource": ""
} |
q21960 | iterInterfaces | train | func iterInterfaces(file *ast.File) <-chan namedInterface {
ch := make(chan namedInterface)
go func() {
for _, decl := range file.Decls {
gd, ok := decl.(*ast.GenDecl)
if !ok || gd.Tok != token.TYPE {
continue
}
for _, spec := range gd.Specs {
ts, ok := spec.(*ast.TypeSpec)
if !ok {
con... | go | {
"resource": ""
} |
q21961 | isVariadic | train | func isVariadic(f *ast.FuncType) bool {
nargs := len(f.Params.List)
if nargs == 0 {
return false
}
_, ok := f.Params.List[nargs-1].Type.(*ast.Ellipsis)
return ok
} | go | {
"resource": ""
} |
q21962 | NewController | train | func NewController(t TestReporter) *Controller {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
return &Controller{
T: h,
expectedCalls: newCallSet(),
}
} | go | {
"resource": ""
} |
q21963 | WithContext | train | func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
ctx, cancel := context.WithCancel(ctx)
return NewController(&cancelReporter{h, cancel}), ctx
} | go | {
"resource": ""
} |
q21964 | RecordCall | train | func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
ctrl.T.Helper()
recv := reflect.ValueOf(receiver)
for i := 0; i < recv.Type().NumMethod(); i++ {
if recv.Type().Method(i).Name == method {
return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).T... | go | {
"resource": ""
} |
q21965 | RecordCallWithMethodType | train | func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
ctrl.T.Helper()
call := newCall(ctrl.T, receiver, method, methodType, args...)
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
ctrl.expectedCalls.Add(call)
return call
} | go | {
"resource": ""
} |
q21966 | Call | train | func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
ctrl.T.Helper()
// Nest this code so we can use defer to make sure the lock is released.
actions := func() []func([]interface{}) []interface{} {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
expec... | go | {
"resource": ""
} |
q21967 | Finish | train | func (ctrl *Controller) Finish() {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
if ctrl.finished {
ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
}
ctrl.finished = true
// If we're currently panicking, probably because this is a deferred call,
// pa... | go | {
"resource": ""
} |
q21968 | Imports | train | func (pkg *Package) Imports() map[string]bool {
im := make(map[string]bool)
for _, intf := range pkg.Interfaces {
intf.addImports(im)
}
return im
} | go | {
"resource": ""
} |
q21969 | funcArgsFromType | train | func funcArgsFromType(t reflect.Type) (in []*Parameter, variadic *Parameter, out []*Parameter, err error) {
nin := t.NumIn()
if t.IsVariadic() {
nin--
}
var p *Parameter
for i := 0; i < nin; i++ {
p, err = parameterFromType(t.In(i))
if err != nil {
return
}
in = append(in, p)
}
if t.IsVariadic() {
... | go | {
"resource": ""
} |
q21970 | ParseMagnetURI | train | func ParseMagnetURI(uri string) (m Magnet, err error) {
u, err := url.Parse(uri)
if err != nil {
err = fmt.Errorf("error parsing uri: %s", err)
return
}
if u.Scheme != "magnet" {
err = fmt.Errorf("unexpected scheme: %q", u.Scheme)
return
}
xt := u.Query().Get("xt")
if !strings.HasPrefix(xt, xtPrefix) {
... | go | {
"resource": ""
} |
q21971 | Load | train | func Load(r io.Reader) (*MetaInfo, error) {
var mi MetaInfo
d := bencode.NewDecoder(r)
err := d.Decode(&mi)
if err != nil {
return nil, err
}
return &mi, nil
} | go | {
"resource": ""
} |
q21972 | LoadFromFile | train | func LoadFromFile(filename string) (*MetaInfo, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return Load(f)
} | go | {
"resource": ""
} |
q21973 | Write | train | func (mi MetaInfo) Write(w io.Writer) error {
return bencode.NewEncoder(w).Encode(mi)
} | go | {
"resource": ""
} |
q21974 | SetDefaults | train | func (mi *MetaInfo) SetDefaults() {
mi.Comment = "yoloham"
mi.CreatedBy = "github.com/anacrolix/torrent"
mi.CreationDate = time.Now().Unix()
// mi.Info.PieceLength = 256 * 1024
} | go | {
"resource": ""
} |
q21975 | Magnet | train | func (mi *MetaInfo) Magnet(displayName string, infoHash Hash) (m Magnet) {
for t := range mi.UpvertedAnnounceList().DistinctValues() {
m.Trackers = append(m.Trackers, t)
}
m.DisplayName = displayName
m.InfoHash = infoHash
return
} | go | {
"resource": ""
} |
q21976 | UpvertedAnnounceList | train | func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList {
if mi.AnnounceList.OverridesAnnounce(mi.Announce) {
return mi.AnnounceList
}
if mi.Announce != "" {
return [][]string{[]string{mi.Announce}}
}
return nil
} | go | {
"resource": ""
} |
q21977 | totalBytesEstimate | train | func totalBytesEstimate(tc *torrent.Client) (ret int64) {
var noInfo, hadInfo int64
for _, t := range tc.Torrents() {
info := t.Info()
if info == nil {
noInfo++
continue
}
ret += info.TotalLength()
hadInfo++
}
if hadInfo != 0 {
// Treat each torrent without info as the average of those with,
// ... | go | {
"resource": ""
} |
q21978 | ipv6 | train | func (cn *connection) ipv6() bool {
ip := cn.remoteAddr.IP
if ip.To4() != nil {
return false
}
return len(ip) == net.IPv6len
} | go | {
"resource": ""
} |
q21979 | hasPreferredNetworkOver | train | func (l *connection) hasPreferredNetworkOver(r *connection) (left, ok bool) {
var ml multiLess
ml.NextBool(l.isPreferredDirection(), r.isPreferredDirection())
ml.NextBool(!l.utp(), !r.utp())
ml.NextBool(l.ipv6(), r.ipv6())
return ml.FinalOk()
} | go | {
"resource": ""
} |
q21980 | bestPeerNumPieces | train | func (cn *connection) bestPeerNumPieces() pieceIndex {
if cn.t.haveInfo() {
return cn.t.numPieces()
}
return cn.peerMinPieces
} | go | {
"resource": ""
} |
q21981 | setNumPieces | train | func (cn *connection) setNumPieces(num pieceIndex) error {
cn.peerPieces.RemoveRange(bitmap.BitIndex(num), bitmap.ToEnd)
cn.peerPiecesChanged()
return nil
} | go | {
"resource": ""
} |
q21982 | Post | train | func (cn *connection) Post(msg pp.Message) {
torrent.Add(fmt.Sprintf("messages posted of type %s", msg.Type.String()), 1)
// We don't need to track bytes here because a connection.w Writer wrapper
// takes care of that (although there's some delay between us recording
// the message, and the connection writer flush... | go | {
"resource": ""
} |
q21983 | nominalMaxRequests | train | func (cn *connection) nominalMaxRequests() (ret int) {
if cn.t.requestStrategy == 3 {
expectingTime := int64(cn.totalExpectingTime())
if expectingTime == 0 {
expectingTime = math.MaxInt64
} else {
expectingTime *= 2
}
return int(clamp(
1,
int64(cn.PeerMaxRequests),
max(
// It makes sense t... | go | {
"resource": ""
} |
q21984 | request | train | func (cn *connection) request(r request, mw messageWriter) bool {
if _, ok := cn.requests[r]; ok {
panic("chunk already requested")
}
if !cn.PeerHasPiece(pieceIndex(r.Index)) {
panic("requesting piece peer doesn't have")
}
if _, ok := cn.t.conns[cn]; !ok {
panic("requesting but not in active conns")
}
if c... | go | {
"resource": ""
} |
q21985 | writer | train | func (cn *connection) writer(keepAliveTimeout time.Duration) {
var (
lastWrite time.Time = time.Now()
keepAliveTimer *time.Timer
)
keepAliveTimer = time.AfterFunc(keepAliveTimeout, func() {
cn.mu().Lock()
defer cn.mu().Unlock()
if time.Since(lastWrite) >= keepAliveTimeout {
cn.tickleWriter()
}
... | go | {
"resource": ""
} |
q21986 | iterBitmapsDistinct | train | func iterBitmapsDistinct(skip *bitmap.Bitmap, bms ...bitmap.Bitmap) iter.Func {
return func(cb iter.Callback) {
for _, bm := range bms {
if !iter.All(func(i interface{}) bool {
skip.Add(i.(int))
return cb(i)
}, bitmap.Sub(bm, *skip).Iter) {
return
}
}
}
} | go | {
"resource": ""
} |
q21987 | shouldRequestWithoutBias | train | func (cn *connection) shouldRequestWithoutBias() bool {
if cn.t.requestStrategy != 2 {
return false
}
if len(cn.t.readers) == 0 {
return false
}
if len(cn.t.conns) == 1 {
return true
}
if cn == cn.t.fastestConn {
return true
}
return false
} | go | {
"resource": ""
} |
q21988 | stopRequestingPiece | train | func (cn *connection) stopRequestingPiece(piece pieceIndex) bool {
return cn.pieceRequestOrder.Remove(bitmap.BitIndex(piece))
} | go | {
"resource": ""
} |
q21989 | updatePiecePriority | train | func (cn *connection) updatePiecePriority(piece pieceIndex) bool {
tpp := cn.t.piecePriority(piece)
if !cn.PeerHasPiece(piece) {
tpp = PiecePriorityNone
}
if tpp == PiecePriorityNone {
return cn.stopRequestingPiece(piece)
}
prio := cn.getPieceInclination()[piece]
switch cn.t.requestStrategy {
case 1:
swit... | go | {
"resource": ""
} |
q21990 | postHandshakeStats | train | func (cn *connection) postHandshakeStats(f func(*ConnStats)) {
t := cn.t
f(&t.stats)
f(&t.cl.stats)
} | go | {
"resource": ""
} |
q21991 | allStats | train | func (cn *connection) allStats(f func(*ConnStats)) {
f(&cn.stats)
if cn.reconciledHandshakeStats {
cn.postHandshakeStats(f)
}
} | go | {
"resource": ""
} |
q21992 | useful | train | func (c *connection) useful() bool {
t := c.t
if c.closed.IsSet() {
return false
}
if !t.haveInfo() {
return c.supportsExtension("ut_metadata")
}
if t.seeding() && c.PeerInterested {
return true
}
if c.peerHasWantedPieces() {
return true
}
return false
} | go | {
"resource": ""
} |
q21993 | setRW | train | func (cn *connection) setRW(rw io.ReadWriter) {
cn.r = rw
cn.w = rw
} | go | {
"resource": ""
} |
q21994 | rw | train | func (cn *connection) rw() io.ReadWriter {
return struct {
io.Reader
io.Writer
}{cn.r, cn.w}
} | go | {
"resource": ""
} |
q21995 | upload | train | func (c *connection) upload(msg func(pp.Message) bool) bool {
// Breaking or completing this loop means we don't want to upload to the
// peer anymore, and we choke them.
another:
for c.uploadAllowed() {
// We want to upload to the peer.
if !c.Unchoke(msg) {
return false
}
for r := range c.PeerRequests {
... | go | {
"resource": ""
} |
q21996 | Lookup | train | func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
if ipl == nil {
return
}
// TODO: Perhaps all addresses should be converted to IPv6, if the future
// of IP is to always be backwards compatible. But this will cost 4x the
// memory for IPv4 addresses?
v4 := ip.To4()
if v4 != nil {
r, ok = ipl.lookup(... | go | {
"resource": ""
} |
q21997 | lookup | train | func lookup(
first func(i int) net.IP,
full func(i int) Range,
n int,
ip net.IP,
) (
r Range, ok bool,
) {
// Find the index of the first range for which the following range exceeds
// it.
i := sort.Search(n, func(i int) bool {
if i+1 >= n {
return true
}
return bytes.Compare(ip, first(i+1)) < 0
})
i... | go | {
"resource": ""
} |
q21998 | lookup | train | func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
return lookup(func(i int) net.IP {
return ipl.ranges[i].First
}, func(i int) Range {
return ipl.ranges[i]
}, len(ipl.ranges), ip)
} | go | {
"resource": ""
} |
q21999 | NewFromReader | train | func NewFromReader(f io.Reader) (ret *IPList, err error) {
var ranges []Range
// There's a lot of similar descriptions, so we maintain a pool and reuse
// them to reduce memory overhead.
uniqStrs := make(map[string]string)
scanner := bufio.NewScanner(f)
lineNum := 1
for scanner.Scan() {
r, ok, lineErr := Parse... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.