Example #1
0
// Read implements persistedIndex.
func (x *defQueryTreeIndex) Read(r io.Reader) error {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}
	var mt mafsaUnitTable
	err = binary.Unmarshal(b, &mt)
	x.mt = &mt
	if err == nil && len(x.mt.B) > 0 {
		x.mt.t, err = new(mafsa.Decoder).Decode(x.mt.B)
	}
	x.ready = (err == nil)
	return err
}
Example #2
0
func TestUnitOffsets_BinaryEncoding(t *testing.T) {
	uofs := unitOffsets{Unit: 123, byteOffsets: []int64{1, 100, 1000, 200, 2}}
	b, err := binary.Marshal(&uofs)
	if err != nil {
		t.Fatal(err)
	}

	var uofs2 unitOffsets
	if err := binary.Unmarshal(b, &uofs2); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(uofs2, uofs) {
		t.Errorf("got %v, want %v", uofs2, uofs)
	}
}
Example #3
0
// getByFile returns a list of source units that contain the file
// specified by the path. The path can also be a directory, in which
// case all source units that contain files underneath that directory
// are returned.
func (x *unitFilesIndex) getByPath(path string) ([]unit.ID2, bool, error) {
	vlog.Printf("unitFilesIndex.getByPath(%s)", path)
	c_unitFilesIndex_getByPath++

	if x.phtable == nil {
		panic("phtable not built/read")
	}
	v := x.phtable.Get([]byte(path))
	if v == nil {
		return nil, false, nil
	}

	var us []unit.ID2
	if err := binary.Unmarshal(v, &us); err != nil {
		return nil, true, err
	}
	return us, true, nil
}
Example #4
0
// getByFile returns a list of source units that contain the file
// specified by the path. The path can also be a directory, in which
// case all source units that contain files underneath that directory
// are returned.
func (x *defFilesIndex) getByPath(path string) (byteOffsets, bool, error) {
	vlog.Printf("defFilesIndex.getByPath(%s)", path)
	c_defFilesIndex_getByPath++

	if x.phtable == nil {
		panic("phtable not built/read")
	}
	v := x.phtable.Get([]byte(path))
	if v == nil {
		return nil, false, nil
	}

	var ofs byteOffsets
	if err := binary.Unmarshal(v, &ofs); err != nil {
		return nil, true, err
	}
	return ofs, true, nil
}
Example #5
0
func (x *defRefsIndex) getByDef(def graph.RefDefKey) (byteOffsets, bool, error) {
	c_defRefsIndex_getByDef++
	if x.phtable == nil {
		panic("phtable not built/read")
	}

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

	v := x.phtable.Get(k)
	if v == nil {
		return nil, false, nil
	}

	var ofs byteOffsets
	if err := binary.Unmarshal(v, &ofs); err != nil {
		return nil, true, err
	}
	return ofs, true, nil
}