Esempio n. 1
0
            /// <summary>
            /// adds a child node to this node, and splits the node if it has more children than 'BlockSieve.maxChildrenPerNode'
            /// </summary>
            /// <param name="intervalBitSet">the vertex set of the child on this interval</param>
            /// <param name="child">the child node</param>
            public void AddChild(BitSet intervalBitSet, SieveNode child)
            {
                children.Add((intervalBitSet, child));

                child.parent = this;

                if (children.Count > maxChildrenPerNode)
                {
                    Split();
                }
            }
Esempio n. 2
0
        /// <summary>
        /// adds a ptdur to this sieve
        /// </summary>
        /// <param name="ptdur">the ptdur to add</param>
        /// <param name="forceAddition">forces the addition of the ptdur without testing if a ptdur already exists that is 'better' in terms of optional components</param>
        /// <returns>the leaf that this ptdur is stored in</returns>
        public Leaf Add(PTD ptdur, bool forceAddition = false)
        {
            SieveNode currentNode = startNode;

            // traverse the tree
            do
            {
                InnerNode currentInnerNode = currentNode as InnerNode;

                // if it exists, then find the child with the matching interval BitSet and mark it as the current node
                bool currentNodeHasMatchingChild = false;
                for (int i = 0; i < currentInnerNode.children.Count; i++)
                {
                    (BitSet childSet, SieveNode sieveNode) = currentInnerNode.children[i];
                    if (ptdur.vertices.EqualsOnInterval(childSet, currentInnerNode.intervalFrom, currentInnerNode.intervalTo))
                    {
                        currentNode = sieveNode;
                        currentNodeHasMatchingChild = true;
                        break;
                    }
                }
                // if such a child does not exist, make one
                if (!currentNodeHasMatchingChild)
                {
                    // add new inner node that covers the rest of the interval if the current node doesn't cover it fully
                    if (currentInnerNode.intervalTo < vertexCount)
                    {
                        InnerNode newNode        = new InnerNode(currentInnerNode.intervalTo, vertexCount, currentInnerNode);
                        BitSet    intervalBitSet = ptdur.vertices;
                        currentInnerNode.AddChild(intervalBitSet, newNode);
                        currentInnerNode = newNode;
                    }

                    Debug.Assert(currentInnerNode.intervalTo == vertexCount);

                    // add leaf
                    Leaf newLeaf = new Leaf(ptdur, currentInnerNode);
                    currentInnerNode.AddChild(ptdur.vertices, newLeaf);
                    currentNode = newLeaf;

                    return(newLeaf);
                }
            }while (!currentNode.isLeaf);


            // test if a ptdur exists in this leaf that is 'better' than the one to add or vice versa
            Leaf currentNodeAsLeaf = currentNode as Leaf;

            currentNodeAsLeaf.ptdur = ptdur;
            return(currentNodeAsLeaf);
        }