public override ItcId Sum(ItcId aOther) { if (aOther != Zero) { throw new Exception("Over unity."); } return this; }
public static ItcId Tree(ItcId aLeft, ItcId aRight) { if (aLeft == One && aRight == One) { return One; } if (aLeft == Zero && aRight == Zero) { return Zero; } return new ItcIdTree(aLeft, aRight); }
public override ItcEvent Grow(ItcId aId, out long aCost) { if (aId == ItcId.One) { aCost = 0; return Single(iValue + 1); } long cost; ItcEvent evPrime = new ItcEventTree(iValue, Zero, Zero).Grow(aId, out cost); aCost = cost + GrowConstant; return evPrime; }
internal override ItcEvent Fill(ItcId aLeft, ItcId aRight) { if (aLeft == ItcId.One) { ItcEvent rightPrime = aRight.Fill(iRight); return Tree( iValue, Single(Math.Max(iLeft.Max, rightPrime.Min)), rightPrime); } if (aRight == ItcId.One) { ItcEvent leftPrime = aLeft.Fill(iLeft); return Tree( iValue, leftPrime, Single(Math.Max(iRight.Max, leftPrime.Min))); } return Tree( iValue, aLeft.Fill(iLeft), aRight.Fill(iRight)); }
public ItcEvent InternalGrow(ItcId aLeft, ItcId aRight, out long aCost) { long costLeft, costRight; ItcEvent growLeft, growRight; if (aRight != ItcId.Zero) { growRight = iRight.Grow(aRight, out costRight); } else { growRight = null; costRight = long.MaxValue; } if (aLeft != ItcId.Zero) { growLeft = iLeft.Grow(aLeft, out costLeft); } else { growLeft = null; costLeft = long.MaxValue; } Debug.Assert(growLeft != null || growRight != null); if (costLeft < costRight) { aCost = costLeft + 1; return Tree(iValue, growLeft, iRight); } aCost = costRight + 1; return Tree(iValue, iLeft, growRight); }
public override ItcEvent Grow(ItcId aId, out long aCost) { return aId.InternalGrow(this, out aCost); }
internal ItcStamp(ItcId aId, ItcEvent aEvent) { iId = aId; iEvent = aEvent; }
public override void Split(out ItcId aLeft, out ItcId aRight) { if (Zero == iLeft) { ItcId sub1, sub2; iRight.Split(out sub1, out sub2); aLeft = Tree(Zero, sub1); aRight = Tree(Zero, sub2); } else if (Zero == iRight) { ItcId sub1, sub2; iLeft.Split(out sub1, out sub2); aLeft = Tree(sub1, Zero); aRight = Tree(sub2, Zero); } else { aLeft = Tree(iLeft, Zero); aRight = Tree(Zero, iRight); } }
public ItcEvent Grow(ItcId aId) { long ignore; return Grow(aId, out ignore); }
public abstract ItcId Sum(ItcId aOther);
public abstract void Split(out ItcId aLeft, out ItcId aRight);
public override ItcId Sum(ItcId aOther) { return aOther; }
public override void Split(out ItcId aLeft, out ItcId aRight) { aLeft = Zero; aRight = Zero; }
public override ItcId Sum(ItcId aOther) { if (Zero == aOther) { return this; } if (One == aOther) { throw new Exception("Over unity."); } var otherTree = (ItcIdTree) aOther; return Tree(iLeft.Sum(otherTree.iLeft), iRight.Sum(otherTree.iRight)); }
internal override ItcEvent Fill(ItcId aLeft, ItcId aRight) { return this; }
public abstract ItcEvent Grow(ItcId aId, out long aCost);
public override void Split(out ItcId aLeft, out ItcId aRight) { aLeft = Tree(One, Zero); aRight = Tree(Zero, One); }
internal abstract ItcEvent Fill(ItcId aLeft, ItcId aRight);
public ItcIdTree(ItcId aLeft, ItcId aRight) { iLeft = aLeft; iRight = aRight; }