DoubleLinkedList<GraphNode *> Dijkstra(GraphNode *Start, GraphNode * End) { Map<GraphNode *, DijkstraHelperNode *> NodeHelperMap; DoubleLinkedList<DijkstraHelperNode *> Visited; MinHeap<DijkstraHelperNode *> OpenHeap; DijkstraHelperNode *NewHelper = new DijkstraHelperNode(); NewHelper->m_Node = Start; NewHelper->m_Cost = 0; NodeHelperMap.Insert(Start, NewHelper); OpenHeap.Insert(NewHelper); while(!OpenHeap.IsEmpty()) { DijkstraHelperNode *CurrentHelperNode = OpenHeap.PopTop(); assert(CurrentHelperNode != NULL); GraphNode *CurrentGraphNode = CurrentHelperNode->m_Node; assert(CurrentGraphNode != NULL); DoubleLinkedList<GraphEdge *> *CurrendEdges = CurrentGraphNode->GetEdges(); DoubleListNode<GraphEdge *> *CurrentEdge = CurrentEdges.GetHead(); while(CurrentEdge != NULL) { GraphNode *OtherNode = CurrentEdge->m_End; if(OtherNode == CurrentGraphNode) { OtherNode = CurrentEdge->m_Start; } assert(OtherNode != CurrentGraphNode); DijkstraHelperNode *NodeHelper = NodeHelperMap.GetValue(OtherNode); if(NodeHelper == NULL) { NodeHelper = new DijkstraHelperNode(); NodeHelper->m_Node = OtherNode; NodeHelperMap.Insert(OtherNode, NodeHelper); OpenHeap.Insert(NodeHelper); } int CostToNode = CurrentHelperNode->m_Cost + CurrentEdge->m_Cost; if(CostToNode < NodeHelper->m_Cost) { NodeHelper->m_Cost = CostToNode; NodeHelper->m_Previous = CurrentGraphNode; OpenHeap.Update(NodeHelper); } if(OtherNode == End) { break; } } } DoubleLinkedList<GraphNode *> Path; DijkstraHelperNode *EndHelper = NodeHelperMap.GetValue(End); if(EndHelper != NULL) { DijkstraHelperNode *CurrentHelper = EndHelper; while(CurrentHelper != NULL) { Path.AddFront(CurrentHelper->m_Node); CurrentHelper = CurrentHelper->m_Previous; } } }
void ReverseHash::RegisterHash( const HashedString& Hash, const SimpleString& String ) { if( gReverseHashEnabled ) { #if BUILD_DEV const Map<HashedString, SimpleString>::Iterator HashIter = gReverseHashMap.Search( Hash ); if( HashIter.IsValid() ) { const SimpleString ExistingString = HashIter.GetValue(); if( ExistingString != String ) { PRINTF( "ReverseHash: Hash collision detected between \"%s\" and \"%s\"!\n", ExistingString.CStr(), String.CStr() ); } } #endif gReverseHashMap[ Hash ] = String; } else { // Even though it's safe, this shouldn't be called if the reverse hash isn't enabled, // because it could be wasting time doing the SimpleString construction. WARNDESC( "ReverseHash: Not enabled." ); } }
SimpleString ReverseHash::ReversedHash( const HashedString& Hash ) { if( gReverseHashEnabled ) { const Map<HashedString, SimpleString>::Iterator HashIter = gReverseHashMap.Search( Hash ); if( HashIter.IsValid() ) { return HashIter.GetValue(); } else { WARN; return SimpleString( "(Hash)" ); } } else { WARNDESC( "ReverseHash: Not enabled." ); return SimpleString( "" ); } }