本文整理汇总了C#中System.Collections.SortedSet类的典型用法代码示例。如果您正苦于以下问题:C# SortedSet类的具体用法?C# SortedSet怎么用?C# SortedSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortedSet类属于System.Collections命名空间,在下文中一共展示了SortedSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
var students
= new SortedDictionary<string, SortedSet<Student>>();
var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
var file = new StreamReader (projectDir + Path.DirectorySeparatorChar + "students.txt");
string line;
while(null != (line = file.ReadLine()))
{
var record = line.Split ('|').Select(p => p.Trim()).ToList();
if( !students.ContainsKey(record[2] )) {
students[record[2]] = new SortedSet<Student>();
}
students [record [2]].Add(new Student (record[0], record[1], record[2]));
}
foreach (var course in students) {
Console.Write ("{0}: ", course.Key);
var i = 0;
foreach (var student in course.Value) {
Console.Write (student);
if (i < course.Value.Count-1) {
Console.Write (", ");
}
i++;
}
Console.WriteLine ();
}
}
示例2: CreateNamesDictionary
/// <summary>
/// Creates dictionaries that maps from types full names to
/// a suitable collection name. The resulting name is usually
/// simple the name of the type. When there is more than
/// one type with the same name, FullName is progressively
/// perpended to name until there is no ambiguity.
/// Two dictionaries are generated, one with pluralized last name
/// and one with singular one.
/// </summary>
/// <param name="pPersistables">Types to be translated.</param>
/// <param name="pSchema">Schema to add names dictionaries.</param>
private static void CreateNamesDictionary(Type[] pPersistables, ref SchemaInfo pSchema)
{
Dictionary<string, string> lPlural;
SortedSet<string> lSingular = new SortedSet<string>();
// Initially maps FullName to Name.
lPlural = pPersistables.ToDictionary(lPersistable => lPersistable.ToGenericTypeString(), lPersistable => lPersistable.Name + "s");
foreach (Type type in pPersistables)
lSingular.Add(type.ToGenericTypeString());
// Solve name clashes.
pPersistables
.ToLookup(lPersistable => lPersistable.Name)
.Where(lGroup => lGroup.Count() > 1)
.Select(lGroup => SolveNameClash(lGroup))
.ToList()
.ForEach(delegate(Dictionary<string, string[]> lSub)
{
foreach (KeyValuePair<string, string[]> lPair in lSub)
{
// Singular names just join names.
// lSingular[lPair.Key] = String.Join("_", lPair.Value);
// Last name gets pluralized for plural names.
lPair.Value[lPair.Value.Count() - 1] = lPair.Value.Last() + "s";
lPlural[lPair.Key] = String.Join("_", lPair.Value);
}
});
pSchema.SingularNames = lSingular;
pSchema.TypesNameToPluralName = lPlural;
}
示例3: Main
static void Main(string[] args)
{
long[] primes = ESieve(7071);
long[][] powers = new long[3][];
int target = 50000000;
List<long> templist = new List<long>(primes);
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < primes.Length; i++)
{
templist[i] *= primes[i];
}
powers[j] = templist.ToArray();
}
SortedSet<long> numbers = new SortedSet<long>();
for (int i = 0; i < primes.Length; i++)
{
for (int j = 0; j < primes.Length; j++)
{
for (int k = 0; k < primes.Length; k++)
{
long number = powers[0][i] + powers[1][j] + powers[2][k];
if (number > target) break;
numbers.Add(number);
}
}
}
Console.Write(numbers.Count);
Console.WriteLine();
}
示例4: CountCirc
public CountCirc(int el)
{
quantity = 2;
primes = new SortedSet<int>(Sift(el));
primes.Remove(2);
primes.Remove(5);
}
示例5: ReadSourceFiles
public static ISet<string> ReadSourceFiles(string pdbPath)
{
var clsid = new Guid("3BFCEA48-620F-4B6B-81F7-B9AF75454C7D");
var type = Type.GetTypeFromCLSID(clsid);
var source = (DiaSource)Activator.CreateInstance(type);
source.loadDataFromPdb(pdbPath);
IDiaSession session;
source.openSession(out session);
IDiaEnumTables enumTables;
session.getEnumTables(out enumTables);
var result = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (IDiaTable diaEnumTable in enumTables)
{
var sourceFiles = diaEnumTable as IDiaEnumSourceFiles;
if (sourceFiles == null)
continue;
foreach (IDiaSourceFile sourceFile in sourceFiles)
result.Add(sourceFile.fileName);
}
return result;
}
示例6: Supermarket
public Supermarket()
{
this.productsByType = new Dictionary<string, SortedSet<Product>>();
this.productNames = new HashSet<string>();
this.productsByPrice = new SortedDictionary<double, SortedSet<Product>>();
this.allPrices = new SortedSet<double>();
}
示例7: SortedSetTests
static SortedSetTests()
{
QUnit.module("SortedSet tests");
QUnit.test("new SortedSet fails with null compare", delegate
{
QUnit.raises(delegate { new SortedSet(null, new Array(), true); }, "should throw an exception");
});
QUnit.test("new SortedSet succeeds with null array (sorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, new Array(), true);
QUnit.equals(s.Count, 0, "count should be zero");
});
QUnit.test("new SortedSet succeeds with null array (unsorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, new Array(), true);
QUnit.equals(s.Count, 0, "count should be zero");
});
QUnit.test("new SortedSet succeeds (empty, sorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, new Array(), true);
QUnit.equals(s.Count, 0, "count should be zero");
});
QUnit.test("new SortedSet succeeds (empty, not sorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, new Array(), false);
QUnit.equals(s.Count, 0, "count should be zero");
});
QUnit.test("new SortedSet succeeds (non empty, sorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, TestSortedArray, true);
QUnit.equals(s.Count, TestSortedArray.Length, "count should be zero");
});
QUnit.test("new SortedSet succeeds (not empty, unsorted)", delegate
{
SortedSet s = new SortedSet(CompareNumber, TestUnsortedArray, false);
QUnit.equals(s.Count, TestUnsortedArray.Length, "count should be zero");
});
QUnit.test("SortedSet.GetItems succeeds", delegate
{
SortedSet s = new SortedSet(CompareNumber, TestUnsortedArray, false);
QUnit.equals(s.IndexOf(0), 0, "should find 0");
QUnit.equals(s.IndexOf(1), 1, "should find 1");
QUnit.equals(s.IndexOf(2), 2, "should find 2");
QUnit.equals(s.IndexOf(3), 3, "should find 3");
QUnit.equals(s.IndexOf(4), 4, "should find 4");
QUnit.equals(s.IndexOf(5), 5, "should find 5");
QUnit.equals(s.IndexOf(6), -1, "should not find 6");
});
}
示例8: FindDuplicateFiles
public ScanResult FindDuplicateFiles(String dirPath)
{
worker.ReportProgress(0, "Preparing files ...");
FileInfo[] files = new DirectoryInfo(dirPath).GetFiles("*", SearchOption.AllDirectories);
Array.Sort(files, Comparer<FileInfo>.Create((a,b) => b.FullName.CompareTo(a.FullName)));
int total = files.Length;
double progress = 0;
IDictionary<long, IDictionary<FileInfo, IList<FileInfo>>> byteTable = new Dictionary<long, IDictionary<FileInfo, IList<FileInfo>>>();
foreach (FileInfo file in files) {
worker.ReportProgress((int)(++progress/total*100), String.Format("Scanning files... ({0}/{1})", progress, total));
// Compare size
long fileSize = file.Length;
if (!byteTable.ContainsKey(fileSize))
byteTable.Add(fileSize, new Dictionary<FileInfo, IList<FileInfo>>());
// Compare contents of the files with the same size
IDictionary<FileInfo, IList<FileInfo>> fileTable = byteTable[fileSize]; // All files in fileMap have the same size
bool foundDuplicate = false;
// Compare the current file to each file in fileTable
foreach (KeyValuePair<FileInfo, IList<FileInfo>> pair in fileTable) {
// If find a duplicate, add the file to the duplicate-files-list and break the iteration
if (FilesAreEqual(pair.Key, file)) {
foundDuplicate = true;
pair.Value.Add(file);
break;
}
}
// No duplicate found, create a new entry in fileTable
if (!foundDuplicate)
fileTable.Add(file, new List<FileInfo>());
}
// Build the result
worker.ReportProgress(100, "Build the result ...");
ScanResult result = new ScanResult();
int sum = 0;
foreach (IDictionary<FileInfo, IList<FileInfo>> fileTable in byteTable.Values) {
foreach (KeyValuePair<FileInfo, IList<FileInfo>> pair in fileTable) {
if (pair.Value.Count > 0) {
ISet<FileInfo> list = new SortedSet<FileInfo>(Comparer<FileInfo>.Create((a, b) => b.FullName.CompareTo(a.FullName)));
list.Add(pair.Key);
result.RemoveList.Add(pair.Key, false);
foreach (FileInfo file in pair.Value) {
list.Add(file);
result.RemoveList.Add(file, true);
}
result.FileList.Add(pair.Key, list);
sum += pair.Value.Count;
}
}
}
result.NumDuplicates = sum;
return result;
}
示例9: Main
static void Main(string[] args)
{
var stackOfValues = new Stack<string>();
GetInitialValuesFromArgs(args, ref stackOfValues);
var demoSet1 = new Set<string>(stackOfValues.ToArray());
Console.WriteLine(demoSet1.ToString());
var demoSet3 = new SortedSet(stackOfValues.ToArray());
Console.WriteLine(demoSet3.ToString());
Console.ReadKey();
}
示例10: Add
public void Add ()
{
var set = new SortedSet<int> ();
Assert.AreEqual (0, set.Count);
Assert.IsTrue (set.Add (2));
Assert.IsTrue (set.Add (4));
Assert.IsTrue (set.Add (3));
Assert.AreEqual (3, set.Count);
Assert.IsFalse (set.Add (2));
}
示例11: DataSet
/***************************** Constructor *********************************/
public DataSet()
{
egoLikedTweets = new HashSet<long>();
egoLikedTweetsInTimeline = new HashSet<long>();
egoUnLikedTweetsInTimeline = new HashSet<long>();
timeline = new SortedSet<long>(new TweetIDComparer());
egoLikedTweets.Clear();
egoLikedTweetsInTimeline.Clear();
egoUnLikedTweetsInTimeline.Clear();
timeline.Clear();
}
示例12: Simulation
private ConcurrentQueue<Cell[]> updated; // Cells updated since last checked by client
#endregion Fields
#region Constructors
/// <summary>
/// Initialize a new simulation with a blank grid (with all cells in the default state) of the default size.
/// </summary>
public Simulation()
{
toCheck = new SortedSet<CPoint>(new PointComparer());
toUpdate = new ConcurrentQueue<Cell>();
updated = new ConcurrentQueue<Cell[]>();
grid = new uint[1][];
ca = new CA();
initGridBlank(defaultX, defaultY);
refresh = defaultRefresh;
throttled = false;
}
示例13: DataSctructure
public DataSctructure()
{
this.dictionary = new Dictionary<int, string>();
this.hashSet = new HashSet<int>();
this.sortedList = new SortedList<int, string>();
this.sortedSet = new SortedSet<int>();
this.list = new List<int>();
this.linkedList = new LinkedList<int>();
this.pair = new KeyValuePair<int, string>();
fillTheStructures();
}
示例14: Remove
public void Remove ()
{
var set = new SortedSet<int> ();
Assert.IsTrue (set.Add (2));
Assert.IsTrue (set.Add (4));
Assert.AreEqual (2, set.Count);
Assert.IsTrue (set.Remove (4));
Assert.IsTrue (set.Remove (2));
Assert.AreEqual (0, set.Count);
Assert.IsFalse (set.Remove (4));
Assert.IsFalse (set.Remove (2));
}
示例15: InitData
public void InitData()
{
int[] temp = new int[length];
for (int i = 0; i < length; i++)
{
int n = i + 1;
int triangleNumberForN = n * (n + 1) / 2;
temp[i] = triangleNumberForN;
}
triangleNumbers = new SortedSet<int>(temp);
}