本文整理汇总了C#中SortedSet.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.ToArray方法的具体用法?C# SortedSet.ToArray怎么用?C# SortedSet.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveDuplicate
private static void RemoveDuplicate(HeaderDetail_v1<Handeco_Header, Handeco_Detail> headerDetail)
{
// company.detail.raisonSociale company.header.name
if (headerDetail.Header.Name.Equals(headerDetail.Detail.RaisonSociale, StringComparison.InvariantCultureIgnoreCase))
headerDetail.Header.Name = null;
SortedSet<string> detailGroupes = new SortedSet<string>(headerDetail.Detail.Groupes);
headerDetail.Detail.Groupes = detailGroupes.ToArray();
List<string> headerGroupes = new List<string>();
foreach (string groupe in headerDetail.Header.Groupes)
{
if (!detailGroupes.Contains(groupe))
headerGroupes.Add(groupe);
}
headerDetail.Header.Groupes = headerGroupes.ToArray();
// company.header.activités company.detail.activités.type
SortedSet<string> detailActivités = new SortedSet<string>(from activité in headerDetail.Detail.Activités select activité.Type);
List<string> headerActivités = new List<string>();
foreach (string activité in headerDetail.Header.Activités)
{
if (!detailActivités.Contains(activité))
headerActivités.Add(activité);
}
headerDetail.Header.Activités = headerActivités.ToArray();
}
示例2: RemoveDuplicate
public static void RemoveDuplicate(Handeco_Company company)
{
// company.detail.raisonSociale company.header.name
if (company.header.name.Equals(company.detail.raisonSociale, StringComparison.InvariantCultureIgnoreCase))
company.header.name = null;
List<string> groupes = new List<string>();
// company.detail.adhésionGroupement company.header.groupes
//string detailGroupe = company.detail.adhésionGroupement;
SortedSet<string> detailGroupes = new SortedSet<string>(company.detail.groupes);
company.detail.groupes = detailGroupes.ToArray();
foreach (string groupe in company.header.groupes)
{
//if (!groupe.Equals(detailGroupe, StringComparison.InvariantCultureIgnoreCase))
if (!detailGroupes.Contains(groupe))
groupes.Add(groupe);
}
company.header.groupes = groupes.ToArray();
// company.header.activités company.detail.activités.type
//company.header.activités
//SortedList<string, string> headerActivités = new SortedList<string, string>();
//SortedSet<string> headerActivités = new SortedSet<string>(company.header.activités);
SortedSet<string> detailActivités = new SortedSet<string>(from activité in company.detail.activités select activité.type);
List<string> headerActivités = new List<string>();
foreach (string activité in company.header.activités)
{
if (!detailActivités.Contains(activité))
headerActivités.Add(activité);
}
company.header.activités = headerActivités.ToArray();
}
示例3: WordCooccurrenceMatrix
public WordCooccurrenceMatrix(SortedSet<string> words)
{
_lookupTable = words.ToArray();
//Create a square (n x n) matrix with the same rows and columns.
_n = _lookupTable.Length;
//_matrix = new SparseMatrix<int>(_n, _n);
_matrix = new RowOrientedSparseMatrix<int>(_n, _n);
}
示例4: Update
public void Update(List<List<Point3D>> pointListList)
{
SortedSet<double> sortedSet = new SortedSet<double>();
pointListList.ForEach(pointList => pointList.ForEach(point => sortedSet.Add(point.X)));
this.xs = sortedSet.ToArray();
this.xEdges = new double[this.xs.Length][][];
List<double[]>[] xEdgeList = new List<double[]>[this.xs.Length];
for (int i = 0; i < xEdgeList.Length; ++i)
{
xEdgeList[i] = new List<double[]>();
}
foreach (List<Point3D> pointList in pointListList)
{
List<int> indexList = new List<int>(pointList.Count);
for (int j = 0; j < pointList.Count; ++j)
{
indexList.Add(Array.BinarySearch(this.xs, pointList[j].X) - 1);
}
for (int i = pointList.Count - 1, j = 0; j < pointList.Count; i = j, ++j)
{
if (pointList[i].X == pointList[j].X)
{
continue;
}
int iMin = pointList[i].X < pointList[j].X ? i : j;
int iMax = i + j - iMin;
double x1 = pointList[iMin].X;
double y1 = pointList[iMin].Y;
double x2 = pointList[iMax].X;
double y2 = pointList[iMax].Y;
double slope = (y2 - y1) / (x2 - x1);
int xIndex1 = indexList[iMin];
int xIndex2 = indexList[iMax];
for (int xIndex = xIndex1 + 1; xIndex <= xIndex2; ++xIndex)
{
xEdgeList[xIndex].Add(new double[2] { y1 + (this.xs[xIndex] - x1) * slope, slope });
}
}
}
for (int xIndex = 0; xIndex < xEdgeList.Length; ++xIndex)
{
xEdgeList[xIndex].Sort((t1, t2) => Math.Sign(t1[0] == t2[0] ? t1[1] - t2[1] : t1[0] - t2[0]));
this.xEdges[xIndex] = xEdgeList[xIndex].ToArray();
}
}
示例5: FindSets
public static Tuple<int, int, int>[] FindSets(params int[] cards)
{
if (cards.Length < 3) return new Tuple<int, int, int>[0];
List<Tuple<int, int, int>> result = new List<Tuple<int, int, int>>();
for (int i = 0; i < cards.Length; i++)
{
for (int j = i + 1; j < cards.Length; j++)
{
int completion = SetHelper.CompleteSet(cards[i], cards[j]);
if (cards.Contains(completion))
{
SortedSet<int> sorter = new SortedSet<int>();
sorter.Add(cards[i]);
sorter.Add(cards[j]);
sorter.Add(completion);
Tuple<int, int, int> set = new Tuple<int, int, int>(sorter.ToArray()[0], sorter.ToArray()[1], sorter.ToArray()[2]);
if (!result.Contains(set))
result.Add(set);
}
}
}
return result.ToArray();
}
示例6: GetRequiredBlockHeights
/// <summary>
/// Determines which block hashes are required to build a locator for the given height.
/// </summary>
/// <param name="targetHeight">The height of the last block that should be described by the locator.</param>
/// <returns>An array of block heights that are required to build a locator for the given height.</returns>
public static int[] GetRequiredBlockHeights(int targetHeight)
{
SortedSet<int> heights = new SortedSet<int>();
for (int groupIndex = 0; groupIndex < GroupCount; groupIndex++)
{
int groupDivisor = GroupDivisors[groupIndex];
int height = targetHeight - targetHeight%groupDivisor;
for (int i = 0; i < ItemsPerGroup && height >= 0; i++, height -= groupDivisor)
{
heights.Add(height);
}
}
return heights.ToArray();
}
示例7: Solve
// nektery podminky by asi mely byt rozumnejsi
public long Solve()
{
var hammingNumbers = GetHammingNumbers().OrderBy(t => t);
var hammingPrimes = GetHammingPrimes(hammingNumbers).OrderBy(t => t).ToArray();
var results = new SortedSet<long> { 1 };
// tohle je pomaly - dobra rekurze by byla rychlejsi
foreach (var hammingPrime in hammingPrimes)
{
Console.WriteLine("{0} {1}", hammingPrime, results.Count);
var count = 0;
foreach (var result in results.ToArray())
{
count++;
var power = result * hammingPrime;
if (power > Limit)
{
Console.WriteLine("{0} {1}", count, result);
break;
}
results.Add(power);
}
}
var sum = 0L;
foreach (var hammingNumber in hammingNumbers)
{
foreach (var result in results)
{
var current = hammingNumber * result;
if (current > Limit)
{
break;
}
sum = (sum + current) % modulo;
}
}
return sum;
}
示例8: testSingle
public void testSingle()
{
Random random = new Random((int)DateTime.Now.Ticks);
SortedSet<int> list = new SortedSet<int>();
SortedSet<int> list2 = new SortedSet<int>();
for (int i = 0; i < random.Next(50); i++)
{
int temp = random.Next(1000);
if (!list.Contains(temp))
list.Add(temp);
}
for (int i = 0; i < random.Next(50); i++)
{
int temp = random.Next(1000);
if (!list2.Contains(temp))
list2.Add(temp);
}
int median = find(list.ToArray(), list2.ToArray());
int lessThan = 0;
int moreThan = 0;
foreach (var v in list)
{
if (v <= median) lessThan++;
else moreThan++;
}
foreach (var v in list2)
{
if (v <= median) lessThan++;
else moreThan++;
}
AssertHelper.assert(lessThan == moreThan || Math.Abs(lessThan - moreThan) == 1, "Less and More should have the same count.");
}
示例9: DynamicDocIdSetIterator
public DynamicDocIdSetIterator(SortedSet<int> docIds)
{
_docIds = docIds.ToArray();
}
示例10: GetTools
private IList<string> GetTools()
{
string cacheKey;
var projectItems = GetProjectItems(out cacheKey);
string[] toolsArray = MemoryCache.Default.Get(cacheKey) as string[];
if (toolsArray == null)
{
SortedSet<string> tools = new SortedSet<string>();
foreach (var item in projectItems)
tools.Add(item.CustomTool);
toolsArray = tools.ToArray();
MemoryCache.Default.Add(cacheKey.ToString(), toolsArray, m_cachePolicy);
}
return toolsArray;
}
示例11: ExecuteBuild
public override void ExecuteBuild()
{
LogConsole("************************* BuildCommonTools");
// Get the list of platform names
string[] PlatformNames = ParseParamValue("platforms", BuildHostPlatform.Current.Platform.ToString()).Split('+');
// Parse the platforms
List<UnrealBuildTool.UnrealTargetPlatform> Platforms = new List<UnrealTargetPlatform>();
foreach(string PlatformName in PlatformNames)
{
UnrealBuildTool.UnrealTargetPlatform Platform;
if(!UnrealBuildTool.UnrealTargetPlatform.TryParse(PlatformName, true, out Platform))
{
throw new AutomationException("Unknown platform specified on command line - '{0}' - valid platforms are {1}", PlatformName, String.Join("/", Enum.GetNames(typeof(UnrealBuildTool.UnrealTargetPlatform))));
}
Platforms.Add(Platform);
}
// Add all the platforms if specified
if(ParseParam("allplatforms"))
{
foreach(UnrealTargetPlatform Platform in Enum.GetValues(typeof(UnrealTargetPlatform)))
{
if(!Platforms.Contains(Platform))
{
Platforms.Add(Platform);
}
}
}
// Get the agenda
List<string> ExtraBuildProducts = new List<string>();
UE4Build.BuildAgenda Agenda = MakeAgenda(Platforms.ToArray(), ExtraBuildProducts);
// Build everything. We don't want to touch version files for GitHub builds -- these are "programmer builds" and won't have a canonical build version
UE4Build Builder = new UE4Build(this);
Builder.Build(Agenda, InDeleteBuildProducts:true, InUpdateVersionFiles: false);
// Add UAT and UBT to the build products
Builder.AddUATFilesToBuildProducts();
Builder.AddUBTFilesToBuildProducts();
// Add all the extra build products
foreach(string ExtraBuildProduct in ExtraBuildProducts)
{
Builder.AddBuildProduct(ExtraBuildProduct);
}
// Make sure all the build products exist
UE4Build.CheckBuildProducts(Builder.BuildProductFiles);
// Write the manifest if needed
string ManifestPath = ParseParamValue("manifest");
if(ManifestPath != null)
{
SortedSet<string> Files = new SortedSet<string>();
foreach(string BuildProductFile in Builder.BuildProductFiles)
{
Files.Add(BuildProductFile);
}
File.WriteAllLines(ManifestPath, Files.ToArray());
}
}
示例12: GetLines
// Formatting code to display this measure and the notes it contains
public string[] GetLines()
{
if (_lines != null)
return _lines;
_lines = new string[TabFile.LineCount];
for (int i = 0; i < TabFile.LineCount; i++)
_lines[i] = "";
// Group the event time of all entities together in order to calculate
// their position in the measure relative to their event time
SortedSet<float> events = new SortedSet<float>();
events.Add(Start);
events.Add(End);
events.UnionWith(Notes.Keys);
events.UnionWith(Beats.Keys);
// The slots array holds the positions of the individual entities
// in the measure
int[] slots = Common.GetSlots(events.ToArray(), 0.05f);
bool[] slotIsNote = new bool[slots.Length];
int t = 0;
foreach (float time in events)
slotIsNote[t++] = Notes.ContainsKey(time);
// Now get the notes' and chords' text strings to be added to the measure
// and calculate the width of one slot in order to create a monospaced measure
List<string[]> noteStrings = new List<string[]>();
int maxNoteLength = 0;
foreach (TabLinesEntity n in Notes.Values)
{
string[] l = n.GetLines();
noteStrings.Add(l);
if (l[0].Length > maxNoteLength)
maxNoteLength = l[0].Length;
}
int slotLength = maxNoteLength + 1;
// The slot length calculation algorithm might have returned high slot values
// causing overly an long tab measure => "compress" the slot distribution
while (slots[slots.Length - 1] * slotLength > TabFile.LINE_WRAP)
{
int[] nextSlots = new int[slots.Length];
bool last = false;
for (int i = 0; i < slots.Length; i++)
{
nextSlots[i] = slots[i] / 2;
// Stop if 2 notes/chords would occupy the same position on the next compression step
if (i != 0 && slotIsNote[i] && slotIsNote[i - 1] && nextSlots[i] == nextSlots[i - 1])
{
last = true; // "break out of for loop"
break;
}
}
if (last)
break;
slots = nextSlots;
}
// Now create the measure's tab representation
int s = 0;
foreach (float time in events)
{
// Check if the current event actually is a note and not a beat
if (!Notes.ContainsKey(time))
{
s++;
continue;
}
TabLinesEntity tle = Notes[time];
int slot = slots[s];
// calculate the position of the current note/chord in the measure
// +1 because the first column should always be empty for readability's sake
int index = slot * slotLength + 1;
// First fill the measure with empty measure data up to the current position
FillLines(index);
// Now append the note/chord to the measure
string[] l = tle.GetLines();
for (int j = 0; j < TabFile.LineCount; j++)
{
char padding = (j < TabFile.FIRST_STRING ? TabFile.PADDING_INFO : TabFile.PADDING_STRING);
_lines[j] += l[j].PadLeft(slotLength, padding);
}
s++;
}
// Fill the measure till the end
int lastSlot = slots[events.Count - 1];
int measureLength = lastSlot * slotLength;
FillLines(measureLength);
//.........这里部分代码省略.........
示例13: ClusterColorSpace
//Cluster the final clusters into color space
public void ClusterColorSpace()
{
double maxDist = 20*20;
int minRegions = 5;
SortedSet<int> activeClusterIds = new SortedSet<int>(rootIds);
String logFile = "colorlog.txt";
StreamWriter log = File.AppendText(logFile);
log.WriteLine("\n\tCluster ColorSpace Run " + DateTime.Now.ToString());
log.Flush();
//the smaller id comes first in the dictionary for pairwise distances
PriorityQueue<Tuple<int, int>, double> pq = new PriorityQueue<Tuple<int, int>, double>();
int counter = activeClusterIds.Last()+1;
int[] ids = activeClusterIds.ToArray<int>();
//Calculate the initial distances
for (int i = 0; i < ids.Count(); i++)
{
for (int j = i+1; j < ids.Count(); j++)
{
//log.WriteLine(ids[i] + ", " + ids[j] + " dist " + -1 * clusters[ids[i]].lab.SqDist(clusters[ids[j]].lab));
//log.Flush();
//pq.Enqueue(new Tuple<int, int>(ids[i], ids[j]), -1 * clusters[ids[i]].lab.SqDist(clusters[ids[j]].lab));
PixelCluster a = clusters[ids[i]];
PixelCluster b = clusters[ids[j]];
double newDist = a.lab.SqDist(b.lab);
//Add in Ward's variance (variation in Color Segmentation using Region Merging)
//http://www.mathworks.com/help/toolbox/stats/linkage.html
//newDist = newDist * Math.Sqrt(2 * a.count * b.count / (a.count + b.count));
pq.Enqueue(new Tuple<int, int>(ids[i], ids[j]), -1 * newDist);
}
}
Stopwatch timer = new Stopwatch();
timer.Start();
while (activeClusterIds.Count > minRegions)
{
//Find the pair with the smallest distance
KeyValuePair<Tuple<int, int>, double> result = BestPair(pq, activeClusterIds);
Tuple<int, int> pair = result.Key;
double bestDist = -1 * result.Value;
Console.WriteLine("num clusters: " + activeClusterIds.Count());
if (bestDist > maxDist)
break;
PixelCluster a = clusters[pair.Item1];
PixelCluster b = clusters[pair.Item2];
//Create a new cluster with unique id, we don't care about the neighbors
PixelCluster merged = new PixelCluster();
merged.id = counter++;
merged.lab = (a.lab * a.count + b.lab * b.count) / (a.count + b.count);
merged.count = a.count + b.count;
merged.children = new int[] { a.id, b.id };
merged.parentId = merged.id;
a.parentId = merged.id;
b.parentId = merged.id;
clusters.Add(merged.id, merged);
//Update the active cluster set
activeClusterIds.Remove(a.id);
activeClusterIds.Remove(b.id);
activeClusterIds.Add(merged.id);
double totalCount = a.count + b.count;
//Update the distances, based on old distances
foreach (int i in activeClusterIds)
{
if (i == merged.id)
continue;
//TODO: Ward's method with minimum variance
//For now, just use the dist between the centroids
PixelCluster c = clusters[i];
double newDist = merged.lab.SqDist(c.lab);
//Add in Ward's variance (variation in Color Segmentation using Region Merging)
//http://www.mathworks.com/help/toolbox/stats/linkage.html
//newDist = newDist * Math.Sqrt(2*a.count * b.count / (a.count + b.count));
if (c.id < merged.id)
pq.Enqueue(new Tuple<int, int>(c.id, merged.id), -1 * newDist);
else
pq.Enqueue(new Tuple<int, int>(merged.id, c.id), -1 * newDist);
}
//.........这里部分代码省略.........
示例14: GetScheduledArrivals
public static async Task<RealtimeArrival[]> GetScheduledArrivals(string stopId)
{
DateTime minTime = DateTime.Now - TimeSpan.FromMinutes(5);
DateTime maxTime = DateTime.Now + TimeSpan.FromMinutes(45);
ServiceDay day = DateTime.Now.GetServiceDay();
var weekSched = await LoadSchedule(stopId);
if (weekSched == null)
return null;
var daySched = weekSched[day];
SortedSet<RealtimeArrival> result = new SortedSet<RealtimeArrival>(Comparer<RealtimeArrival>.Create((sa1, sa2) => sa1.ScheduledArrivalTime < sa2.ScheduledArrivalTime ? -1 : sa1.ScheduledArrivalTime > sa2.ScheduledArrivalTime ? 1 : 0));
string curRouteId = null;
string curRouteName = "";
if (daySched == null || daySched.IsEmpty)
return result.ToArray();
foreach (var item in daySched)
{
if (curRouteId != item.Route)
{
curRouteId = item.Route;
await AccessRouteCache(delegate (List<Tuple<BusRoute, string[], string[]>> routes)
{
curRouteName = routes.First(rte => rte.Item1.ID == item.Route).Item1.Name;
return false;
});
}
if (item.ScheduledDepartureTime >= minTime && item.ScheduledDepartureTime < maxTime)
result.Add(new RealtimeArrival() { Route = item.Route, RouteName = curRouteName, Destination = item.Destination, LastUpdateTime = DateTime.Now, PredictedArrivalTime = null, ScheduledArrivalTime = item.ScheduledDepartureTime, Stop = item.Stop, Trip = item.Trip });
}
return result.ToArray();
}
示例15: GetValidMoves
public ICollection<string> GetValidMoves(int ruleId)
{
var rule = GetRuleById(ruleId);
var moves = new SortedSet<string>();
var doc = new XmlDocument();
doc.LoadXml(rule.RuleDefinition);
foreach (XmlNode child in doc.FirstChild)
{
moves.Add(child.Name);
}
return moves.ToArray();
}