ns-allinone-2.35/ns-2.35/linkstate/ls.cc
bool LsTopoMap::update(int nodeId, 
		       const LsLinkStateList& linkStateList)
{
	LsLinkStateList * LSLptr = findPtr (nodeId);
	if (LSLptr == NULL) {
		insert(nodeId, linkStateList);
		return true;
	}

	bool retCode = false;
	LsLinkStateList::iterator itrOld;
	for (LsLinkStateList::const_iterator itrNew = linkStateList.begin();
	     itrNew != linkStateList.end(); itrNew++ ) {
  
		for (itrOld = LSLptr->begin();
		     itrOld != LSLptr->end(); itrOld++) {

			if ((*itrNew).neighborId_ == (*itrOld).neighborId_) {
				// old link state found
				if (nodeId != myNodeId_)
					// update the sequence number, if 
					// it's not  my own link state
					(*itrOld).sequenceNumber_ = 
						(*itrNew).sequenceNumber_;
				if ((*itrNew).status_ != (*itrOld).status_) {
					(*itrOld).status_ = (*itrNew).status_;
					retCode = true;
				}
				if ((*itrNew).cost_ != (*itrOld).cost_) {
					(*itrOld).cost_ = (*itrNew).cost_;
					retCode = true;
				}
				break; // no need to search for more old link state;
			} // end if old link state found
		} // end for old link states
		if (itrOld == LSLptr->end()) {
			// no old link found
			LSLptr->push_back(*itrNew);
			retCode = true;
		}
	}// end for new link states 
	return retCode;
}
// -- update --, return true if anything's changed 
-, return true if anything's changed
- return true if anything ' s changed
bool LsTopoMap::update(int nodeId, 
		       const LsLinkStateList& linkStateList)
{
	LsLinkStateList * LSLptr = findPtr (nodeId);
	if (LSLptr == NULL) {
		insert(nodeId, linkStateList);
		return true;
	}
	bool retCode = false;
	LsLinkStateList::iterator itrOld;
	for (LsLinkStateList::const_iterator itrNew = linkStateList.begin();
	     itrNew != linkStateList.end(); itrNew++ ) {
		for (itrOld = LSLptr->begin();
		     itrOld != LSLptr->end(); itrOld++) {
			if ((*itrNew).neighborId_ == (*itrOld).neighborId_) {
				if (nodeId != myNodeId_)
					(*itrOld).sequenceNumber_ = 
						(*itrNew).sequenceNumber_;
				if ((*itrNew).status_ != (*itrOld).status_) {
					(*itrOld).status_ = (*itrNew).status_;
					retCode = true;
				}
				if ((*itrNew).cost_ != (*itrOld).cost_) {
					(*itrOld).cost_ = (*itrNew).cost_;
					retCode = true;
				}
				break; 
			} 
		} 
		if (itrOld == LSLptr->end()) {
			LSLptr->push_back(*itrNew);
			retCode = true;
		}
	}
	return retCode;
}
bool LsTopoMap :: update ( int nodeId , const LsLinkStateList & linkStateList ) { LsLinkStateList * LSLptr = findPtr ( nodeId ) ; if ( LSLptr == NULL ) { insert ( nodeId , linkStateList ) ; return true ; } bool retCode = false ; LsLinkStateList :: iterator itrOld ; for ( LsLinkStateList :: const_iterator itrNew = linkStateList . begin ( ) ; itrNew != linkStateList . end ( ) ; itrNew ++ ) { for ( itrOld = LSLptr -> begin ( ) ; itrOld != LSLptr -> end ( ) ; itrOld ++ ) { if ( ( * itrNew ) . neighborId_ == ( * itrOld ) . neighborId_ ) { if ( nodeId != myNodeId_ ) ( * itrOld ) . sequenceNumber_ = ( * itrNew ) . sequenceNumber_ ; if ( ( * itrNew ) . status_ != ( * itrOld ) . status_ ) { ( * itrOld ) . status_ = ( * itrNew ) . status_ ; retCode = true ; } if ( ( * itrNew ) . cost_ != ( * itrOld ) . cost_ ) { ( * itrOld ) . cost_ = ( * itrNew ) . cost_ ; retCode = true ; } break ; } } if ( itrOld == LSLptr -> end ( ) ) { LSLptr -> push_back ( * itrNew ) ; retCode = true ; } } return retCode ; }
update --, return true if anything's changed
update -- return true if anything ' s changed
// old link state found // update the sequence number, if  // it's not  my own link state // no need to search for more old link state; // end if old link state found // end for old link states // no old link found // end for new link states 