提交 ab7fbc05 编写于 作者: F Fabian Reinartz

Zero timestamp as base, use binary search list postings

上级 dd72b520
......@@ -201,13 +201,12 @@ func OpenShard(path string, logger log.Logger) (*Shard, error) {
}
// TODO(fabxc): get time from client-defined `now` function.
baset := time.Now().UnixNano() / int64(time.Millisecond)
// baset := time.Now().UnixNano() / int64(time.Millisecond)
baset := time.Unix(0, 0).UnixNano() / int64(time.Millisecond)
if len(pbs) > 0 {
baset = pbs[len(pbs)-1].stats.MaxTime
}
if head == nil {
fmt.Println("creating new head", baset)
head, err = OpenHeadBlock(filepath.Join(path, fmt.Sprintf("%d", baset)), baset)
if err != nil {
return nil, err
......
......@@ -164,6 +164,10 @@ type listPostings struct {
idx int
}
func newListPostings(list []uint32) *listPostings {
return &listPostings{list: list, idx: -1}
}
func (it *listPostings) Value() uint32 {
return it.list[it.idx]
}
......@@ -175,7 +179,7 @@ func (it *listPostings) Next() bool {
func (it *listPostings) Seek(x uint32) bool {
// Do binary search between current position and end.
it.idx = sort.Search(len(it.list)-it.idx, func(i int) bool {
it.idx += sort.Search(len(it.list)-it.idx, func(i int) bool {
return it.list[i+it.idx] >= x
})
return it.idx < len(it.list)
......
......@@ -17,27 +17,6 @@ func (m *mockPostings) Seek(v uint32) bool { return m.seek(v) }
func (m *mockPostings) Value() uint32 { return m.value() }
func (m *mockPostings) Err() error { return m.err() }
func newListPostings(list []uint32) *mockPostings {
i := -1
return &mockPostings{
next: func() bool {
i++
return i < len(list)
},
seek: func(v uint32) bool {
for ; i < len(list); i++ {
if list[i] >= v {
return true
}
}
return false
},
value: func() uint32 {
return list[i]
},
err: func() error { return nil },
}
}
func TestIntersectIterator(t *testing.T) {
var cases = []struct {
a, b []uint32
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册