static int discoverTrianglesSingleCore(BTreeMap <int, int[]> edges) { int triangles = 0; BTreeMapIterator <int, int[]> edgesItr = edges.Iterator(); while (edgesItr.MoveNext()) { int nodeId = edgesItr.CurrentKey(); int[] edge = edgesItr.CurrentValue(); int stop = edge.Length - 1; int i = stop; int edgeToStart, edgeTo; int pos; while (i >= 0) { int[] edgeInfo2; edgeToStart = edge[i--]; if (nodeId < edgeToStart) { if (edges.TryGetValue(edgeToStart, out edgeInfo2)) { for (int j = stop; j >= i; j--) { edgeTo = edge[j]; if (edgeToStart < edgeTo) { pos = Array.BinarySearch <int>(edgeInfo2, edgeTo); if (pos >= 0) { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To triangles++; } } else { break; } } } } else { break; } } } return(triangles); }
public static HashSet <Person> SearchGeoHashIndex(string bootDirectory, double minLat, double minLon, double maxLat, double maxLon) { HashSet <Person> resultSet = new HashSet <Person>(); if (minLat > maxLat) { double t = minLat; minLat = maxLat; maxLat = t; } if (minLon > maxLon) { double t = minLon; minLon = maxLon; maxLon = t; } WGS84Point min = new WGS84Point(minLat, minLon); WGS84Point max = new WGS84Point(maxLat, maxLon); BoundingBox bbox = new BoundingBox(min, max); GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox); using (SessionNoServer session = new SessionNoServer(bootDirectory)) { session.BeginRead(); BTreeMap <Int64, VelocityDbList <Person> > btreeMap = session.AllObjects <BTreeMap <Int64, VelocityDbList <Person> > >().FirstOrDefault(); foreach (GeoHash hash in query.SearchHashes) { BTreeMapIterator <Int64, VelocityDbList <Person> > itr = btreeMap.Iterator(); itr.GoTo(hash.LongValue); var current = itr.Current(); while (current.Value != null) { GeoHash geoHash = GeoHash.FromLongValue(current.Key); if (geoHash.Within(hash) || (geoHash.SignificantBits > hash.SignificantBits && hash.Within(geoHash))) { foreach (Person person in current.Value) { resultSet.Add(person); } current = itr.Next(); } else { break; } } } // actual geohash bounding box may be including some that are not within requested bounding box so remove such items if any HashSet <Person> notWithin = new HashSet <Person>(); foreach (Person person in resultSet) { if (person.Lattitude < min.Latitude || person.Lattitude > max.Latitude || person.Longitude < min.Longitude || person.Lattitude > max.Latitude) { notWithin.Add(person); } } foreach (Person person in notWithin) { resultSet.Remove(person); } foreach (Person person in resultSet) { Console.WriteLine(person.ToString() + " Lattitude: " + person.Lattitude + " Longitude: " + person.Longitude); } session.Commit(); } return(resultSet); }