Pathfinding.BinaryHeapM.Rebuild C# (CSharp) Méthode

Rebuild() public méthode

public Rebuild ( ) : void
Résultat void
		public void Rebuild () {
#if ASTARDEBUG
			int changes = 0;
#endif
			
			for (int i=2;i<numberOfItems;i++) {
				int bubbleIndex = i;
				PathNode node = binaryHeap[i];
				uint nodeF = node.F;
				while (bubbleIndex != 1) {
					int parentIndex = bubbleIndex / 2;
					
					if (nodeF < binaryHeap[parentIndex].F) {
						//Node tmpValue = binaryHeap[parentIndex];
						binaryHeap[bubbleIndex] = binaryHeap[parentIndex];
						binaryHeap[parentIndex] = node;
						bubbleIndex = parentIndex;
#if ASTARDEBUG
						changes++;
#endif
					} else {
						break;
					}
				}
				
			}
			
#if ASTARDEBUG
			Debug.Log ("+++ Rebuilt Heap - "+changes+" changes +++");
#endif
			
		}
	}

Usage Example

Exemple #1
0
 /** Rebuild the heap to account for changed node values.
  * Some path types change the target for the H score in the middle of the path calculation,
  * that requires rebuilding the heap to keep it correctly sorted.
  */
 public void RebuildHeap()
 {
     heap.Rebuild();
 }