static public void Test() { BitVector S1 = 0b0011_0010; BitVector S2 = 0b0100_0011; Debug.Assert(SetOp.Union(S1, S2) == 0b0111_0011); Debug.Assert(SetOp.Union(S1, S2) == SetOp.Union(S2, S1)); Debug.Assert(SetOp.Intersect(S1, S2) == 0b0000_0010); Debug.Assert(SetOp.Intersect(S1, S2) == SetOp.Intersect(S2, S1)); Debug.Assert(SetOp.Substract(S1, S2) == 0b0011_0000); Debug.Assert(SetOp.Substract(S2, S1) == 0b0100_0001); Debug.Assert(SetOp.CountSetBits(S1) == 3); Debug.Assert(SetOp.MinTableIndex(S1) == 1); Debug.Assert(SetOp.MinTableIndex(S2) == 0); Debug.Assert(SetOp.OrderBeforeSet(3) == 15); var l = SetOp.TablesAscending(S2).ToList(); Debug.Assert(l.SequenceEqual(new List <int>() { 0, 1, 6 })); l = SetOp.TablesDescending(S2).ToList(); Debug.Assert(l.SequenceEqual(new List <int>() { 6, 1, 0 })); }
static internal string ToString(BitVector S) { string r = ""; foreach (var t in SetOp.TablesAscending(S)) { r += t + ", "; } return(r); }
// given a set of tables, returns the set of its neighbours BitVector Neighbours(BitVector S) { BitVector result = 0; int ntables = vertices_.Count; foreach (var t in SetOp.TablesAscending(S)) { foreach (var n in NeighboursOf(t)) { result |= (long)(1 << n); } } return(result); }
// extra a subgraph for the given nodes set S // (1) we shall also remove both uncovered nodes and edges // (2) make this as fast as possible as it is tightly tested in // DP_bushy algorithm // // say we have // A - B - C // \ D // SubGraph(ABD) => {A-D and non-connected node C}. // internal JoinGraph SubGraph(BitVector S) { var subvert = new List <LogicNode>(); var subtablelist = SetOp.TablesAscending(S).ToList(); foreach (var t in subtablelist) { subvert.Add(vertices_[t]); } var subjoins = new List <Expr>(); foreach (var j in preds_) { var i12 = ParseJoinPredExpr(j); int i1 = i12[0], i2 = i12[1]; if (subtablelist.Contains(i1) && subtablelist.Contains(i2)) { subjoins.Add(j); } } return(new JoinGraph(subvert, subjoins)); }