Ejemplo n.º 1
0
        public PathNode Remove()
        {
            this.numberOfItems--;
            PathNode node = this.binaryHeap[0].node;

            this.binaryHeap[0] = this.binaryHeap[this.numberOfItems];
            int num = 0;

            while (true)
            {
                int  num2 = num;
                uint f    = this.binaryHeap[num].F;
                int  num3 = num2 * 4 + 1;
                if (num3 <= this.numberOfItems && (this.binaryHeap[num3].F < f || (this.binaryHeap[num3].F == f && this.binaryHeap[num3].node.G < this.binaryHeap[num].node.G)))
                {
                    f   = this.binaryHeap[num3].F;
                    num = num3;
                }
                if (num3 + 1 <= this.numberOfItems && (this.binaryHeap[num3 + 1].F < f || (this.binaryHeap[num3 + 1].F == f && this.binaryHeap[num3 + 1].node.G < this.binaryHeap[num].node.G)))
                {
                    f   = this.binaryHeap[num3 + 1].F;
                    num = num3 + 1;
                }
                if (num3 + 2 <= this.numberOfItems && (this.binaryHeap[num3 + 2].F < f || (this.binaryHeap[num3 + 2].F == f && this.binaryHeap[num3 + 2].node.G < this.binaryHeap[num].node.G)))
                {
                    f   = this.binaryHeap[num3 + 2].F;
                    num = num3 + 2;
                }
                if (num3 + 3 <= this.numberOfItems && (this.binaryHeap[num3 + 3].F < f || (this.binaryHeap[num3 + 3].F == f && this.binaryHeap[num3 + 3].node.G < this.binaryHeap[num].node.G)))
                {
                    f   = this.binaryHeap[num3 + 3].F;
                    num = num3 + 3;
                }
                if (num2 == num)
                {
                    break;
                }
                BinaryHeapM.Tuple tuple = this.binaryHeap[num2];
                this.binaryHeap[num2] = this.binaryHeap[num];
                this.binaryHeap[num]  = tuple;
            }
            return(node);
        }
Ejemplo n.º 2
0
 public void Rebuild()
 {
     for (int i = 2; i < this.numberOfItems; i++)
     {
         int num = i;
         BinaryHeapM.Tuple tuple = this.binaryHeap[i];
         uint f = tuple.F;
         while (num != 1)
         {
             int num2 = num / 4;
             if (f >= this.binaryHeap[num2].F)
             {
                 break;
             }
             this.binaryHeap[num]  = this.binaryHeap[num2];
             this.binaryHeap[num2] = tuple;
             num = num2;
         }
     }
 }
Ejemplo n.º 3
0
        public void Add(PathNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (this.numberOfItems == this.binaryHeap.Length)
            {
                int num = Math.Max(this.binaryHeap.Length + 4, (int)Math.Round((double)((float)this.binaryHeap.Length * this.growthFactor)));
                if (num > 262144)
                {
                    throw new Exception("Binary Heap Size really large (2^18). A heap size this large is probably the cause of pathfinding running in an infinite loop. \nRemove this check (in BinaryHeap.cs) if you are sure that it is not caused by a bug");
                }
                BinaryHeapM.Tuple[] array = new BinaryHeapM.Tuple[num];
                for (int i = 0; i < this.binaryHeap.Length; i++)
                {
                    array[i] = this.binaryHeap[i];
                }
                this.binaryHeap = array;
            }
            BinaryHeapM.Tuple tuple = new BinaryHeapM.Tuple(node.F, node);
            this.binaryHeap[this.numberOfItems] = tuple;
            int  num2 = this.numberOfItems;
            uint f    = node.F;
            uint g    = node.G;

            while (num2 != 0)
            {
                int num3 = (num2 - 1) / 4;
                if (f >= this.binaryHeap[num3].F && (f != this.binaryHeap[num3].F || g <= this.binaryHeap[num3].node.G))
                {
                    break;
                }
                this.binaryHeap[num2] = this.binaryHeap[num3];
                this.binaryHeap[num3] = tuple;
                num2 = num3;
            }
            this.numberOfItems++;
        }