示例#1
0
        /*************************/
        // Basic operations
        /*************************/
        // Inserting works correctly because we assume that a node that gets newly inserted will not be in the tree already
        // By definition of boolean decompositions this is redundant and the node should be removed from the decomposition tree
        public void Insert(BitSet node)
        {
            if (Parent.ContainsKey(node))
                throw new Exception("This node already exists in the decomposition tree");

            // Check if this is the first node that we add to the collection
            if (Size == 0)
            {
                root = node;
                Contained.Add(node);
                return;
            }

            // The parent of the node that we are currently insering should be the node X that this node is a subset of, and X is has the highest index so far
            BitSet parent = new BitSet(0, 0);
            for (int i = Size - 1; i >= 0; i--)
            {
                parent = Contained[i];
                if (node.IsSubsetOf(parent))
                    break;
            }

            Parent[node] = parent;

            // The node will always be a leftchild if the previously inserted node had an even number, and vice versa
            // This assumes that we always add children of a node directly after each other
            if (Size % 2 == 0)
                RightChild[parent] = node;
            else
                LeftChild[parent] = node;

            Contained.Add(node);
        }