Example #1
0
void ReactantList::removeMappingSet(unsigned int mappingSetId)
{
	//Make sure this mappingSet is not empty
	if(n_mappingSets==0) {
		printDetails();
		cout.flush();
		cerr<<"Trying to remove from an empty ReactantList!!"<<endl;
		exit(1);
	}

	//First, get the position of the mappingSet we need to remove
	int pos = msPositionMap[mappingSetId];

	//Make sure the position is valid (not out of bounds of the List)
	if(pos+1>(n_mappingSets)) {
		cout<<"Error in ReactantList:  you can't remove a mappingSet that has been cleared! (trying to remove: "<< mappingSetId << " in pos " << pos <<" but size is: "<<size()<<endl;
		printDetails();

		return;
	}

	//If the array has only one element, or we just happened to select the last element,
	//then just remove the last element without a swap
	if( pos+1 == (n_mappingSets) ) {
		popLastMappingSet();
		return;
	}

	//Otherwise, we have to swap with the last element in the list
	MappingSet *tempMappingSet = mappingSets[pos];
	mappingSets[pos] = mappingSets[n_mappingSets-1];
	mappingSets[n_mappingSets-1] = tempMappingSet;

	//Careful here!  We have to swap values in the msPositionMap
	//so that msPositionMap[mappingId] points correctly to where
	//that MappingSet now lives.  Notice that this is a different
	//swap than above in the MappingSets array!
	msPositionMap[mappingSetId] = n_mappingSets-1;
	msPositionMap[mappingSets[pos]->getId()] = pos;

	//Remember to remove
	n_mappingSets--;

	//Make sure we clear what we don't need
	unsigned int clone = tempMappingSet->getClonedMapping();
	tempMappingSet->clear();



	//Now, IF this mapping set had a clone, we have to remove it as well
	if(clone!=MappingSet::NO_CLONE) {
		this->removeMappingSet(clone);
	}
}
Example #2
0
void ReactantTree::removeMappingSet(unsigned int mappingSetId)
{
	if(n_mappingSets==0) {
		cerr<<"Trying to remove from an empty ReactantTree!!"<<endl;
		exit(1);
	}

	//first get the position of this mappingSet in the tree
	int msTreeArrayPosition = msTreePositionMap[mappingSetId];


	//If we have already confirmed this push on the tree, we must take it out of
	//the tree.  IF we didn't find this on the tree, then perhaps it just wasn't
	//pushed on yet.
	if(msTreeArrayPosition>=0) {
		removeFromTreeOnly(msTreeArrayPosition,mappingSetId);
	}


	//At this point, the tree is up to date, but we still have to get rid of the empty mappingSet
	//by swapping it with the end of the list...  This will allow us to reuse the mappingSet without
	//destroying it and creating it again later...


	//So first, get the position of the mappingSet we need to remove
	int pos = msPositionMap[mappingSetId];

	//Make sure the position is valid (not out of bounds of the List)
	if(pos+1>(n_mappingSets)) {
		cout<<"Error in ReactantTree:  you can't remove a mappingSet that has been cleared! (trying to remove: ";
		cout<< mappingSetId << " in pos " << pos <<" but size is: "<<size()<<endl;
		exit(1);
	}

	//If the array has only one element, or we just happened to select the last element,
	//then just remove the last element without a swap - we can do this by popping the
	//last mapping set.  This will work, because we already cleared the tree at this location
	if( pos+1 == (n_mappingSets) ) {
		popLastMappingSet();
		return;
	}

	//Otherwise, we have to swap with the last element in the list
	MappingSet *tempMappingSet = mappingSets[pos];
	mappingSets[pos] = mappingSets[n_mappingSets-1];
	mappingSets[n_mappingSets-1] = tempMappingSet;

	//Careful here!  We have to swap values in the msPositionMap
	//so that msPositionMap[mappingId] points correctly to where
	//that MappingSet now lives.
	msPositionMap[mappingSetId] = n_mappingSets-1;
	msPositionMap[mappingSets[pos]->getId()] = pos;

	//Make sure we clear what we don't need
	unsigned int clone = mappingSets[n_mappingSets-1]->getClonedMapping();
	tempMappingSet->clear();

	//Remember to mark the removal on our counter...
	n_mappingSets--;

	//Remove all the clones as well
	if(clone!=MappingSet::NO_CLONE) {
		this->removeMappingSet(clone);
	}
}