Пример #1
0
// Build creates the defRefsIndex.
func (x *defRefsIndex) Build(refs []*graph.Ref, fbr fileByteRanges, ofs byteOffsets) error {
	vlog.Printf("defRefsIndex: building inverted def->ref index (%d refs)...", len(refs))
	defToRefOfs := map[graph.RefDefKey]byteOffsets{}
	for i, ref := range refs {
		defToRefOfs[ref.RefDefKey()] = append(defToRefOfs[ref.RefDefKey()], ofs[i])
	}

	vlog.Printf("defRefsIndex: adding %d index phtable keys...", len(defToRefOfs))
	b := phtable.Builder(len(fbr))
	for def, refOfs := range defToRefOfs {
		v, err := binary.Marshal(refOfs)
		if err != nil {
			return err
		}

		k, err := proto.Marshal(&def)
		if err != nil {
			return err
		}

		b.Add([]byte(k), v)
	}
	vlog.Printf("defRefsIndex: building index phtable...")
	h, err := b.Build()
	if err != nil {
		return err
	}
	h.StoreKeys = true // so defRefUnitsIndex can enumerate defs pointed to by this unit's refs
	x.phtable = h
	x.ready = true
	vlog.Printf("defRefsIndex: done building index.")
	return nil
}
Пример #2
0
// Build implements unitIndexBuilder.
func (x *unitFilesIndex) Build(units []*unit.SourceUnit) error {
	vlog.Printf("unitFilesIndex: building index...")
	f2u := make(filesToUnits, len(units)*10)
	for _, u := range units {
		for _, f := range u.Files {
			f2u.add(f, u.ID2())
		}
	}
	b := phtable.Builder(len(f2u))
	for file, fileUnits := range f2u {
		ub, err := binary.Marshal(fileUnits)
		if err != nil {
			return err
		}
		b.Add([]byte(file), ub)
	}
	h, err := b.Build()
	if err != nil {
		return err
	}
	x.phtable = h
	x.ready = true
	vlog.Printf("unitFilesIndex: done building index.")
	return nil
}
Пример #3
0
// Build implements defIndexBuilder.
func (x *defFilesIndex) Build(defs []*graph.Def, ofs byteOffsets) error {
	vlog.Printf("defFilesIndex: building index...")
	f2ofs := make(filesToDefOfs, len(defs)/50)
	for i, def := range defs {
		if len(f2ofs[def.File]) < x.perFile && DefFilters(x.filters).SelectDef(def) {
			f2ofs.add(def.File, ofs[i], x.perFile)
		}
	}
	b := phtable.Builder(len(f2ofs))
	for file, defOfs := range f2ofs {
		ob, err := binary.Marshal(defOfs)
		if err != nil {
			return err
		}
		b.Add([]byte(file), ob)
	}
	h, err := b.Build()
	if err != nil {
		return err
	}
	x.phtable = h
	x.ready = true
	vlog.Printf("defFilesIndex: done building index.")
	return nil
}