本文整理汇总了C#中SortedSet.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Remove方法的具体用法?C# SortedSet.Remove怎么用?C# SortedSet.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public static Stack<Square> Search(Map map, Square source, Square target, Func<Square, Square, int> heuristic)
{
Dictionary<Square, Square> parents = new Dictionary<Square, Square>();
HashSet<Square> closed = new HashSet<Square>();
SortedSet<Square> open = new SortedSet<Square>();
source.Score.Cost = 0;
source.Score.Estimate = heuristic(source, target);
open.Add(source);
while (open.Count > 0)
{
// Get node with lowest f(x) score
Square current = open.First();
if (current == target)
break;
// Transfer node to closed set
open.Remove(current);
closed.Add(current);
// Examine neighbors
foreach (Square neighbor in map.GetNeighbors(current))
{
// Check if node is already processed or not passable
if (closed.Contains(neighbor) || (neighbor != target && !neighbor.IsPassable))
continue;
// Tentative g score
float g = current.Score.Cost + 1;
// Add (new) node to open
if (!open.Contains(neighbor))
{
parents[neighbor] = current;
neighbor.Score.Cost = g;
neighbor.Score.Estimate = heuristic(neighbor, target);
open.Add(neighbor);
}
// Updating existing node in open
else if (g < neighbor.Score.Cost)
{
open.Remove(neighbor);
parents[neighbor] = current;
neighbor.Score.Cost = g;
open.Add(neighbor);
}
}
}
return ReconstructPath(parents, target);
}
示例2: find
public int find(int[] array, int k)
{
if (array == null || array.Length == 0) return -1;
SortedSet<int> queue = new SortedSet<int>();
int maxItem = array[0];
queue.Add(array[0]);
foreach (int v in array)
{
if (queue.Count < k)
queue.Add(v);
// can enqueue
else if (v < queue.Max)
{
queue.Remove(queue.Max);
queue.Add(v);
}
}
int res = -1;
foreach (var v in queue) {
if (--k == 0) {
res = v;
break;
}
}
return res;
}
示例3: Main
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
SortedSet<long> numberCollection = new SortedSet<long>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++)
{
long currentNumber = long.Parse(Console.ReadLine());
if (!numberCollection.Contains(currentNumber))
{
numberCollection.Add(currentNumber);
}
else
{
numberCollection.Remove(currentNumber);
}
if (numberCollection.Count == 0)
{
sb.AppendLine("There are no numbers");
}
else if (numberCollection.Count == 1)
{
sb.AppendLine("There is only one number");
}
else
{
long minDifference = CalculateMinDifference(numberCollection);
sb.AppendLine(minDifference.ToString());
}
}
Console.Write(sb.ToString());
}
示例4: AprioriGen
//产生候选集:使用《数据挖掘导论》上P210页的方法
static List<SortedSet<string>> AprioriGen(List<SortedSet<string>> kFequentSet)
{
List<SortedSet<string>> result = new List<SortedSet<string>>();
for (int i = 0; i < kFequentSet.Count; i++)
{
SortedSet<string> aTmpSet = new SortedSet<string>(kFequentSet[i]);
string aLastElement = kFequentSet[i].Last<string>();
aTmpSet.Remove(aLastElement);//去掉最后一个元素
for (int j = i + 1; j < kFequentSet.Count; j++)
{
SortedSet<string> bTmpSet = new SortedSet<string>(kFequentSet[j]);
string bLastElement = kFequentSet[j].Last<string>();
bTmpSet.Remove(bLastElement);//去掉最后一个元素
if (bTmpSet.Count == aTmpSet.Count)
{
bTmpSet.ExceptWith(aTmpSet);
if (bTmpSet.Count == 0 && !aLastElement.Equals(bLastElement))//前k-2个元素相同而最后一个元素不同
{
result.Add(new SortedSet<string>(kFequentSet[i]));
result[result.Count - 1].Add(bLastElement);
}
}
}
}
return result;
}
示例5: FindMinimumSpanningTree
private static void FindMinimumSpanningTree(bool[] used, SortedSet<Edge> priority, List<Edge> mpdNodes, List<Edge> edges)
{
while (priority.Count > 0)
{
var edge = priority.Min;
priority.Remove(edge);
if (!used[edge.EndNode])
{
used[edge.EndNode] = true;
mpdNodes.Add(edge);
for (int i = 0; i < edges.Count; i++)
{
if (!mpdNodes.Contains(edges[i]))
{
if (edge.EndNode == edges[i].StartNode && !used[edges[i].EndNode])
{
priority.Add(edges[i]);
}
}
}
}
}
}
示例6: Load
/// <summary>
/// FanIn
/// </summary>
public IEnumerable<Activity> Load(Feed feed)
{
var snapshot = new Dictionary<byte[], Queue<Activity>>(activityStreamStore.Count);
foreach (var item in activityStreamStore)
{
snapshot.Add(item.Key, new Queue<Activity>(item.Value));
}
SortedSet<Activity> buffer = new SortedSet<Activity>(Activity.Comparer);
var streams = feed.FeedStreams.ToList();
var streamsCount = streams.Count;
// Init
for (int streamIndexInsideSubsciption = 0; streamIndexInsideSubsciption < streamsCount; streamIndexInsideSubsciption++)
{
var streamId = streams[streamIndexInsideSubsciption];
var activity = snapshot[streamId].Dequeue();
buffer.Add(activity);
}
while (buffer.Count > 0)
{
Activity nextActivity = buffer.FirstOrDefault();
buffer.Remove(nextActivity);
var streamQueue = snapshot[nextActivity.StreamId];
if (streamQueue.Count > 0)
{
var candidate = snapshot[nextActivity.StreamId].Dequeue();
buffer.Add(candidate);
}
yield return nextActivity;
}
}
示例7: Load
/// <summary>
/// FanIn
/// </summary>
public IEnumerable<Activity> Load(ActivityStream stream, ActivityStreamOptions feedOptions)
{
// At this point we have all the streams with their timestamp
Dictionary<byte[], long> streamsToLoad = new StreamCrawler(streamStore).StreamsToLoad(stream, feedOptions.Paging.Timestamp);
Dictionary<string, DateTime> debug = streamsToLoad.ToDictionary(key => Encoding.UTF8.GetString(key.Key), val => DateTime.FromFileTimeUtc(val.Value));
feedOptions = feedOptions ?? ActivityStreamOptions.Default;
var snapshot = GetSnapshot(streamsToLoad, feedOptions);
SortedSet<Activity> buffer = new SortedSet<Activity>(Activity.ComparerDesc);
// Init
foreach (var str in streamsToLoad)
{
var streamId = str.Key;
FetchNextActivity(snapshot, streamId, buffer);
}
while (buffer.Count > 0)
{
Activity nextActivity = buffer.First();
buffer.Remove(nextActivity);
yield return nextActivity;
FetchNextActivity(snapshot, nextActivity.StreamId, buffer);
}
}
示例8: FindLongestPath
private int FindLongestPath(int maxSalary, int startSalary)
{
IDictionary<int, int> longestPaths = new Dictionary<int, int>() { { startSalary, 1 }};
SortedSet<int> salaries = new SortedSet<int>();
salaries.Add(startSalary);
while (salaries.Count != 0)
{
int salary = salaries.Min;
int path = longestPaths[salary];
foreach (int nextSalary in GetNextSalaries(maxSalary, salary))
{
if (!salaries.Contains(nextSalary))
{
salaries.Add(nextSalary);
longestPaths.Add(nextSalary, path + 1);
}
else
if (longestPaths[nextSalary] < path + 1)
longestPaths[nextSalary] = path + 1;
}
salaries.Remove(salary);
}
return longestPaths.Values.Max();
}
示例9: FindMinimumSpanningTree
public void FindMinimumSpanningTree()
{
SortedSet<EdgeWeighted> priority = new SortedSet<EdgeWeighted>();
bool[] usedEdges = new bool[this.n + 1];
List<EdgeWeighted> mpdEdges = new List<EdgeWeighted>();
// adding edges that connect the node 1 with all the others - 2, 3, 4 ...
foreach (EdgeWeighted edge in this.edges)
{
if (edge.StartNode == this.edges[0].StartNode)
{
priority.Add(edge);
}
}
usedEdges[this.edges[0].StartNode] = true;
while (priority.Count > 0)
{
EdgeWeighted edge = priority.Min;
priority.Remove(edge);
if (!usedEdges[edge.EndNode])
{
usedEdges[edge.EndNode] = true; // we "visit" this node
mpdEdges.Add(edge);
this.AddEdges(edge, this.edges, mpdEdges, priority, usedEdges);
}
}
this.PrintMinimumSpanningTree(mpdEdges);
}
示例10: Main
static void Main()
{
int n = int.Parse(Console.ReadLine());
var noIncommingEdges = new SortedSet<char>();
for (int i = 0; i < n; i++)
{
string currentMessage = Console.ReadLine();
Node previousNode = GetNodeByCharFromGraph(currentMessage[0]);
for (int j = 1; j < currentMessage.Length; j++)
{
Node currentNode = GetNodeByCharFromGraph(currentMessage[j]);
previousNode.Successors.Add(currentNode);
currentNode.Parents.Add(previousNode);
previousNode = currentNode;
}
}
foreach (var node in graph.Values)
{
if (node.Parents.Count == 0)
{
noIncommingEdges.Add(node.Value);
}
}
var result = new List<char>();
while (noIncommingEdges.Count > 0)
{
var currentNodeSymbol = noIncommingEdges.Min;
noIncommingEdges.Remove(currentNodeSymbol);
result.Add(currentNodeSymbol);
var currentNode = graph[currentNodeSymbol];
var children = currentNode.Successors.ToList();
foreach (var child in children)
{
child.Parents.Remove(currentNode);
currentNode.Successors.Remove(child);
if (child.Parents.Count == 0)
{
noIncommingEdges.Add(child.Value);
}
}
}
Console.WriteLine(String.Join("", result));
}
示例11: HandleConversionGivesCorrectKind
public void HandleConversionGivesCorrectKind()
{
var expectedKinds = new SortedSet<HandleKind>((HandleKind[])Enum.GetValues(typeof(HandleKind)));
Action<Handle, HandleKind> assert = (handle, expectedKind) =>
{
Assert.False(expectedKinds.Count == 0, "Repeat handle in tests below.");
Assert.Equal(expectedKind, handle.Kind);
expectedKinds.Remove(expectedKind);
};
assert(default(ModuleDefinitionHandle), HandleKind.ModuleDefinition);
assert(default(AssemblyDefinitionHandle), HandleKind.AssemblyDefinition);
assert(default(InterfaceImplementationHandle), HandleKind.InterfaceImplementation);
assert(default(MethodDefinitionHandle), HandleKind.MethodDefinition);
assert(default(MethodSpecificationHandle), HandleKind.MethodSpecification);
assert(default(TypeDefinitionHandle), HandleKind.TypeDefinition);
assert(default(ExportedTypeHandle), HandleKind.ExportedType);
assert(default(TypeReferenceHandle), HandleKind.TypeReference);
assert(default(TypeSpecificationHandle), HandleKind.TypeSpecification);
assert(default(MemberReferenceHandle), HandleKind.MemberReference);
assert(default(FieldDefinitionHandle), HandleKind.FieldDefinition);
assert(default(EventDefinitionHandle), HandleKind.EventDefinition);
assert(default(PropertyDefinitionHandle), HandleKind.PropertyDefinition);
assert(default(StandaloneSignatureHandle), HandleKind.StandaloneSignature);
assert(default(MemberReferenceHandle), HandleKind.MemberReference);
assert(default(FieldDefinitionHandle), HandleKind.FieldDefinition);
assert(default(EventDefinitionHandle), HandleKind.EventDefinition);
assert(default(PropertyDefinitionHandle), HandleKind.PropertyDefinition);
assert(default(ParameterHandle), HandleKind.Parameter);
assert(default(GenericParameterHandle), HandleKind.GenericParameter);
assert(default(GenericParameterConstraintHandle), HandleKind.GenericParameterConstraint);
assert(default(ModuleReferenceHandle), HandleKind.ModuleReference);
assert(default(CustomAttributeHandle), HandleKind.CustomAttribute);
assert(default(DeclarativeSecurityAttributeHandle), HandleKind.DeclarativeSecurityAttribute);
assert(default(ManifestResourceHandle), HandleKind.ManifestResource);
assert(default(ConstantHandle), HandleKind.Constant);
assert(default(ManifestResourceHandle), HandleKind.ManifestResource);
assert(default(MethodImplementationHandle), HandleKind.MethodImplementation);
assert(default(AssemblyFileHandle), HandleKind.AssemblyFile);
assert(default(StringHandle), HandleKind.String);
assert(default(AssemblyReferenceHandle), HandleKind.AssemblyReference);
assert(default(UserStringHandle), HandleKind.UserString);
assert(default(GuidHandle), HandleKind.Guid);
assert(default(BlobHandle), HandleKind.Blob);
assert(default(NamespaceDefinitionHandle), HandleKind.NamespaceDefinition);
assert(default(DocumentHandle), HandleKind.Document);
assert(default(MethodDebugInformationHandle), HandleKind.MethodDebugInformation);
assert(default(LocalScopeHandle), HandleKind.LocalScope);
assert(default(LocalConstantHandle), HandleKind.LocalConstant);
assert(default(LocalVariableHandle), HandleKind.LocalVariable);
assert(default(ImportScopeHandle), HandleKind.ImportScope);
assert(default(CustomDebugInformationHandle), HandleKind.CustomDebugInformation);
Assert.True(expectedKinds.Count == 0, "Some handles are missing from this test: " + string.Join("," + Environment.NewLine, expectedKinds));
}
示例12: Apply
public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
var len = parents[0].Length;
var child = new LinearLinkage(len);
var remaining = new SortedSet<int>(Enumerable.Range(0, len));
do {
var groups = parents.Select(x => x.GetGroupForward(remaining.Min).Where(y => remaining.Contains(y)).ToList()).ToList();
var max = groups.Select((v, idx) => Tuple.Create(idx, v.Count)).MaxItems(x => x.Item2).SampleRandom(random).Item1;
var i = groups[max][0];
for (var k = 1; k < groups[max].Count; k++) {
child[i] = groups[max][k];
remaining.Remove(i);
i = child[i];
}
child[i] = i;
remaining.Remove(i);
} while (remaining.Count > 0);
return child;
}
示例13: Select
public static Tuple<Chromosome, Chromosome> Select(IList<Chromosome> population, Random random, out Chromosome worst)
{
SortedSet<Chromosome> tournament = new SortedSet<Chromosome>();
DiscreteUniformDistribution discrete = new DiscreteUniformDistribution(0, population.Count - 1);
while (tournament.Count < K)
{
int index = discrete.GetRandomValue(random);
tournament.Add(population[index]);
}
worst = tournament.Max;
tournament.Remove(worst);
double sumFitness;
CalculateFitness(tournament, out sumFitness);
Chromosome parent1 = SelectParent(tournament, sumFitness, random);
tournament.Remove(parent1);
CalculateFitness(tournament, out sumFitness);
Chromosome parent2 = SelectParent(tournament, sumFitness, random);
return new Tuple<Chromosome, Chromosome>(parent1, parent2);
}
示例14: CalculateDominatesSet
public static SortedSet<IRBlock> CalculateDominatesSet(IRGraph cfg, SortedSet<IRBlock> V, SortedSet<IRBlock> VSansR, IRBlock v)
{
SortedSet<IRBlock> VSansv = new SortedSet<IRBlock>();
VSansv.UnionWith(V);
VSansv.Remove(v); // V - {v}
SortedSet<IRBlock> S = FindReachableBlocks(cfg, v.GetIndex());
VSansv.ExceptWith(S);
return VSansv; // V - {v} - S
}
示例15: Apply
public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
var len = parents[0].Length;
var p = random.Next(parents.Length);
var child = new LinearLinkage(len);
var remaining = new SortedSet<int>(Enumerable.Range(0, len));
do {
var i = remaining.Min;
foreach (var g in parents[p].GetGroupForward(i)) {
if (!remaining.Contains(g)) continue;
child[i] = g;
i = g;
remaining.Remove(g);
}
child[i] = i;
remaining.Remove(i);
p = (p + 1) % parents.Length;
} while (remaining.Count > 0);
return child;
}