コード例 #1
0
ファイル: varchar.go プロジェクト: postfix/fs2
// Create a new varchar structure. This takes a blockfile and an offset
// of an allocated block. The block becomes the control block for the
// varchar file (storing the free list for the allocator). It is
// important for the parent structure to track the location of this
// control block.
func NewVarchar(bf *fmap.BlockFile, a uint64) (v *Varchar, err error) {
	ptOff, err := bf.Allocate()
	if err != nil {
		return nil, err
	}
	posTree, err := NewAt(bf, ptOff, 8, 0)
	if err != nil {
		return nil, err
	}
	szOff, err := bf.Allocate()
	if err != nil {
		return nil, err
	}
	sizeTree, err := NewAt(bf, szOff, 4, 8)
	if err != nil {
		return nil, err
	}
	v = &Varchar{
		bf:       bf,
		posTree:  posTree,
		sizeTree: sizeTree,
		a:        a,
		blkSize:  bf.BlockSize(),
	}
	err = v.bf.Do(v.a, 1, func(bytes []byte) error {
		ctrl := asCtrl(bytes)
		ctrl.Init(ptOff, szOff)
		return nil
	})
	if err != nil {
		return nil, err
	}
	return v, nil
}
コード例 #2
0
ファイル: list.go プロジェクト: postfix/fs2
func NewAt(bf *fmap.BlockFile, ctrl_a uint64) (*List, error) {
	vc_a, err := bf.Allocate()
	if err != nil {
		return nil, err
	}
	it_a, err := bf.Allocate()
	if err != nil {
		return nil, err
	}
	v, err := bptree.NewVarchar(bf, vc_a)
	if err != nil {
		return nil, err
	}
	it, err := bptree.NewAt(bf, it_a, 8, 8)
	if err != nil {
		return nil, err
	}
	l := &List{
		bf:      bf,
		varchar: v,
		idxTree: it,
		a:       ctrl_a,
		count:   0,
	}
	err = l.bf.Do(ctrl_a, 1, func(bytes []byte) error {
		c := l.asCtrl(bytes)
		c.Init(vc_a, it_a)
		return nil
	})
	if err != nil {
		return nil, err
	}
	return l, nil
}
コード例 #3
0
ファイル: list.go プロジェクト: postfix/fs2
func New(bf *fmap.BlockFile) (*List, error) {
	ctrl_a, err := bf.Allocate()
	if err != nil {
		return nil, err
	}
	data := make([]byte, 8)
	moff := slice.AsUint64(&data)
	*moff = ctrl_a
	err = bf.SetControlData(data)
	if err != nil {
		return nil, err
	}
	return NewAt(bf, ctrl_a)
}
コード例 #4
0
ファイル: linked_list_test.go プロジェクト: postfix/fs2
func (t *T) assert_alc(bf *fmap.BlockFile) uint64 {
	a, err := bf.Allocate()
	t.assert_nil(err)
	return a
}