src/Generic/edt/discmodel/CorefUtils.cpp
/**
 *  Insert an Entity into an array of entities sorted
 *  ascendingly w.r.t. link distance from a target 
 *  Mention
 *  
 *  @param sortedArray the array into which we want to insert
 *  @param currSolution the current working EntitySet
 *  @param ent the Entity in question
 *  @param ment the target Mention
 *  @param maxEntities the maximum number of entities 
 *                     permitted in <code>sortedArray</code>
 */
Insert an Entity into an array of entities sorted
ascendingly w.r.t. link distance from a target
Mention


Insert an Entity into an array of entities sorted ascendingly w . r . t . link distance from a target Mention
void CorefUtils::insertEntityIntoSortedArray(GrowableArray<Entity *> &sortedArray, 
											 const EntitySet *currSolution, 
											 Entity *ent, const Mention *ment, 
											 int maxEntites) 
{
	MentionUID lastID = getLatestMention(currSolution, ent, ment);
	if (lastID.isValid()) {
		bool inserted = false;
		for (int j = 0; j < sortedArray.length(); j++) {
			if (lastID < getLatestMention(currSolution, sortedArray[j], ment)) {
				if (sortedArray.length() == maxEntites) {
					for (int k = 0; k < j; k++)
						sortedArray[k] = sortedArray[k+1];
				} else {
					sortedArray.add(sortedArray[sortedArray.length()-1]);
					for (int k = sortedArray.length()-2; k >= j; k--)
						sortedArray[k+1] = sortedArray[k];
				}
				sortedArray[j] = ent;
				inserted = true;
				break;
			}
		}
		if (!inserted && (sortedArray.length() < maxEntites)) {
			sortedArray.add(ent);
		}
		if (sortedArray.length() > maxEntites) {
			Entity *tmp, *nextEnt = sortedArray.removeLast();
			for (int i = sortedArray.length()-1; i >= 0; i--) {
				tmp = sortedArray[i];
				sortedArray[i] = nextEnt;
				nextEnt = tmp;
			}
		}
	}
}
void CorefUtils :: insertEntityIntoSortedArray ( GrowableArray < Entity * > & sortedArray , const EntitySet * currSolution , Entity * ent , const Mention * ment , int maxEntites ) { MentionUID lastID = getLatestMention ( currSolution , ent , ment ) ; if ( lastID . isValid ( ) ) { bool inserted = false ; for ( int j = 0 ; j < sortedArray . length ( ) ; j ++ ) { if ( lastID < getLatestMention ( currSolution , sortedArray [ j ] , ment ) ) { if ( sortedArray . length ( ) == maxEntites ) { for ( int k = 0 ; k < j ; k ++ ) sortedArray [ k ] = sortedArray [ k + 1 ] ; } else { sortedArray . add ( sortedArray [ sortedArray . length ( ) - 1 ] ) ; for ( int k = sortedArray . length ( ) - 2 ; k >= j ; k -- ) sortedArray [ k + 1 ] = sortedArray [ k ] ; } sortedArray [ j ] = ent ; inserted = true ; break ; } } if ( ! inserted && ( sortedArray . length ( ) < maxEntites ) ) { sortedArray . add ( ent ) ; } if ( sortedArray . length ( ) > maxEntites ) { Entity * tmp , * nextEnt = sortedArray . removeLast ( ) ; for ( int i = sortedArray . length ( ) - 1 ; i >= 0 ; i -- ) { tmp = sortedArray [ i ] ; sortedArray [ i ] = nextEnt ; nextEnt = tmp ; } } } }
Insert an Entity into an array of entities sorted
  ascendingly w.r.t.
Insert an Entity into an array of entities sorted ascendingly w . r . t .
// find where the entity should be added
 // move the last one down one
