当前位置: 首页>>代码示例>>Golang>>正文


Golang graph.Defs函数代码示例

本文整理汇总了Golang中sourcegraph/com/sourcegraph/srclib/graph.Defs函数的典型用法代码示例。如果您正苦于以下问题:Golang Defs函数的具体用法?Golang Defs怎么用?Golang Defs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Defs函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testRepoStore_Defs_ByCommitIDs

func testRepoStore_Defs_ByCommitIDs(t *testing.T, rs RepoStoreImporter) {
	const numCommits = 3
	for c := 1; c <= numCommits; c++ {
		unit := &unit.SourceUnit{Type: "t", Name: "u"}
		data := graph.Output{Defs: []*graph.Def{{DefKey: graph.DefKey{Path: "p"}}}}
		commitID := fmt.Sprintf("c%d", c)
		if err := rs.Import(commitID, unit, data); err != nil {
			t.Errorf("%s: Import(%s, %v, data): %s", rs, commitID, unit, err)
		}
		if rs, ok := rs.(RepoIndexer); ok {
			if err := rs.Index(commitID); err != nil {
				t.Fatalf("%s: Index: %s", rs, err)
			}
		}
	}

	want := []*graph.Def{
		{DefKey: graph.DefKey{CommitID: "c1", UnitType: "t", Unit: "u", Path: "p"}},
		{DefKey: graph.DefKey{CommitID: "c3", UnitType: "t", Unit: "u", Path: "p"}},
	}

	defs, err := rs.Defs(ByCommitIDs("c1", "c3"))
	if err != nil {
		t.Fatalf("%s: Defs: %s", rs, err)
	}
	sort.Sort(graph.Defs(defs))
	sort.Sort(graph.Defs(want))
	if !reflect.DeepEqual(defs, want) {
		t.Errorf("%s: Defs: got defs %v, want %v", rs, defs, want)
	}
}
开发者ID:abec,项目名称:srclib,代码行数:31,代码来源:repo_store_test.go

示例2: testMultiRepoStore_Defs_ByRepoCommitIDs

func testMultiRepoStore_Defs_ByRepoCommitIDs(t *testing.T, mrs MultiRepoStoreImporter) {
	repos := []string{"r1", "r2", "r3"}
	commitIDs := []string{"c1", "c2"}
	for _, repo := range repos {
		for _, commitID := range commitIDs {
			if err := mrs.Import(repo, commitID, &unit.SourceUnit{Type: "t", Name: "u"}, graph.Output{Defs: []*graph.Def{
				{DefKey: graph.DefKey{Path: "p"}},
			}}); err != nil {
				t.Errorf("%s: Import: %s", mrs, err)
			}
			if mrs, ok := mrs.(MultiRepoIndexer); ok {
				if err := mrs.Index(repo, commitID); err != nil {
					t.Fatalf("%s: Index: %s", mrs, err)
				}
			}
		}
	}

	want := []*graph.Def{
		{DefKey: graph.DefKey{Repo: "r1", CommitID: "c2", UnitType: "t", Unit: "u", Path: "p"}},
		{DefKey: graph.DefKey{Repo: "r3", CommitID: "c1", UnitType: "t", Unit: "u", Path: "p"}},
	}

	defs, err := mrs.Defs(ByRepoCommitIDs(Version{Repo: "r1", CommitID: "c2"}, Version{Repo: "r3", CommitID: "c1"}))
	if err != nil {
		t.Errorf("%s: Defs: %s", mrs, err)
	}
	sort.Sort(graph.Defs(defs))
	sort.Sort(graph.Defs(want))
	if !reflect.DeepEqual(defs, want) {
		t.Errorf("%s: Defs: got defs %v, want %v", mrs, defs, want)
	}
}
开发者ID:ildarisaev,项目名称:srclib,代码行数:33,代码来源:multi_repo_store_test.go

示例3: sortedOutput

func sortedOutput(o *graph.Output) *graph.Output {
	sort.Sort(graph.Defs(o.Defs))
	sort.Sort(graph.Refs(o.Refs))
	sort.Sort(graph.Docs(o.Docs))
	sort.Sort(ann.Anns(o.Anns))
	return o
}
开发者ID:xuy,项目名称:srclib,代码行数:7,代码来源:grapher.go

示例4: defsAtOffsets

// defsAtOffsets reads the defs at the given serialized byte offsets
// from the def data file and returns them in arbitrary order.
func (s *fsUnitStore) defsAtOffsets(ofs byteOffsets, fs []DefFilter) (defs []*graph.Def, err error) {
	vlog.Printf("%s: reading defs at %d offsets with filters %v...", s, len(ofs), fs)
	f, err := openFetcherOrOpen(s.fs, unitDefsFilename)
	if err != nil {
		return nil, err
	}
	defer func() {
		err2 := f.Close()
		if err == nil {
			err = err2
		}
	}()

	ffs := DefFilters(fs)

	p := parFetches(s.fs, fs)
	if p == 0 {
		return nil, nil
	}

	var defsLock sync.Mutex
	par := parallel.NewRun(p)
	for _, ofs_ := range ofs {
		ofs := ofs_
		par.Acquire()
		go func() {
			defer par.Release()

			if _, moreOK := LimitRemaining(fs); !moreOK {
				return
			}

			// Guess how many bytes this def is. The s3vfs (if that's the
			// VFS impl in use) will autofetch beyond that if needed.
			const byteEstimate = 2 * decodeBufSize
			r, err := rangeReader(s.fs, unitDefsFilename, f, ofs, byteEstimate)
			if err != nil {
				par.Error(err)
				return
			}
			dec := Codec.NewDecoder(r)
			var def graph.Def
			if _, err := dec.Decode(&def); err != nil {
				par.Error(err)
				return
			}
			if ffs.SelectDef(&def) {
				defsLock.Lock()
				defs = append(defs, &def)
				defsLock.Unlock()
			}
		}()
	}
	if err := par.Wait(); err != nil {
		return defs, err
	}
	sort.Sort(graph.Defs(defs))
	vlog.Printf("%s: read %v defs at %d offsets with filters %v.", s, len(defs), len(ofs), fs)
	return defs, nil
}
开发者ID:xuy,项目名称:srclib,代码行数:62,代码来源:fs_store.go

示例5: testMultiRepoStore_Defs_ByRepoCommitIDs_ByDefQuery

func testMultiRepoStore_Defs_ByRepoCommitIDs_ByDefQuery(t *testing.T, mrs MultiRepoStoreImporter) {
	repos := []string{"r1", "r2", "r3"}
	commitIDs := []string{"c1", "c2"}
	for _, repo := range repos {
		for _, commitID := range commitIDs {
			data := graph.Output{
				Defs: []*graph.Def{
					{DefKey: graph.DefKey{Path: "p1"}, Name: "abc-" + repo},
					{DefKey: graph.DefKey{Path: "p2"}, Name: "xyz-" + repo},
				},
			}
			if err := mrs.Import(repo, commitID, &unit.SourceUnit{Key: unit.Key{Type: "t", Name: "u"}}, data); err != nil {
				t.Errorf("%s: Import: %s", mrs, err)
			}
			if mrs, ok := mrs.(MultiRepoIndexer); ok {
				if err := mrs.Index(repo, commitID); err != nil {
					t.Fatalf("%s: Index: %s", mrs, err)
				}
			}
			if err := mrs.CreateVersion(repo, commitID); err != nil {
				t.Errorf("%s: CreateVersion: %s", mrs, err)
			}
		}
	}

	c_defQueryTreeIndex_getByQuery.set(0)

	want := []*graph.Def{
		{DefKey: graph.DefKey{Repo: "r1", CommitID: "c2", UnitType: "t", Unit: "u", Path: "p1"}, Name: "abc-r1"},
		{DefKey: graph.DefKey{Repo: "r3", CommitID: "c1", UnitType: "t", Unit: "u", Path: "p1"}, Name: "abc-r3"},
	}

	defs, err := mrs.Defs(ByRepoCommitIDs(Version{Repo: "r1", CommitID: "c2"}, Version{Repo: "r3", CommitID: "c1"}), ByDefQuery("abc"))
	if err != nil {
		t.Errorf("%s: Defs: %s", mrs, err)
	}
	sort.Sort(graph.Defs(defs))
	sort.Sort(graph.Defs(want))
	if !deepEqual(defs, want) {
		t.Errorf("%s: Defs: got defs %v, want %v", mrs, defs, want)
	}
	if isIndexedStore(mrs) {
		if want := 2; c_defQueryTreeIndex_getByQuery.get() != want {
			t.Errorf("%s: Defs: got %d index hits on tree def query index, want %d", mrs, c_defQueryTreeIndex_getByQuery.get(), want)
		}
	}
}
开发者ID:xuy,项目名称:srclib,代码行数:47,代码来源:multi_repo_store_test.go

示例6: testTreeStore_Defs_ByUnits

func testTreeStore_Defs_ByUnits(t *testing.T, ts TreeStoreImporter) {
	units := []*unit.SourceUnit{
		{Key: unit.Key{Type: "t1", Name: "u1"}},
		{Key: unit.Key{Type: "t2", Name: "u2"}},
		{Key: unit.Key{Type: "t3", Name: "u3"}},
	}
	for i, unit := range units {
		data := graph.Output{
			Defs: []*graph.Def{{DefKey: graph.DefKey{Path: fmt.Sprintf("p%d", i+1)}}},
		}
		if err := ts.Import(unit, data); err != nil {
			t.Errorf("%s: Import(%v, data): %s", ts, unit, err)
		}
	}
	if ts, ok := ts.(TreeIndexer); ok {
		if err := ts.Index(); err != nil {
			t.Fatalf("%s: Index: %s", ts, err)
		}
	}

	want := []*graph.Def{
		{DefKey: graph.DefKey{UnitType: "t1", Unit: "u1", Path: "p1"}},
		{DefKey: graph.DefKey{UnitType: "t3", Unit: "u3", Path: "p3"}},
	}

	c_fsTreeStore_unitsOpened.set(0)
	defs, err := ts.Defs(ByUnits(unit.ID2{Type: "t3", Name: "u3"}, unit.ID2{Type: "t1", Name: "u1"}))
	if err != nil {
		t.Errorf("%s: Defs(ByUnits): %s", ts, err)
	}
	sort.Sort(graph.Defs(defs))
	sort.Sort(graph.Defs(want))
	if !deepEqual(defs, want) {
		t.Errorf("%s: Defs(ByUnits): got defs %v, want %v", ts, defs, want)
	}
	if isIndexedStore(ts) {
		if c_fsTreeStore_unitsOpened.get() != 0 {
			t.Errorf("%s: Defs(ByUnits): got %d units opened, want none (should be able to use ByUnits filter to avoid needing to open any units)", ts, c_fsTreeStore_unitsOpened.get())
		}
	}
}
开发者ID:xuy,项目名称:srclib,代码行数:41,代码来源:tree_store_test.go

示例7: DefsSort

func (ds DefsSortByKey) DefsSort(defs []*graph.Def) {
	sort.Sort(graph.Defs(defs))
}
开发者ID:xuy,项目名称:srclib,代码行数:3,代码来源:filter.go


注:本文中的sourcegraph/com/sourcegraph/srclib/graph.Defs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。