本文整理汇总了Golang中github.com/timtadh/fs2/fmap.BlockFile类的典型用法代码示例。如果您正苦于以下问题:Golang BlockFile类的具体用法?Golang BlockFile怎么用?Golang BlockFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlockFile类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetUserStore
func GetUserStore(dir string) (*UserFileStore, error) {
var bf *fmap.BlockFile
var users *bptree.BpTree
path := filepath.Join(dir, "users.bptree")
err := createOrOpen(path,
func(path string) (err error) {
bf, err = fmap.CreateBlockFile(path)
if err != nil {
return err
}
users, err = bptree.New(bf, -1, -1)
return err
},
func(path string) (err error) {
bf, err = fmap.OpenBlockFile(path)
if err != nil {
return err
}
users, err = bptree.Open(bf)
return err
},
)
if err != nil {
return nil, err
}
s := &UserFileStore{
path: path,
bf: bf,
users: users,
}
return s, bf.Sync()
}
开发者ID:smcabrera,项目名称:cc-survey,代码行数:32,代码来源:user_store.go
示例2: NewAt
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
}
开发者ID:postfix,项目名称:fs2,代码行数:34,代码来源:list.go
示例3: OpenVarchar
// Open a varchar structure in the given blockfile with the given offset
// as the control block. This function will confirm that the control
// block is indeed a properly formated control block.
func OpenVarchar(bf *fmap.BlockFile, a uint64) (v *Varchar, err error) {
v = &Varchar{bf: bf, a: a, blkSize: bf.BlockSize()}
var ptOff uint64
var szOff uint64
err = v.bf.Do(v.a, 1, func(bytes []byte) error {
ctrl := asCtrl(bytes)
if ctrl.flags&consts.VARCHAR_CTRL == 0 {
return errors.Errorf("Expected a Varchar control block")
}
ptOff = ctrl.posTree
szOff = ctrl.sizeTree
return nil
})
if err != nil {
return nil, err
}
v.posTree, err = OpenAt(bf, ptOff)
if err != nil {
return nil, err
}
v.sizeTree, err = OpenAt(bf, szOff)
if err != nil {
return nil, err
}
return v, nil
}
开发者ID:postfix,项目名称:fs2,代码行数:29,代码来源:varchar.go
示例4: Open
func Open(bf *fmap.BlockFile) (*List, error) {
data, err := bf.ControlData()
if err != nil {
return nil, err
}
ctrl_a := *slice.AsUint64(&data)
return OpenAt(bf, ctrl_a)
}
开发者ID:postfix,项目名称:fs2,代码行数:8,代码来源:list.go
示例5: New
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)
}
开发者ID:postfix,项目名称:fs2,代码行数:14,代码来源:list.go
示例6: NewVarchar
// 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
}
开发者ID:postfix,项目名称:fs2,代码行数:39,代码来源:varchar.go
示例7: newLeafIn
func (t *T) newLeafIn(bf *fmap.BlockFile, a uint64) {
t.assert_nil(bf.Do(a, 1, func(bytes []byte) error {
_, err := newLeaf(0, bytes, 8, 8)
return err
}))
}
开发者ID:postfix,项目名称:fs2,代码行数:6,代码来源:linked_list_test.go
示例8: assert_alc
func (t *T) assert_alc(bf *fmap.BlockFile) uint64 {
a, err := bf.Allocate()
t.assert_nil(err)
return a
}
开发者ID:postfix,项目名称:fs2,代码行数:5,代码来源:linked_list_test.go
注:本文中的github.com/timtadh/fs2/fmap.BlockFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论