Beispiel #1
0
 void Start()
 {
     tg = gameObject.GetComponent <TreeGenerator> () as TreeGenerator;
     tl = gameObject.GetComponent <TreeLeaves> () as TreeLeaves;
 }
Beispiel #2
0
        public bool AddedValue(int value)
        {
            #region Initialize first value and Root

            if (NodeCount == 0)
            {
                Index FirstIndex = new Index(NodeSize);
                Leaf  FirstLeaf  = new Leaf(NodeSize);

                //Add value to the first Index and Leaf
                FirstIndex.Items.Add(value);
                FirstLeaf.Items.Add(value);

                //Reference initial and first Leaf
                FirstIndex.LeafList.Add(new Leaf(NodeSize));
                FirstIndex.LeafList.Add(FirstLeaf);

                //Set IndexLevel
                FirstIndex.IndexLevel = 0;

                //Add index to IndexList and Root
                Root = new Index(FirstIndex);
                TreeIndexs.Add(Root);
                TreeLeaves.Add(FirstIndex.LeafList[0]);
                TreeLeaves.Add(FirstIndex.LeafList[1]);

                //Increment Counts
                NodeCount++;
                IndexCount++;
                LeafCount++;
                return(true);
            }

            #endregion

            #region Attempt to put value into a Leaf

            else
            {
                //Find Leaf to insert value
                Leaf   LeafToFill = FindLeaf(value);
                INSERT response   = LeafToFill.Insert(value);
                if (response == INSERT.DUPLICATE)
                {
                    //Do nothing since you need a unique new value
                    return(false);
                }
                else if (response == INSERT.NEEDSPLIT)
                {
                    //Split Leaf and Indexes if needed
                    SplitLeaf(LeafToFill);
                    return(true);
                }
                else
                {
                    //Success!
                    return(true);
                }
            }

            #endregion
        }