status_t ArpIndexedList::NodeFor(int32 index, void *rawData, ArpIndexedNode **answer) { ArpIndexedNode *originalNode, *node; // Assume that the user has supplied a useful index, and find the node closet to it. if (NodeAt(index, &node, 0, ARP_FORWARDS) == B_ERROR) { if (NodeAt(index, &node, 0, ARP_BACKWARDS) == B_ERROR) return B_ERROR; } if (node == 0) return B_ERROR; originalNode = node; // Seek forwards for the answer. while (node != 0) { if (node->RawContents() == rawData) { *answer = node; return B_OK; } node = node->next; } // If that doesn't work, try seeking backwards. node = originalNode; while (node != 0) { if (node->RawContents() == rawData) { *answer = node; return B_OK; } node = node->prev; } return B_ERROR; }
IntersectionNode IntersectionNodesInAirport::GetNodeByID(int id) const { IntersectionNode node; for (int i=0;i<GetCount();i++) { if (NodeAt(i).GetID() == id) { node = NodeAt(i); break; } } return node; }
void IntersectionNodesInAirport::UpdateDataToDB( int nAirportID, const std::vector<int>& vUpdateNodeIndexs ) { /*IntersectionNodeList DbIntersections; IntersectionNode::ReadNodeList(nAirportID,DbIntersections);*/ /*int nNodeIdx =0; for(IntersectionNodeList::iterator itrClac = m_vNodeList.begin();itrClac != m_vNodeList.end(); ++itrClac) { for(IntersectionNodeList::iterator itrDB = DbIntersections.begin();itrDB != DbIntersections.end();itrDB ++) { if( itrClac->GetID() == itrDB->GetID() || (*itrClac).IsIdentical( *itrDB ) ) { (*itrClac).m_nID = (*itrDB).m_nID; DbIntersections.erase(itrDB); break; } } } for(IntersectionNodeList::iterator itrDB = DbIntersections.begin();itrDB != DbIntersections.end();itrDB ++) { (*itrDB).DeleteData(); }*/ ////delete invalid nodes //for(IntersectionNodeList::iterator itrOld = m_vOldList.begin();itrOld != m_vOldList.end();itrOld ++) //{ // IntersectionNode& theOldNode = *itrOld; // bool bNodeInNewList = false; // for(IntersectionNodeList::iterator itrClac = m_vNodeList.begin();itrClac != m_vNodeList.end(); ++itrClac) // { // IntersectionNode& theNewNode = *itrClac; // if( theNewNode.GetID() == theOldNode.GetID() || theNewNode.IsIdentical(theOldNode ) ) // { // theNewNode.m_nID = theOldNode.m_nID; // bNodeInNewList = true; // break; // } // } // if( !bNodeInNewList ) // theOldNode.DeleteData(); // //} for(int i=0;i< (int)vUpdateNodeIndexs.size();i++) { IntersectionNode& theNode = NodeAt(vUpdateNodeIndexs[i]); theNode.SaveData(nAirportID); } //m_vOldList = m_vNodeList; }
PVOID MemAllocator::Alloc() { //_aligned_malloc( AllocationSize, 32 ); assert(CountFree); if (!CountFree) { return malloc(AllocationSize); //new BYTE[AllocationSize]; } ULONG nFreeIndex = IndexAt(FirstFree); ++FirstFree %= CountTotal; CountFree--; return NodeAt(nFreeIndex); }
int IntersectionNodesInAirport::FindNodeIndex( int nObjID1, DistanceUnit distofObj1, int nObjID2 ) const { DistanceUnit minDist = ARCMath::DISTANCE_INFINITE; int nFitNodeId = -1; for (int i=0;i<GetCount();i++) { IntersectionNode theNode = NodeAt(i); if( theNode.HasObject(nObjID1) && theNode.HasObject(nObjID2) ){ DistanceUnit theDist = theNode.GetDistance(nObjID1); DistanceUnit offsetDist = abs(theDist - distofObj1); if( offsetDist< minDist) { minDist = offsetDist; nFitNodeId = i; } } } return nFitNodeId; }
ULONG& MemAllocator::IndexAt(ULONG index) { return *(ULONG*) (NodeAt(index) + AllocationSize); }