本文整理汇总了C#中SortedSet.GetViewBetween方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.GetViewBetween方法的具体用法?C# SortedSet.GetViewBetween怎么用?C# SortedSet.GetViewBetween使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.GetViewBetween方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpecialNumbers
//Its not clear where x is supposed to be defined, this function isn't specifically requested, don't like magic numbers
public static Tuple<double, double> GetSpecialNumbers(SortedSet<double> set, double x)
{
if (set.Count < 3)
throw new NotEnoughSetItemsException(
string.Format("GetSpecial numbers expects at least 3 items in the provided set, got {0}", set.Count));
Tuple<double, double> pair = new Tuple<double, double>(set.ToList()[2],set.GetViewBetween(set.Min, ApproximateNumberFunc(x)).Max);
return pair;
}
示例2: Main
static void Main()
{
var baseSet = new SortedSet<int> { 1, 5, 12, 20, 25 };
var view = baseSet.GetViewBetween(10, 20);
view.Add(14);
Console.WriteLine(baseSet.Count);
foreach (int value in view)
{
Console.WriteLine(value);
}
}
示例3: Main
static void Main(string[] args)
{
var letters = new SortedSet<char>("the quick brown fox");
foreach (char c in letters)
{
Console.Write(c); // bcefhiknoqrtuwx
}
foreach (char c in letters.GetViewBetween('f', 'j'))
{
Console.Write(c); // fhi
}
}
示例4: Main
static void Main()
{
var set = new SortedSet<int>(); // black-red tree
set.Add(8); // 8
set.Add(6); // 6, 8
set.Add(-3); // -3, 6, 8
set.Add(-78); // -78, -3, 6, 8
set.Add(1); // -78, -3, 1, 6, 8
set.Add(12); // -78, -3, 1, 6, 8, 12
set.ToList().ForEach(s => Console.Write(s + " "));
var subset = set.GetViewBetween(-78, 6); // O(log(n)) running time
Console.WriteLine("\nGetViewBetween(-78, 6) ->");
subset.ToList().ForEach(Console.WriteLine);
set.Remove(-3);
Console.WriteLine("Remove(-3) ->");
Console.WriteLine(string.Join(" , ", set));
//---------------------------//
Random random = new Random();
var randomSet = new SortedSet<int>();
for (int i = 0; i < 10; i++)
{
randomSet.Add(random.Next(50)); // non repeating elements
}
Console.WriteLine(string.Join(" , ", randomSet));
//--------------------------//
var startTime = DateTime.Now;
var sortedSet = new SortedSet<int>(); // tree
for (int i = 0; i < 1000000; i++)
{
sortedSet.Add(i);
}
Console.WriteLine(DateTime.Now - startTime); // logarithm
startTime = DateTime.Now;
var list = new List<int>(); // list
for (int i = 0; i < 1000000; i++)
{
list.Add(i);
//list.Insert(0, i); // very slow
}
Console.WriteLine(DateTime.Now - startTime); //constant
}
示例5: TestSubSetEnumerator
public static void TestSubSetEnumerator()
{
SortedSet<int> sortedSet = new SortedSet<int>();
for (int i = 0; i < 10000; i++)
{
if (!sortedSet.Contains(i))
sortedSet.Add(i);
}
SortedSet<int> mySubSet = sortedSet.GetViewBetween(45, 90);
Assert.Equal(46, mySubSet.Count); //"not all elements were encountered"
IEnumerable<int> en = mySubSet.Reverse();
Assert.True(mySubSet.SetEquals(en)); //"Expected to be the same set."
}
示例6: FindPrefix
/// <summary>
/// Finds <see cref="string"/> items by its prefix.
/// </summary>
/// <param name="sortedSet"><see cref="SortedSet{T}"/> of items.</param>
/// <param name="prefix">Prefix.</param>
/// <returns>An <see cref="IEnumerable{T}"/> that contains elements from the input <see cref="SortedSet{T}"/> that start with <paramref name="prefix"/>.</returns>
private static IEnumerable<string> FindPrefix(SortedSet<string> sortedSet, string prefix)
{
foreach (var word in sortedSet.GetViewBetween(prefix, sortedSet.Max))
{
if (word.StartsWith(prefix))
{
yield return word;
}
}
}
示例7: ComputeEncoding
public string ComputeEncoding(FlowMatrix flowSpec, int maxSelWidth = 6)
{
var sb = new StringBuilder();
sb.AppendLine("Control word encoding report");
sb.AppendFormat(" Number of c-steps: {0}", flowSpec.NumCSteps);
sb.AppendLine();
sb.AppendFormat(" Maximum LUT inputs: {0}", maxSelWidth);
sb.AppendLine();
FlowSpec = flowSpec;
var flowMap = new Dictionary<SignalRef, List<Flow>>();
var neutralFlow = flowSpec.NeutralFlow;
_vcf.AddFlow(neutralFlow);
for (int i = 0; i < flowSpec.NumCSteps; i++)
{
var pflow = flowSpec.GetFlow(i);
var nflow = new ParFlow(neutralFlow);
nflow.Integrate(pflow);
_vcf.AddFlow(nflow);
foreach (var flow in nflow.Flows)
{
List<Flow> flows;
if (!flowMap.TryGetValue(flow.Target, out flows))
{
flows = new List<Flow>();
flowMap[flow.Target] = flows;
}
flows.Add(flow);
}
}
_vcf.Encode();
var startTime = DateTime.Now;
var encFlows = flowMap.Values
.Select((l, i) => new EncodedFlow(l, i)).ToArray();
var uncompressedMuxBits = encFlows.Sum(ef => MathExt.CeilLog2(ef.NumSymbols));
sb.AppendFormat(" Uncompressed CW: {0} MUX bits + {1} value bits",
uncompressedMuxBits, _vcf.GetUncompressedValueWordWidth());
sb.AppendLine();
int numTargets = encFlows.Length;
var mergeCandidates = new List<Tuple<int, int, MergedFlow>>();
var indices = new SortedSet<int>(Enumerable.Range(0, numTargets));
var curGen = (EncodedFlow[])encFlows.Clone();
bool mergedAny;
var nextCandidates = new List<Tuple<int, int, MergedFlow>>();
do
{
foreach (int i in indices)
{
if (curGen[i].NumSymbols <= 1)
continue;
var upview = indices.GetViewBetween(i + 1, numTargets);
foreach (int j in upview)
{
if (curGen[j].NumSymbols <= 1)
continue;
var mergedFlow = new MergedFlow(curGen[i], curGen[j]);
mergeCandidates.Add(Tuple.Create(i, j, mergedFlow));
}
}
var orderedMergeCandidates = mergeCandidates.OrderByDescending(t => t.Item3.Score);
var nextGen = (EncodedFlow[])curGen.Clone();
var mergedIndices = new HashSet<int>();
var mergedLowIndices = new SortedSet<int>();
var mergedHiIndices = new HashSet<int>();
mergedAny = false;
foreach (var tup in orderedMergeCandidates)
{
Debug.Assert(tup.Item2 > tup.Item1);
var mergedFlow = tup.Item3;
if (mergedFlow.Score == 0.0)
break;
int selWidth = MathExt.CeilLog2(mergedFlow.NumSymbols);
if (selWidth > maxSelWidth)
continue;
if (mergedIndices.Contains(tup.Item1) ||
mergedIndices.Contains(tup.Item2))
continue;
mergedIndices.Add(tup.Item1);
mergedIndices.Add(tup.Item2);
mergedLowIndices.Add(tup.Item1);
mergedHiIndices.Add(tup.Item2);
indices.Remove(tup.Item2);
mergedFlow.Realize();
Debug.Assert(nextGen[tup.Item1].Targets.All(t => mergedFlow.Targets.Contains(t)));
Debug.Assert(nextGen[tup.Item2].Targets.All(t => mergedFlow.Targets.Contains(t)));
nextGen[tup.Item1] = mergedFlow;
mergedAny = true;
//.........这里部分代码省略.........