bool DirectedGraph::removeEdge(int fromNodeId, int toNodeId) {
	ListType::iterator neighborToRemove;
	ListType* fromNeighbors = inNeighborsTable[toNodeId];
	
	neighborToRemove = std::lower_bound(fromNeighbors->begin(), fromNeighbors->end(), fromNodeId);
	if (neighborToRemove != fromNeighbors->end() && (*neighborToRemove == fromNodeId))
		fromNeighbors->erase(neighborToRemove);
	else
		return false;
	
	ListType* toNeighbors = outNeighborsTable[fromNodeId];
	neighborToRemove = std::lower_bound(toNeighbors->begin(), toNeighbors->end(), toNodeId);
	assert(*neighborToRemove == toNodeId);
	toNeighbors->erase(neighborToRemove);
	edgeCount--;
	return true;
}
Beispiel #2
0
	void addToList(const typename ListType::value_type &data, ListType &list) const {
		if (length()<=0) {
			// Ensure that no dummy data will get added. Shouldn't get here.
			return;
		}
		if (startbyte()==0 && goesToEndOfFile()) {
			// favor a single chunk covering the whole file.
			list.clear();
			list.insert(list.end(), data);
			return;
		}

		typename ListType::iterator endIter=list.end(), iter=list.begin();
		Range::base_type startdata = startbyte();
		Range::base_type maxend = startdata;
		bool includeseof = false;
		while (iter != endIter) {
			// maxend is not relevant for ranges strictly above us.
			if ((*iter).startbyte() > startdata) {
				break;
			}
			if ((*iter).endbyte() > maxend) {
				maxend = (*iter).endbyte();
			}
			if ((*iter).goesToEndOfFile()) {
				includeseof = true;
			}
			// we do not want to allow for more than one
			// range starting at the same start byte--
			// If this is the case, one is guaranteed to overlap.
			if ((*iter).startbyte() >= startdata) {
				break;
			}
			++iter;
		}
		if (includeseof || (maxend > endbyte() && !goesToEndOfFile())) {
			return; // already included by another range.
		}
		iter = list.insert(iter, data);
		++iter;
		while (iter != endIter) {
			typename ListType::iterator nextIter = iter;
			++nextIter;

			if (goesToEndOfFile() ||
					(!(*iter).goesToEndOfFile() && (*iter).endbyte() <= endbyte())) {
				list.erase(iter);
			}

			iter = nextIter;
		}
	}