Commit 6b40eab4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 87e754cd
...@@ -38,17 +38,17 @@ import ( ...@@ -38,17 +38,17 @@ import (
// //
// where // where
// //
// rev - is ZODB revision, and // rev - is ZODB revision,
// id - is an identifier of what has been changed(*) // id - is an identifier of what has been changed(*), and
// [tail, head] - is covered revision range // (tail, head] - is covered revision range
// //
// It provides operations to // It provides operations to
// //
// - append information to the tail about next revision, // - append information to the tail about next revision,
// - forget information in the tail past specified revision, and // - forget information in the tail past specified revision,
// - query the tail for len, head and tail. // - query the tail for slice with rev ∈ (lo, hi],
// - query the tail for slice with rev ∈ (lo, hi]. // - query the tail about what is last revision that changed an id,
// - query the tail about what is last revision that changed an id. // - query the tail for len and (tail, head].
// //
// ΔTail is safe to access for multiple-readers / single writer. // ΔTail is safe to access for multiple-readers / single writer.
// //
...@@ -61,13 +61,11 @@ type ΔTail struct { ...@@ -61,13 +61,11 @@ type ΔTail struct {
tailv []δRevEntry tailv []δRevEntry
lastRevOf map[Oid]Tid // index for LastRevOf queries lastRevOf map[Oid]Tid // index for LastRevOf queries
// TODO also add either tailv idx <-> rev index, or lastRevOf -> tailv idx
// (if linear back-scan of δRevEntry starts to eat cpu).
} }
// δRevEntry represents information of what have been changed in one revision. // δRevEntry represents information of what have been changed in one revision.
// //
// XXX -> CommitEvent? // XXX -> CommitEvent? -> ΔRevEntry?
type δRevEntry struct { type δRevEntry struct {
rev Tid rev Tid
changev []Oid changev []Oid
...@@ -78,7 +76,7 @@ func NewΔTail() *ΔTail { ...@@ -78,7 +76,7 @@ func NewΔTail() *ΔTail {
return &ΔTail{lastRevOf: make(map[Oid]Tid)} return &ΔTail{lastRevOf: make(map[Oid]Tid)}
} }
// Len returns number of elements. // Len returns number of revisions.
func (δtail *ΔTail) Len() int { func (δtail *ΔTail) Len() int {
return len(δtail.tailv) return len(δtail.tailv)
} }
...@@ -102,7 +100,7 @@ func (δtail *ΔTail) Tail() Tid { ...@@ -102,7 +100,7 @@ func (δtail *ΔTail) Tail() Tid {
return δtail.tailv[0].rev-1 return δtail.tailv[0].rev-1
} }
// SliceByRev returns δtail slice with .rev ∈ (low, high]. // SliceByRev returns δtail slice of elements with .rev ∈ (low, high].
// //
// it must be called with the following condition: // it must be called with the following condition:
// //
...@@ -110,7 +108,7 @@ func (δtail *ΔTail) Tail() Tid { ...@@ -110,7 +108,7 @@ func (δtail *ΔTail) Tail() Tid {
// //
// the caller must not modify returned slice. // the caller must not modify returned slice.
// //
// Note: contrary to regular go slicing, low is exclisive while high is inclusive. // Note: contrary to regular go slicing, low is exclusive while high is inclusive.
func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry { func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
tail := δtail.Tail() tail := δtail.Tail()
head := δtail.head head := δtail.head
...@@ -125,14 +123,14 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry { ...@@ -125,14 +123,14 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
return tailv return tailv
} }
// find max j : [j].rev ≤ high XXX linear scan // find max j : [j].rev ≤ high XXX linear scan -> binary search
j := len(tailv)-1 j := len(tailv)-1
for ; j >= 0 && tailv[j].rev > high; j-- {} for ; j >= 0 && tailv[j].rev > high; j-- {}
if j < 0 { if j < 0 {
return nil // ø return nil // ø
} }
// find max i : [i].rev > low XXX linear scan // find max i : [i].rev > low XXX linear scan -> binary search
i := j i := j
for ; i >= 0 && tailv[i].rev > low; i-- {} for ; i >= 0 && tailv[i].rev > low; i-- {}
i++ i++
...@@ -235,7 +233,7 @@ func (δtail *ΔTail) LastRevOf(id Oid, at Tid) (_ Tid, exact bool) { ...@@ -235,7 +233,7 @@ func (δtail *ΔTail) LastRevOf(id Oid, at Tid) (_ Tid, exact bool) {
} }
// what's in index is after at - scan tailv back to find appropriate entry // what's in index is after at - scan tailv back to find appropriate entry
// XXX linear scan // XXX linear scan - fix it by: .lastRevOf = {} oid -> []rev↑
for i := l - 1; i >= 0; i-- { for i := l - 1; i >= 0; i-- {
δ := δtail.tailv[i] δ := δtail.tailv[i]
if δ.rev > at { if δ.rev > at {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment