Commit af2ca266 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e7b598c6
...@@ -96,7 +96,7 @@ type ΔFtail struct { ...@@ -96,7 +96,7 @@ type ΔFtail struct {
// zblkTrack keeps information in which root/blocks ZBlk is present as of @head. // zblkTrack keeps information in which root/blocks ZBlk is present as of @head.
type zblkTrack struct { type zblkTrack struct {
inroot map[zodb.Oid]setI64 // {} root -> {}blk XXX later switch to this inroot map[zodb.Oid]setI64 // {} root -> {}blk
} }
// ΔF represents a change in files space. // ΔF represents a change in files space.
...@@ -395,6 +395,8 @@ func (δFtail *ΔFtail) ForgetPast(revCut zodb.Tid) { ...@@ -395,6 +395,8 @@ func (δFtail *ΔFtail) ForgetPast(revCut zodb.Tid) {
func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*readonly*/[]*ΔFile { func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*readonly*/[]*ΔFile {
xtail.AssertSlice(δFtail, lo, hi) xtail.AssertSlice(δFtail, lo, hi)
// XXX locking
// query .δBtail.SliceByRootRev(file.blktab, lo, hi) + // query .δBtail.SliceByRootRev(file.blktab, lo, hi) +
// merge δZBlk history with that. // merge δZBlk history with that.
...@@ -412,10 +414,110 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado ...@@ -412,10 +414,110 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
// δFile ────────o───────o──────x─────x──────────────────────── // δFile ────────o───────o──────x─────x────────────────────────
vδT := δFtail.δBtail.SliceByRootRev(zfile.blktab, lo, hi) // XXX needs activate zfile // vδT := δFtail.δBtail.SliceByRootRev(zfile.blktab, lo, hi) // XXX needs activate zfile
// XXX needs activate zfile
root := zfile.blktab.POid()
vδT := δFtail.δBtail.SliceByRootRev(root, lo, δFtail.Head()) // NOTE @head, not hi
vδZ := δFtail.δBtail.ΔZtail().SliceByRev(lo, hi) vδZ := δFtail.δBtail.ΔZtail().SliceByRev(lo, hi)
var vδf []*ΔFile var vδf []*ΔFile
// vδfTail returns or creates vδf entry for revision tail
// tail must be <= all vδf revisions
vδfTail := func(tail zodb.Tid) *ΔFile {
if l := len(vδf); l > 0 {
δfTail := vδf[l-1]
if δfTail.Rev == tail {
return δfTail
}
if !(tail <= δfTail.Rev) {
panic("tail not ↓")
}
}
δfTail := &ΔFile{Rev: tail, Blocks: setI64{}}
vδf = append(vδf, δfTail)
return δfTail
}
// state of Zinblk as we are scanning ←
// initially corresponds to @head = vδT[-1]
Zinblk := map[zodb.Oid]setI64{} // zblk -> which #blk refer to it
var ZinblkAt zodb.Tid // Zinblk covers [ZinblkAt,<next δT>)
for zblk, zt := range δFtail.trackSetZBlk {
inblk, ok := zt.inroot[root]
if ok {
Zinblk[zblk] = inblk.Clone()
}
}
it := len(vδT) - 1
if it >= 0 {
ZinblkAt = vδT[it].Rev
} else {
ZinblkAt = lo
}
// it--
iz := len(vδZ) - 1
for (iz >= 0 || it >= 0) {
// δZ that is covered by current Zinblk
// -> update δf
if iz >= 0 {
δZ := vδZ[iz]
if ZinblkAt <= δZ.Rev {
for _, oid := range δZ.Changev {
inblk, ok := Zinblk[oid]
if ok {
δf := vδfTail(δZ.Rev)
δf.Blocks.Update(inblk)
}
}
iz--
continue
}
}
// δT -> adjust Zinblk + update δf
if it >= 0 {
δT := vδT[it]
for blk, δzblk := range δT.ΔKV {
// apply in reverse as we go ←
if δzblk.New != xbtree.VDEL {
inblk, ok := Zinblk[δzblk.New]
if ok {
inblk.Del(blk)
}
}
if δzblk.Old != xbtree.VDEL {
inblk, ok := Zinblk[δzblk.Old]
if !ok {
inblk = setI64{}
Zinblk[δzblk.Old] = inblk
}
inblk.Add(blk)
}
if δT.Rev <= hi {
δf := vδfTail(δT.Rev)
δf.Blocks.Add(blk)
δf.Size = true // see Update
}
}
it--
if it >= 0 {
ZinblkAt = vδT[it].Rev
} else {
ZinblkAt = lo
}
}
}
// XXX reverse vδf before return
return vδf
/*
// state of `{} blk -> zblk` as we are scanning ↓ // state of `{} blk -> zblk` as we are scanning ↓
δblktab := map[int64]struct { δblktab := map[int64]struct {
zblk zodb.Oid // blk points to this zblk zblk zodb.Oid // blk points to this zblk
...@@ -444,6 +546,7 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado ...@@ -444,6 +546,7 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
} }
return vδf return vδf
*/
/* /*
......
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