本文整理汇总了C#中System.Collections.SortedList.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.RemoveAt方法的具体用法?C# SortedList.RemoveAt怎么用?C# SortedList.RemoveAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalcCachedInterpolationInfo
public double[,] CalcCachedInterpolationInfo(double a_dTime, SortedList a_sorted)
{
double[,] aReturn = new double[,]{{1}};
int nIndex = 0;
// if (a_sorted.ContainsKey(a_dTime))
nIndex = a_sorted.IndexOfKey(a_dTime);
if (nIndex >= 0)
{
return new double[,]{{(double)a_sorted.GetByIndex(nIndex)}};
}
else
{
a_sorted.Add(a_dTime, -4711);
nIndex = a_sorted.IndexOfKey(a_dTime);
a_sorted.RemoveAt(nIndex);
}
//nIndex is meant to represent the next index after a_dTime.
//If a_dTime is the same as a key, nIndex should be that key's index - 1
if (nIndex <= 0)
return new double[,]{{(double)a_sorted.GetByIndex(0)}};
if (nIndex >= a_sorted.Count)
return new double[,]{{(double)a_sorted.GetByIndex(a_sorted.Count-1)}};
double dTimeAtIndexBefore = (double)a_sorted.GetKey(nIndex-1);
double dTimeAtIndexAfter = (double)a_sorted.GetKey(nIndex);
if (a_dTime == dTimeAtIndexAfter)
{
/* if (nPos < nCnt) then nPos = nPos+1
fTimePosBefore = a_paList.getPropAt(nPos-1)
fTimePosAfter = a_paList.getPropAt(nPos)*/
}
double dVal1 = 0;
double dVal2 = (double)a_sorted.GetValueList()[nIndex-1];
double dVal3 = (double)a_sorted.GetValueList()[nIndex];
double dVal4 = 0;
//TODO: support commands in the list!
//if (ilk(mvVal2) = #List) then mvVal2 = mvVal3
//if (ilk(mvVal3) = #List) then mvVal3 = mvVal2
if (nIndex == 1)
dVal1 = dVal2;
else
dVal1 = (double)a_sorted.GetValueList()[nIndex-2];
//if (ilk(mvVal1) = #List) then mvVal1 = mvVal2
if (nIndex == a_sorted.Count-1)
dVal4 = dVal3;
else
dVal4 = (double)a_sorted.GetValueList()[nIndex+1];
//TODO if (ilk(mvVal4) = #List) then mvVal4 = mvVal3
aReturn = new double[,] {{dVal1, 0}, {dVal2, dTimeAtIndexBefore}, {dVal3, dTimeAtIndexAfter}, {dVal4,0}};
return aReturn;
}
示例2: DoAddLineToSection
/// <summary>
/// Ajoute la ligne line à la section en forme clé=valeur
/// </summary>
/// <param name="section">Dictionnaire de la section</param>
/// <param name="line">Ligne de l'archive en forme "clé=valeur"</param>
protected void DoAddLineToSection( SortedList section, string line ) {
if (section == null) return ;
int pos = line.IndexOf( '=' ) ;
if (pos == -1) {
string trimmed = line.Trim() ;
if (trimmed != "") section.Add( trimmed, null ) ;
} else {
string key = line.Substring( 0, pos ) ;
string val = line.Substring( pos + 1 ) ;
int index = section.IndexOfKey( key ) ;
if (index != -1) section.RemoveAt( index ) ;
section.Add( key, val ) ;
}
}
示例3: KthSmallest
// use a max heap (priority queue) of size k
// (C# doesn't provide priority queue, use SortedList instead)
public static int KthSmallest(int[] a, int k)
{
SortedList list = new SortedList();
int m = a.Length - k + 1;
for (int i = 0; i < m; i++)
list.Add(a[i], null);
for (int i = m; i < a.Length; i++)
{
if ((int)list.GetKey(0) < a[i])
{
list.RemoveAt(0);
list.Add(a[i], null);
}
}
return (int)list.GetKey(0);
}
示例4: Arrange
//.........这里部分代码省略.........
if (childLayer <= nodeLayer)
factor += 1;
else
factor -= 1;
}
if (factor > 0)
candidates[factor] = node;
}
if (candidates.Keys.Count == 0)
continue;
found = true;
ArrayList nextLayer = null;
int ilayer = _layers.IndexOf(layer);
if (ilayer == _layers.Count - 1)
{
nextLayer = new ArrayList();
_layers.Add(nextLayer);
}
else
{
nextLayer = _layers[ilayer + 1] as ArrayList;
}
while (layer.Count > threshold)
{
if (candidates.Keys.Count == 0)
break;
GraphNode node = candidates.GetByIndex(candidates.Count - 1) as GraphNode;
candidates.RemoveAt(candidates.Count - 1);
nextLayer.Add(node);
layer.Remove(node);
node.SetData(_Layer, (int)node.GetData(_Layer) + 1);
}
}
if (found)
break;
}
}
}
// Check if there are directly related nodes on the same layer
found = true;
while (found)
{
found = false;
int ilayer = 0;
ArrayList nodesToDrop = new ArrayList();
foreach (ArrayList layer in _layers)
{
nodesToDrop.Clear();
foreach (GraphNode node in layer)
{
foreach (GraphLink link in node.OutLinks)
{
if ((int)link.Destination.GetData(_Layer) == ilayer)
{
// The node's child is on the same layer.
// Mark it for dropping
示例5: removeZeroItems
private static void removeZeroItems(ref SortedList averageValuations)
{
Dictionary<IInstrument, bool> instCol = new Dictionary<IInstrument, bool>();
foreach (AverageValuation val in averageValuations.Values)
{
if (!instCol.ContainsKey(val.Instrument))
instCol.Add(val.Instrument, val.AvgMarketValue.IsNotZero);
else if (!instCol[val.Instrument] && val.AvgMarketValue.IsNotZero)
instCol[val.Instrument] = true;
}
foreach (IInstrument key in instCol.Keys)
{
if (!instCol[key])
{
for (int i = averageValuations.Count; i > 0; i--)
{
AverageValuation val = (AverageValuation)averageValuations.GetByIndex(i);
if (val.Instrument.Equals(key))
averageValuations.RemoveAt(i);
}
}
}
}
示例6: GRCSolution
// Implementation of the GRC solution's construction algorithm.
public static int[] GRCSolution(QAPInstance instance, double rclThreshold)
{
int numFacilities = instance.NumberFacilities;
int[] assigment = new int[numFacilities];
int totalFacilities = numFacilities;
int index = 0;
double best = 0;
double cost = 0;
int facility = 0;
// Restricted Candidate List.
SortedList<double, int> rcl = new SortedList<double, int>();
// Available cities.
bool[] assigned = new bool[numFacilities];
assigment[0] = Statistics.RandomDiscreteUniform(0, numFacilities-1);
assigned[assigment[0]] = true;
index++;
numFacilities --;
while (numFacilities > 0) {
rcl = new SortedList<double, int>();
for (int i = 0; i < totalFacilities; i++) {
if (!assigned[i]) {
cost = 0;
for (int j = 0; j < index; j++) {
cost += instance.Distances[j,index] * instance.Flows[assigment[j],i];
}
if(rcl.Count == 0) {
best = cost;
rcl.Add(cost, i);
}
else if( cost < best) {
// The new assignment is the new best;
best = cost;
for (int j = rcl.Count-1; j > 0; j--) {
if (rcl.Keys[j] > rclThreshold * best) {
rcl.RemoveAt(j);
}
else {
break;
}
}
rcl.Add(cost, i);
}
else if (cost < rclThreshold * best) {
// The new assigment is a mostly good candidate.
rcl.Add(cost, i);
}
}
}
facility = rcl.Values[Statistics.RandomDiscreteUniform(0, rcl.Count-1)];
assigned[facility] = true;
assigment[index] = facility;
index++;
numFacilities--;
}
return assigment;
}
示例7: GetClosestActiveLights
internal RLIGHT[] GetClosestActiveLights(Vector3 Position)
{
BoundingSphere posSphere = new BoundingSphere(Position, 1.0f);
SortedList<float,RLIGHT> lights = new SortedList<float,RLIGHT>(32);
Hashtable distances = new Hashtable(32);
foreach (RLIGHT light in _LightList.Values)
{
float Distance = Vector3.Distance(light.Position.vector, Position);
if (light.Enabled)
{
switch (light.LightType)
{
case 0:
lights.Add(Distance, light);
break;
case 1:
if(lights.Count >= 32)
{
int i = 0;
foreach(float d in lights.Keys)
{
if(lights[d].LightType != 0)
{
if(Distance < d)
{
lights.RemoveAt(i);
break;
}
}
i++;
}
}
BoundingSphere sphere = new BoundingSphere(light.Position.vector, light.Radius);
if (sphere.Intersects(posSphere))
{
lights.Add(Distance, light);
}
break;
case 2:
lights.Add(Distance, light);
break;
default:
break;
}
}
}
lights.TrimExcess();
List<RLIGHT> l = new List<RLIGHT>(lights.Values);
return l.ToArray();
}
示例8: GRCSolution
// Implementation of the GRC solution's construction algorithm.
public static int[] GRCSolution(SPPInstance instance, double rclThreshold)
{
int numItems = instance.NumberItems;
int numSets = instance.NumberSubsets;
int[] assigment = new int[numItems];
int index = 0;
double best = 0;
double cost = 0;
int setItem = 0;
double[] setWeigths = new double[instance.NumberSubsets];
instance.SubsetsWeight.CopyTo(setWeigths, 0);
// Restricted Candidate List.
SortedList<double, int> rcl = new SortedList<double, int>();
assigment[0] = Statistics.RandomDiscreteUniform(0, numSets-1);
index++;
numItems --;
while (numItems > 0) {
rcl = new SortedList<double, int>();
for (int i = 0; i < numSets; i++) {
cost = Math.Abs(setWeigths[i] - instance.ItemsWeight[index]);
if(rcl.Count == 0) {
best = cost;
rcl.Add(cost, i);
}
else if(cost < best) {
// The new assignment is the new best;
best = cost;
for (int j = rcl.Count-1; j > 0; j--) {
if (rcl.Keys[j] > rclThreshold * best) {
rcl.RemoveAt(j);
}
else {
break;
}
}
rcl.Add(cost, i);
}
else if (cost < rclThreshold * best) {
// The new assigment is a mostly good candidate.
rcl.Add(cost, i);
}
}
setItem = rcl.Values[Statistics.RandomDiscreteUniform(0, rcl.Count-1)];
assigment[index] = setItem;
setWeigths[setItem] -= instance.ItemsWeight[index];
index++;
numItems--;
}
return assigment;
}
示例9: LeaveFunction
/* record leaving of a function */
void LeaveFunction(SortedList functions, int functionId)
{
int index = functions.IndexOfKey(functionId);
if(index != -1)
{
int newValue = (int)functions.GetByIndex(index) - 1;
if(newValue <= 0)
{
functions.RemoveAt(index);
}
else
{
functions.SetByIndex(index, newValue);
}
}
}
示例10: doRoute
internal void doRoute(bool force, Link orgnLink, Link destLink, bool nowCreating)
{
if (!force)
if (!autoRoute) return;
if (flowChart.DontRouteForAwhile)
return;
int i;
float gridSize = flowChart.RoutingOptions.GridSize;
PointF startPoint = points[0];
PointF endPoint = points[points.Count - 1];
// get a rectangle bounding both the origin and the destination
RectangleF bounds = orgnLink.getNodeRect(true);
bounds = Utilities.unionRects(bounds, destLink.getNodeRect(true));
bounds = RectangleF.Union(bounds, Utilities.normalizeRect(
RectangleF.FromLTRB(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y)));
if (bounds.Width < gridSize * 4)
bounds.Inflate(gridSize * 4, 0);
if (bounds.Height < gridSize * 4)
bounds.Inflate(0, gridSize * 4);
bounds.Inflate(bounds.Width, bounds.Height);
int oNearest = 0, dNearest = 0;
routeGetEndPoints(ref startPoint, ref endPoint,
ref oNearest, ref dNearest, orgnLink, destLink, nowCreating);
// Get the starting and ending square
Point ptStart = new Point((int)((startPoint.X - bounds.X) / gridSize),
(int)((startPoint.Y - bounds.Y) / gridSize));
Point ptEnd = new Point((int)((endPoint.X - bounds.X) / gridSize),
(int)((endPoint.Y - bounds.Y) / gridSize));
if (ptStart.X == ptEnd.X && ptStart.Y == ptEnd.Y)
return;
// init the route grid
int gridCols = (int)(bounds.Width / gridSize);
int gridRows = (int)(bounds.Height / gridSize);
RoutingGrid routingGrid = flowChart.RoutingGrid;
routingGrid.allocate(gridCols, gridRows, bounds, this);
byte[,] grid = routingGrid.getCostGrid();
PathNode[,] gridClosed = routingGrid.getClosedGrid();
PathNode[,] gridOpen = routingGrid.getOpenGrid();
bool hurry = (gridCols * gridRows > 90000) &&
flowChart.RoutingOptions.DontOptimizeLongRoutes;
RouteHeuristics calcRouteHeuristics = hurry ?
RoutingOptions.DistSquare : flowChart.RoutingOptions.RouteHeuristics;
routeFixEndRegions(grid, ref ptStart, oNearest, ref ptEnd, dNearest, gridCols, gridRows);
grid[ptStart.X, ptStart.Y] = 0;
grid[ptEnd.X, ptEnd.Y] = 0;
//---------- A* algorithm initialization -----------
SortedList open = new SortedList();
ArrayList closed = new ArrayList();
Stack stack = new Stack();
PathNode temp = new PathNode(ptStart.X, ptStart.Y);
temp.G = 0;
temp.H = calcRouteHeuristics(ptStart, ptEnd);
temp.F = temp.G + temp.H;
open.Add(temp, temp);
gridOpen[temp.X, temp.Y] = temp;
// setup A* cost function
int adjcCost = flowChart.RoutingOptions.LengthCost;
int turnCost = flowChart.RoutingOptions.TurnCost;
PathNode best = null;
bool found = false;
int iterations = 0;
for ( ; ; )
{
iterations++;
// Get the best node from the open list
if (open.Count == 0) break;
PathNode pstmp = open.GetByIndex(0) as PathNode;
open.RemoveAt(0);
gridOpen[pstmp.X, pstmp.Y] = null;
closed.Add(pstmp);
gridClosed[pstmp.X, pstmp.Y] = pstmp;
if ((best = pstmp) == null) break;
// If best == destination -> path found
if (best.X == ptEnd.X && best.Y == ptEnd.Y)
{
found = true;
break;
}
// Generate best's successors
//.........这里部分代码省略.........
示例11: TestRemoveAt
public void TestRemoveAt() {
SortedList sl1 = new SortedList(24);
int k;
string s=null;
for (int i = 0; i < 50; i++) {
s=string.Format("{0:D2}", i);
sl1.Add("kala "+s,i);
}
try {
sl1.RemoveAt(-1);
Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
} catch (ArgumentOutOfRangeException) {}
try {
sl1.RemoveAt(100);
Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
} catch (ArgumentOutOfRangeException) {}
k=sl1.Count;
for (int i=0; i<20; i++) sl1.RemoveAt(9);
AssertEquals("sl.RemoveAt: removing failed",sl1.Count,30);
for (int i=0; i<9; i++)
AssertEquals("sl.RemoveAt: removing failed(2)",sl1["kala "+string.Format("{0:D2}", i)],i);
for (int i=9; i<29; i++)
AssertEquals("sl.RemoveAt: removing failed(3)",sl1["kala "+string.Format("{0:D2}", i)],null);
for (int i=29; i<50; i++)
AssertEquals("sl.RemoveAt: removing failed(4)",sl1["kala "+string.Format("{0:D2}", i)],i);
}
示例12: UpdateCarbList
/* U P D A T E C A R B L I S T */
/*----------------------------------------------------------------------------
%%Function: UpdateCarbList
%%Qualified: bg._bg.UpdateCarbList
%%Contact: rlittle
----------------------------------------------------------------------------*/
private int UpdateCarbList(BGE bgeCur, ref SortedList slbge)
{
// retire all the items at the beginning of the list
while (slbge.Count > 0)
{
BGE bgeFirst = (BGE)slbge.GetByIndex(0);
if (bgeFirst.Date.AddHours(4.0) > bgeCur.Date)
break; // nothing left to retire
slbge.RemoveAt(0);
}
// now, if bgeCur has carbs, then add it to the list
if (bgeCur.Carbs > 0)
slbge.Add(bgeCur.Key, bgeCur);
int nCarbs = 0;
for (int i = 0, iLast = slbge.Count; i < iLast; i++)
{
BGE bge = (BGE) slbge.GetByIndex(i);
if (bge.Date != bgeCur.Date)
nCarbs += bge.Carbs;
}
return nCarbs;
}
示例13: GRCSolution
// Implementation of the GRC solution's construction algorithm.
public static int[] GRCSolution(TSPInstance instance, double rclThreshold)
{
int numCities = instance.NumberCities;
int[] path = new int[instance.NumberCities];
int totalCities = numCities;
int index = 0;
double best = 0;
double cost = 0;
int city = 0;
// Restricted Candidate List.
SortedList<double, int> rcl = new SortedList<double, int>();
// Available cities.
bool[] visited = new bool[numCities];
path[0] = Statistics.RandomDiscreteUniform(0, numCities-1);
visited[path[0]] = true;
numCities --;
while (numCities > 0) {
rcl = new SortedList<double, int>();
for (int i = 0; i < totalCities; i++) {
if (!visited[i]) {
cost = instance.Costs[path[index], i];
if(rcl.Count == 0) {
best = cost;
rcl.Add(cost, i);
}
else if( cost < best) {
// The new city is the new best;
best = cost;
for (int j = rcl.Count-1; j > 0; j--) {
if (rcl.Keys[j] > rclThreshold * best) {
rcl.RemoveAt(j);
}
else {
break;
}
}
rcl.Add(cost, i);
}
else if (cost < rclThreshold * best) {
// The new city is a mostly good candidate.
rcl.Add(cost, i);
}
}
}
city = rcl.Values[Statistics.RandomDiscreteUniform(0, rcl.Count-1)];
index++;
visited[city] = true;
path[index] = city;
numCities--;
}
return path;
}
示例14: GetUpperPowerTextureSize
public EPoint GetUpperPowerTextureSize(EPoint a_size)
{
EPoint sizeReturn = new EPoint();
SortedList aAllowedSizes = new SortedList();
int n = 4;
for (int i = 0; i < 10; i++)
{
aAllowedSizes.Add(n,i);
n*=2;
}
int nVal = a_size.X;
for (int i = 0; i < 2; i++)
{
aAllowedSizes.Add(nVal, -1);
int nIndex = aAllowedSizes.IndexOfValue(-1);
aAllowedSizes.RemoveAt(nIndex);
if (nIndex > aAllowedSizes.Count)
nIndex--;
nVal = Convert.ToInt32(aAllowedSizes.GetKey(nIndex));
if (i == 0)
sizeReturn.X = nVal;
else
sizeReturn.Y = nVal;
nVal = a_size.Y;
}
return sizeReturn;
}
示例15: findPath
//, Excluder excluder)
private List<RouteInstance> findPath(DateTime requestTime, RouteNode origin, RouteNode goal, int weight, int volume, NodeEvaluator evaluator, RouteExcluder excluder)
{
Delivery delivery = new Delivery();
delivery.Origin = origin;
delivery.Destination = goal;
delivery.WeightInGrams = weight;
delivery.VolumeInCm3 = volume;
delivery.TimeOfRequest = requestTime;
originPath = new Dictionary<RouteNode, RouteInstance>();
nodeCost = new Dictionary<RouteNode, double>();
closed = new HashSet<RouteNode>();
var rc = new RouteComparer();
fringe = new SortedList<RouteNode, double>(rc);
fringe.Add(origin, 0);
originPath.Add(origin, new OriginRouteInstance(requestTime));
//if the queue is empty return null (no path)
while (fringe.Count > 0)
{
//take new node off the top of the stack
//this is guaranteed to be the best way to the node
RouteNode curNode = fringe.Keys[0];
if (closed.Contains(curNode))
continue;
nodeCost.Add(curNode, fringe.Values[0]);
closed.Add(curNode);
fringe.RemoveAt(0);
//if it's the goal node exit and return path
if (curNode.Equals(goal))
return completeDelivery(curNode);
//grab a list of all of the routes where the given node is the origin
IEnumerable<Route> routes = routeService.GetAll(curNode);
//take each route that hasn't been ommited and evaluate
foreach (Route path in excluder.Omit(routes))
{
RouteInstance nextInstance = evaluator.GetNextInstance(path);
RouteNode nextNode = path.Destination;
double totalCost = evaluator.GetValue(nextInstance, delivery);
//if the node is not in the fringe
//or the current value is lower than
//the new cost then set the new parent
if (!fringe.ContainsKey(nextNode))
{
originPath.Add(nextNode, nextInstance);
fringe.Add(nextNode, totalCost);
}
else if (fringe[nextNode] > totalCost)
{
originPath.Remove(nextNode);
fringe.Remove(nextNode);
originPath.Add(nextNode, nextInstance);
fringe.Add(nextNode, totalCost);
}
}
}
return null;
}