"os"
)
+// If true, check poset integrity after every mutation
+var debugPoset = false
+
const uintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64
// bitset is a bit array for dense indexes.
// to tell.
// Complexity is O(n).
func (po *poset) Ordered(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Ordered with n1==n2")
}
// to tell.
// Complexity is O(n).
func (po *poset) OrderedOrEqual(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Ordered with n1==n2")
}
// to tell.
// Complexity is O(1).
func (po *poset) Equal(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Equal with n1==n2")
}
// Complexity is O(n) (because it internally calls Ordered to see if we
// can infer n1!=n2 from n1<n2 or n2<n1).
func (po *poset) NonEqual(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Equal with n1==n2")
}
// SetOrder records that n1<n2. Returns false if this is a contradiction
// Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
func (po *poset) SetOrder(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call SetOrder with n1==n2")
}
// SetOrderOrEqual records that n1<=n2. Returns false if this is a contradiction
// Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
func (po *poset) SetOrderOrEqual(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call SetOrder with n1==n2")
}
// (that is, if it is already recorded that n1<n2 or n2<n1).
// Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
func (po *poset) SetEqual(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Add with n1==n2")
}
// (that is, if it is already recorded that n1==n2).
// Complexity is O(n).
func (po *poset) SetNonEqual(n1, n2 *Value) bool {
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
if n1.ID == n2.ID {
panic("should not call Equal with n1==n2")
}
if len(po.undo) == 0 {
panic("empty undo stack")
}
+ if debugPoset {
+ defer po.CheckIntegrity()
+ }
for len(po.undo) > 0 {
pass := po.undo[len(po.undo)-1]
panic(pass.typ)
}
}
+
+ if debugPoset && po.CheckEmpty() != nil {
+ panic("poset not empty at the end of undo")
+ }
}