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

.

parent 1a4b5673
...@@ -217,10 +217,18 @@ type ΔTree struct { ...@@ -217,10 +217,18 @@ type ΔTree struct {
} }
// XXX is a set of PP(leafs) nodes XXX -> PTreeSubSet ? TreePSubSet ? TreePPSet ? PPSubSet ?
// XXX PPNodeSet? TreePPSubSet ?
//
// where PP maps a leaf to {leaf, leaf.parent, leaf.parent.parent, ...} up to
// top root node from where the leaf is reached.
//
// Every node in the set also has .parent pointer.
//
// XXX place // XXX place
type trackIndex map[zodb.Oid]*nodeTrack type trackIndex map[zodb.Oid]*nodeTrack
// XXX place // XXX place XXX PTreeSubSetNode ?
// nodeTrack represents tracking information about a node. // nodeTrack represents tracking information about a node.
type nodeTrack struct { type nodeTrack struct {
parent zodb.Oid // parent node | InvalidOid for root parent zodb.Oid // parent node | InvalidOid for root
...@@ -314,20 +322,37 @@ func (tidx trackIndex) verify() { ...@@ -314,20 +322,37 @@ func (tidx trackIndex) verify() {
} }
} }
// Update tidx with trees subsets from tidx2. // DifferenceInplace sets A = PP(A.leafs \ B.leafs)
func (tidx trackIndex) Update(tidx2 trackIndex) { //
//fmt.Printf("\n\nUpdate:\n") // In other words it removes B nodes from A while still maintaining A as P-connected.
//fmt.Printf("tidx: %s\n", tidx) func (A trackIndex) DifferenceInplace(B trackIndex) {
//fmt.Printf("tidx2: %s\n", tidx2) //fmt.Printf("\n\nDifferenceInplace:\n")
//fmt.Printf("A: %s\n", A)
//fmt.Printf("B: %s\n", B)
tidx.verify() A.verify()
tidx2.verify() B.verify()
defer A.verify()
panic("TODO")
}
for oid, t2 := range tidx2 { // UnionInplace sets A = PP(A.leafs | B.leafs)
t, already := tidx[oid] //
// In other words it adds B nodes to A.
func (A trackIndex) UnionInplace(B trackIndex) {
//fmt.Printf("\n\nUnionInplace:\n")
//fmt.Printf("A: %s\n", A)
//fmt.Printf("B: %s\n", B)
A.verify()
B.verify()
defer A.verify()
for oid, t2 := range B {
t, already := A[oid]
if !already { if !already {
t = &nodeTrack{parent: t2.parent, nchild: t2.nchild} t = &nodeTrack{parent: t2.parent, nchild: t2.nchild}
tidx[oid] = t A[oid] = t
} else { } else {
if t2.parent != t.parent { if t2.parent != t.parent {
// XXX or verify this at Track time and require // XXX or verify this at Track time and require
...@@ -343,12 +368,10 @@ func (tidx trackIndex) Update(tidx2 trackIndex) { ...@@ -343,12 +368,10 @@ func (tidx trackIndex) Update(tidx2 trackIndex) {
if t.parent != zodb.InvalidOid { if t.parent != zodb.InvalidOid {
// this node is already present in both trees // this node is already present in both trees
// compensate for that in its parent (which must be present) // compensate for that in its parent (which must be present)
tidx[t.parent].nchild-- A[t.parent].nchild--
} }
} }
} }
tidx.verify()
} }
// ApplyΔ applies δ to trackIdx. XXX // ApplyΔ applies δ to trackIdx. XXX
...@@ -743,7 +766,7 @@ func (δBtail *ΔBtail) rebuild() (err error) { ...@@ -743,7 +766,7 @@ func (δBtail *ΔBtail) rebuild() (err error) {
// //
// XXX -> teach diffT to return not only δtrack, but also δtrack* // XXX -> teach diffT to return not only δtrack, but also δtrack*
// (conjugate) that would describe how track index changes if going A<-B ? // (conjugate) that would describe how track index changes if going A<-B ?
δBtail.trackIdx.Update(trackNew) δBtail.trackIdx.UnionInplace(trackNew)
return nil return nil
} }
......
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