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 (); } }
/// <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; }
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(); }
public CountCirc(int el) { quantity = 2; primes = new SortedSet<int>(Sift(el)); primes.Remove(2); primes.Remove(5); }
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; }
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>(); }
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"); }); }
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; }
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(); }
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)); }
/***************************** 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(); }
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; }
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(); }
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)); }
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); }
static SortedSet<int> FindPrimesBySieveOfAtkins(int max) { // var isPrime = new BitArray((int)max+1, false); // Can't use BitArray because of threading issues. var isPrime = new bool[max + 1]; var sqrt = (int)Math.Sqrt(max); Parallel.For(1, sqrt, x => { var xx = x * x; for (int y = 1; y <= sqrt; y++) { var yy = y * y; var n = 4 * xx + yy; if (n <= max && (n % 12 == 1 || n % 12 == 5)) isPrime[n] ^= true; n = 3 * xx + yy; if (n <= max && n % 12 == 7) isPrime[n] ^= true; n = 3 * xx - yy; if (x > y && n <= max && n % 12 == 11) isPrime[n] ^= true; } }); var primes = new SortedSet<int>() { 2, 3 }; for (int n = 5; n <= sqrt; n++) { if (isPrime[n]) { primes.Add(n); int nn = n * n; for (int k = nn; k <= max; k += nn) isPrime[k] = false; } } try { for (int n = sqrt + 1; n <= max; n++) if (isPrime[n]) primes.Add(n); } catch (OutOfMemoryException e) { } return primes; }
public Module(string name) { Name = Helpers.RequireName(name); Provides = new SortedSet<string>(); Requires = new SortedSet<string>(); Script = new StringBuilder(); WorkerId = Worker.Any; Provides.Add(name); if (name != InitModuleName) Requires.Add(InitModuleName); }
private void GenerarReporte(List<Cita> list_citas, DateTime desde, DateTime hasta) { int i = 0; int j = 1; int iguales = 0; this.chtGrafico.Titles.Clear(); this.chtGrafico.Legends.Clear(); this.chtGrafico.Series.Clear(); this.chtGrafico.Titles.Add(" Reportes Pacientes Atendidos - Generado el día: " + DateTime.Now + " " + System.Environment.NewLine + " " + System.Environment.NewLine + "Desde el día " + desde + " hasta el día " + hasta); ArrayList list_iguales = new ArrayList(); foreach (Cita cita in list_citas) { this.list_fechas.Add(cita.Fecha); } SortedSet<DateTime> set = new SortedSet<DateTime>(list_fechas); foreach (DateTime val in set) { iguales = 0; foreach (Cita cita in list_citas) { if (cita.Fecha == val) { ++iguales; } } list_iguales.Add(iguales); } int x = list_fechas.Count; int y = set.Count; foreach (DateTime val in set) { Series serie = new Series(); Legend legend = new Legend(); serie.Legend = val.ToString(); legend.Name = "Hora-" + val; legend.Title = "Horas de Atención"; this.chtGrafico.Legends.Add(legend); this.chtGrafico.Series.Add(val.ToString()); this.chtGrafico.Series[i].Points.AddXY(j,list_iguales[i]); this.chtGrafico.Series[i].ChartType = SeriesChartType.Bar; this.chtGrafico.Series[i]["PointWidth"] = "0.6"; this.chtGrafico.Series[i].IsValueShownAsLabel = true; this.chtGrafico.Series[i]["BarLabelStyle"] = "Center"; this.chtGrafico.Series[i]["DrawingStyle"] = "Emboss"; ++i;++j; } chtGrafico.Update(); chtGrafico.UpdateAnnotations(); MessageBox.Show("Registro total de pacientes atendidos: " + list_citas.Count + "." + " " + System.Environment.NewLine + " " + System.Environment.NewLine + "Desde el día " + desde + " hasta el día " + hasta, "SFH Administración de Reportes y Estadísticas - Reportes de Pacientes", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void GenerarReporte(List<Cita> list_citas) { this.chtGrafico.Titles.Add(" Reportes Pacientes " + DateTime.Now); //this.chtGrafico.ChartAreas[0].Area3DStyle.Enable3D = true; int i = 0; int j = 1; foreach (Cita cita in list_citas){ this.list_fechas.Add(cita.Fecha.ToString()); } int[] pointsArray = { Convert.ToInt32(1), Convert.ToInt32(3), Convert.ToInt32(1) }; SortedSet<string> set = new SortedSet<string>(list_fechas); int x = list_fechas.Count; int y = set.Count; // this.chtGrafico.Series[0].Points.AddXY(x, y); foreach (string val in set) { Series serie = new Series(); Legend legend = new Legend(); serie.Legend = val; legend.Name = "Hora-" + val; legend.Title = "Horas de atencion"; this.chtGrafico.Legends.Add(legend); serie = this.chtGrafico.Series.Add(val); //serie.Points.Add(pointsArray[i]); serie.Points.AddXY(j,pointsArray[i]); //this.chtGrafico.Series.Add(serie); //this.chtGrafico.Series[i].Points.AddXY(x, y); /* Series series = this.chtGrafico.Series.Add(val); series.Points.Add(pointsArray[i]); ++i;*/ // this.chtGrafico.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Range; ++i; ++j; chtGrafico.Update(); } }
public void should_be_simplified_using_for_each() { var collection = new SortedSet<int> { 10, 2, 3, 5 }; var copyOfCollection = new List<int>(); foreach (int valueInCollection in collection) { copyOfCollection.Add(valueInCollection); } // change the variable value to fix the test. var expectedCopyResult = new List<int> { 10, 2, 3, 5 }; Assert.Equal(expectedCopyResult, copyOfCollection); }
public static void Run() { //INFO: коллекции практически идентичны по скорости при получении сортированного множества (TestTwo) // SortedDictionary быстрее для look up operation (TestOne) var sortedDictionary = new SortedDictionary<int, User>(); var sortedSet = new SortedSet<User>(); var testSizesForTestOne = new int[] { 100, 1000, 10000, 50000, 100000 }; var testSizesForTestTwo = new int[] { 10, 50, 100, 500, 1000, 5000 }; RunTest(sortedDictionary, sortedSet, testSizesForTestOne, "TestOne", (set, testSize) => RunTestOneSortedDict(set, testSize), (set, testSize) => RunTestOneSortedSet(set, testSize)); RunTest(sortedDictionary, sortedSet, testSizesForTestTwo, "TestTwo", (set, testSize) => RunTestTwoSortedDict(set, testSize), (set, testSize) => RunTestTwoSortedSet(set, testSize)); }
private void GenerarReporte(List<Cita> list_citas) { //this.chtGrafico.Legends.Clear(); this.chtGrafico.Titles.Add(" Reportes Pacientes " + DateTime.Now); this.chtGrafico.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Range; chtGrafico.Palette = ChartColorPalette.SeaGreen; // this.chtGrafico.ChartAreas[0].Area3DStyle.Enable3D = true; int i = 0; foreach (Cita cita in list_citas){ this.list_fechas.Add(cita.Fecha.ToString()); } // Arreglos del Grafico //string[] seriesArray = { "Categoria 1", "Categoria 2", "Categoria 3" }; int[] pointsArray = { Convert.ToInt32(1), Convert.ToInt32(2), Convert.ToInt32(1) }; SortedSet<string> set = new SortedSet<string>(list_fechas); int x = list_fechas.Count; int y = set.Count; this.chtGrafico.Series[0].Points.AddXY(x,y); foreach (string val in set) { Series series = this.chtGrafico.Series.Add(val); series.Points.Add(pointsArray[i]); ++i; //chtGrafico.Update(); } //this.chtGrafico.Legends.RemoveAt(0); chtGrafico.Update(); // Se modifica la Paleta de Colores a utilizar por el control. // this.chart1.Palette = ChartColorPalette.SeaGreen; // Se agrega un titulo al Grafico. // Agregar las Series al Grafico. /*for (int i = 0; i < seriesArray.Length; i++) { // Aqui se agregan las series o Categorias. // Series series = this.chtGrafico.Series.Add(seriesArray[i]); // Aqui se agregan los Valores. } */ }
private static void RunTest(SortedDictionary<int, User> sortedDict, SortedSet<User> sortedSet, IEnumerable<int> testSizes, string label, Func<SortedDictionary<int, User>, int, TimeSpan> testFuncSoretdDict, Func<SortedSet<User>, int, TimeSpan> testFuncSortedSet) { foreach (int test in testSizes) { var result = testFuncSoretdDict(sortedDict, test); Console.WriteLine("{0} with Sorted Dictionary ({1}): {2}", label, test, result); result = testFuncSortedSet(sortedSet, test); Console.WriteLine("{0} with Sorted Set ({1}): {2}", label, test, result); sortedDict.Clear(); sortedSet.Clear(); Console.WriteLine(); } }
public void OrderedCaseInsensitiveEnumeration() { ArrayList expectedOrder = new ArrayList(3); expectedOrder.Add("ONE"); expectedOrder.Add("two"); expectedOrder.Add("tHree"); SortedSet theSet = new SortedSet(expectedOrder, new CaseInsensitiveComparer()); expectedOrder.Sort(new CaseInsensitiveComparer()); int index = 0; foreach (object obj in theSet) { Assert.AreEqual(obj, expectedOrder[index], index.ToString() + " did not have same value"); index++; } }
private static SortedSet<string> GetArtists() { SortedSet<string> artists = new SortedSet<string>(); XmlDocument catalogueDocument = new XmlDocument(); catalogueDocument.Load(XmlCatalogueFilePath); XmlNode catalogueNode = catalogueDocument.DocumentElement; foreach (XmlNode album in catalogueNode.ChildNodes) { var xmlElement = album[@"artist"]; if (xmlElement != null) { string artist = xmlElement.InnerText; artists.Add(artist); } } return artists; }
static void DFS(ref string[,] honeyGrid, ref HashSet<string> Dict, ref HashSet<string> prefix, ref SortedSet<string> Found, int levels) { try { int x = 2 * levels - 1; for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { if (honeyGrid[i, j] != null) { SearchForWords(ref honeyGrid, ref Dict, ref prefix, ref Found, levels, i, j); //calling for all possible non null positions as start position } } } } catch (Exception) { throw; } }
public void OrderedCaseInsensitiveEnumeration() { ArrayList expectedOrder = new ArrayList(3); expectedOrder.Add("ONE"); expectedOrder.Add("two"); expectedOrder.Add("tHree"); SortedSet<string> theSet = new SortedSet<string>(StringComparer.CurrentCultureIgnoreCase); foreach (string str in expectedOrder) theSet.Add(str); expectedOrder.Sort(StringComparer.CurrentCultureIgnoreCase); int index = 0; foreach (string str in theSet) { Assert.AreEqual(str, expectedOrder[index], index.ToString() + " did not have same value"); index++; } }
private void GenerarReporte(List<Cita> list_citas) { int i = 0; int j = 1; int iguales = 0; this.chtGrafico.Titles.Add(" Reportes Pacientes " + DateTime.Now); ArrayList list_iguales = new ArrayList(); //this.chtGrafico.ChartAreas[0].Area3DStyle.Enable3D = true; //this.chtGrafico.ChartAreas[0].AxisX.LabelStyle.Format = DateTime; foreach (Cita cita in list_citas){ this.list_fechas.Add(cita.Fecha); } SortedSet<DateTime> set = new SortedSet<DateTime>(list_fechas); foreach (DateTime val in set) { iguales = 0; foreach (Cita cita in list_citas) { if (cita.Fecha == val) { ++iguales; } } list_iguales.Add(iguales); } int x = list_fechas.Count; int y = set.Count; foreach (DateTime val in set) { Series serie = new Series(); Legend legend = new Legend(); serie.Legend = val.ToString(); legend.Name = "Hora-" + val; legend.Title = "Horas de atencion"; this.chtGrafico.Legends.Add(legend); serie = this.chtGrafico.Series.Add(val.ToString()); serie.Points.AddXY(j, list_iguales[i]); ++i; ++j; } chtGrafico.Update(); }
private static SortedSet<string> BackTrack(string s1, string s2, int i, int j, int[,] matrix) { if (i == 0 || j == 0) { return new SortedSet<string>() { "" }; } else if (s1[i - 1] == s2[j - 1]) { SortedSet<string> temp = new SortedSet<string>(); SortedSet<string> holder = BackTrack(s1, s2, i - 1, j - 1, matrix); foreach (string str in holder) { temp.Add(str + s1[i - 1]); } return temp; } else { SortedSet<string> Result = new SortedSet<string>(); if (matrix[i - 1, j] >= matrix[i, j - 1]) { SortedSet<string> holder = BackTrack(s1, s2, i - 1, j, matrix); foreach (string s in holder) { Result.Add(s); } } if (matrix[i, j - 1] >= matrix[i - 1, j]) { SortedSet<string> holder = BackTrack(s1, s2, i, j - 1, matrix); foreach (string s in holder) { Result.Add(s); } } return Result; } }
/// <summary> /// Tests whether a <see cref="Geometry" /> is sequenced correctly. /// <see cref="LineString" />s are trivially sequenced. /// <see cref="MultiLineString" />s are checked for correct sequencing. /// Otherwise, <c>IsSequenced</c> is defined /// to be <c>true</c> for geometries that are not lineal. /// </summary> /// <param name="geom">The <see cref="Geometry" /> to test.</param> /// <returns> /// <c>true</c> if the <see cref="Geometry" /> is sequenced or is not lineal. /// </returns> public static bool IsSequenced(IGeometry geom) { if (!(geom is IMultiLineString)) return true; IMultiLineString mls = geom as IMultiLineString; // The nodes in all subgraphs which have been completely scanned ISet<ICoordinate> prevSubgraphNodes = new SortedSet<ICoordinate>(); ICoordinate lastNode = null; IList<ICoordinate> currNodes = new List<ICoordinate>(); for (int i = 0; i < mls.NumGeometries; i++) { ILineString line = (ILineString) mls.GetGeometryN(i); ICoordinate startNode = line.GetCoordinateN(0); ICoordinate endNode = line.GetCoordinateN(line.NumPoints - 1); /* * If this linestring is connected to a previous subgraph, geom is not sequenced */ if (prevSubgraphNodes.Contains(startNode)) return false; if (prevSubgraphNodes.Contains(endNode)) return false; if (lastNode != null && startNode != lastNode) { // start new connected sequence prevSubgraphNodes.AddAll(currNodes); currNodes.Clear(); } currNodes.Add(startNode); currNodes.Add(endNode); lastNode = endNode; } return true; }