Tanis.Collections.Heap.LimitOccurrences C# (CSharp) Method

LimitOccurrences() public method

Limits the number of occurrences of a specified value. Same values are equals according to the Equals() method of objects in the list. The first occurrences encountered are kept.
public LimitOccurrences ( object Value, int NumberToKeep ) : void
Value object Value whose occurrences number must be limited.
NumberToKeep int Number of occurrences to keep
return void
		public void LimitOccurrences(object Value, int NumberToKeep)
		{
			if(Value == null) 
				throw new ArgumentNullException("Value");
			int Pos = 0;
			while((Pos = IndexOf(Value, Pos)) >= 0)
			{
				if(NumberToKeep <= 0)
					FList.RemoveAt(Pos);
				else
				{
					Pos++; 
					NumberToKeep--; 
				}
				if(FComparer.Compare(FList[Pos],Value) > 0 ) 
					break; 
			}
		}