public void HugeDictionary_LargeScale() { const int count = 10000000; HugeDictionary <int, int> dictionary; dictionary = new HugeDictionary <int, int>(100); for (int i = 0; i < count; i++) { dictionary.Add(i, -i); } Assert.AreEqual(count, dictionary.Count); for (int i = 0; i < count; i++) { Assert.AreEqual(-i, dictionary[i]); } for (int i = 0; i < count; i++) { dictionary.Remove(i); } Assert.AreEqual(0, dictionary.Count); }
public void HugeDictionary_Basic() { HugeDictionary <string, int> dictionary; int value; dictionary = new HugeDictionary <string, int>(10); Assert.AreEqual(0, dictionary.Count); Assert.IsFalse(dictionary.ContainsKey("0")); Assert.IsFalse(dictionary.ContainsKey("1")); Assert.IsFalse(dictionary.TryGetValue("0", out value)); Assert.AreEqual(0, value); Assert.IsFalse(dictionary.TryGetValue("1", out value)); Assert.AreEqual(0, value); dictionary.Add("0", 0); Assert.AreEqual(1, dictionary.Count); Assert.AreEqual(0, dictionary["0"]); Assert.IsTrue(dictionary.ContainsKey("0")); Assert.IsFalse(dictionary.ContainsKey("1")); Assert.IsTrue(dictionary.TryGetValue("0", out value)); Assert.AreEqual(0, value); Assert.IsFalse(dictionary.TryGetValue("1", out value)); Assert.AreEqual(0, value); dictionary.Add("1", 1); Assert.AreEqual(2, dictionary.Count); Assert.AreEqual(0, dictionary["0"]); Assert.AreEqual(1, dictionary["1"]); Assert.IsTrue(dictionary.ContainsKey("0")); Assert.IsTrue(dictionary.ContainsKey("1")); Assert.IsTrue(dictionary.TryGetValue("0", out value)); Assert.AreEqual(0, value); Assert.IsTrue(dictionary.TryGetValue("1", out value)); Assert.AreEqual(1, value); dictionary.Remove("0"); Assert.AreEqual(1, dictionary.Count); Assert.AreEqual(1, dictionary["1"]); Assert.IsFalse(dictionary.ContainsKey("0")); Assert.IsTrue(dictionary.ContainsKey("1")); Assert.IsFalse(dictionary.TryGetValue("0", out value)); Assert.AreEqual(0, value); Assert.IsTrue(dictionary.TryGetValue("1", out value)); Assert.AreEqual(1, value); dictionary.Clear(); Assert.AreEqual(0, dictionary.Count); Assert.IsFalse(dictionary.ContainsKey("0")); Assert.IsFalse(dictionary.ContainsKey("1")); }
/// <summary> /// Creates a new mapped attributes index. /// </summary> public MappedAttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex | AttributesIndexMode.ReverseStringIndex) { _data = new MemoryArray <uint>(1024); _attributes = new AttributesIndex(mode); _reverseIndex = new HugeDictionary <uint, int>(); for (var p = 0; p < _data.Length; p++) { _data[p] = _NO_DATA; } }
/// <summary> /// Makes this index writable again, once made writeable it will use more memory and be less efficient, use optimize again once the data is updated. /// </summary> public void MakeWriteable() { _reverseIndex = new HugeDictionary <uint, int>(); for (var p = 0; p < _data.Length; p += 2) { if (_data[p + 0] == _NO_DATA) { continue; } _reverseIndex[_data[p + 0]] = p + 0; } }
public void TestHugeDictionaryEnumeration() { // create the huge dictionary. var hugeDictionary = new HugeDictionary <long, long>(100); for (long idx = 0; idx < 1000; idx++) { hugeDictionary.Add(idx, idx); } var items = new List <KeyValuePair <long, long> >( hugeDictionary); Assert.AreEqual(hugeDictionary.Count, items.Count); }
public void HugeDictionary_Capacity() { HugeDictionary <string, int> dictionary; int value; dictionary = new HugeDictionary <string, int>(10, 5000); Assert.AreEqual(0, dictionary.Count); Assert.IsFalse(dictionary.ContainsKey("0")); Assert.IsFalse(dictionary.ContainsKey("1")); Assert.IsFalse(dictionary.TryGetValue("0", out value)); Assert.AreEqual(0, value); Assert.IsFalse(dictionary.TryGetValue("1", out value)); Assert.AreEqual(0, value); }
/// <summary> /// Creates a new hierarchy builder. /// </summary> public FastHierarchyBuilder(DirectedMetaGraph graph, WeightHandler <T> weightHandler) { weightHandler.CheckCanUse(graph); _graph = graph; _weightHandler = weightHandler; _vertexInfo = new VertexInfo <T>(); _depth = new HugeDictionary <long, int>(); _contractionCount = new HugeDictionary <uint, int>(); this.DifferenceFactor = 4; this.DepthFactor = 14; this.ContractedFactor = 1; }
public void HugeDictionary_KeyComparer() { HugeDictionary <string, int> dictionary; dictionary = new HugeDictionary <string, int>(10, StringComparer.OrdinalIgnoreCase); Assert.AreEqual(0, dictionary.Count); Assert.IsFalse(dictionary.ContainsKey("one")); Assert.IsFalse(dictionary.ContainsKey("two")); dictionary.Add("one", 0); Assert.AreEqual(1, dictionary.Count); Assert.AreEqual(0, dictionary["one"]); Assert.AreEqual(0, dictionary["ONE"]); Assert.IsTrue(dictionary.ContainsKey("one")); Assert.IsTrue(dictionary.ContainsKey("One")); }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="collectIntermediates"></param> protected DynamicGraphOsmStreamWriter( IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations, bool collectIntermediates) { _dynamicGraph = dynamicGraph; _interpreter = interpreter; _edgeComparer = edgeComparer; _tagsIndex = tagsIndex; _idTransformations = idTransformations; _preIndexMode = true; _preIndex = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _relevantNodes = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _collectIntermediates = collectIntermediates; _dataCache = new OsmDataCacheMemory(); }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="graph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="collectIntermediates"></param> /// <param name="coordinates"></param> protected GraphOsmStreamTargetBase( RouterDataSourceBase <TEdgeData> graph, IOsmRoutingInterpreter interpreter, ITagsIndex tagsIndex, HugeDictionary <long, uint> idTransformations, bool collectIntermediates, ICoordinateIndex coordinates) { _graph = graph; _interpreter = interpreter; _tagsIndex = tagsIndex; _idTransformations = idTransformations; _preIndexMode = true; _preIndex = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _relevantNodes = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _restricedWays = new HashSet <long>(); _collapsedNodes = new Dictionary <long, KeyValuePair <KeyValuePair <long, uint>, KeyValuePair <long, uint> > >(); _collectIntermediates = collectIntermediates; _dataCache = new OsmDataCacheMemory(); _coordinates = coordinates; }
public void TestHugeDictionary() { // create the huge dictionary. var hugeDictionary = new HugeDictionary<long, long>(); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Add(idx, idx); } Assert.AreEqual(10000, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Remove(idx); } Assert.AreEqual(0, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); hugeDictionary = new HugeDictionary<long, long>(); for (long idx = 0; idx < 10000000; idx++) { hugeDictionary.Add(idx, idx); } Assert.AreEqual(10000000, hugeDictionary.Count); Assert.AreEqual(10, hugeDictionary.CountDictionaries); for (long idx = 0; idx < 10000000; idx++) { hugeDictionary.Remove(idx); } Assert.AreEqual(0, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); }
public void TestHugeDictionary() { // create the huge dictionary. var hugeDictionary = new HugeDictionary <long, long>(); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Add(idx, idx); } Assert.AreEqual(10000, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Remove(idx); } Assert.AreEqual(0, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); hugeDictionary = new HugeDictionary <long, long>(1000); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Add(idx, idx); } Assert.AreEqual(10000, hugeDictionary.Count); Assert.AreEqual(10, hugeDictionary.CountDictionaries); for (long idx = 0; idx < 10000; idx++) { hugeDictionary.Remove(idx); } Assert.AreEqual(0, hugeDictionary.Count); Assert.AreEqual(1, hugeDictionary.CountDictionaries); }
public void TestKeyAndValueCollections() { var dic = new HugeDictionary <int, string>(5); dic.Add(1, "1"); dic.Add(2, "2"); dic.Add(3, "3"); dic.Add(4, "4"); dic.Add(5, "5"); dic.Add(6, "6"); dic.Add(7, "7"); var keys = dic.Keys; Assert.IsNotNull(keys); Assert.IsTrue(keys.IsReadOnly); Assert.AreEqual(7, keys.Count); Assert.IsTrue(keys.Contains(1)); Assert.IsTrue(keys.Contains(2)); Assert.IsTrue(keys.Contains(3)); Assert.IsTrue(keys.Contains(4)); Assert.IsTrue(keys.Contains(5)); Assert.IsTrue(keys.Contains(6)); Assert.IsTrue(keys.Contains(7)); var values = dic.Values; Assert.IsNotNull(values); Assert.IsTrue(values.IsReadOnly); Assert.AreEqual(7, values.Count); Assert.IsTrue(values.Contains("1")); Assert.IsTrue(values.Contains("2")); Assert.IsTrue(values.Contains("3")); Assert.IsTrue(values.Contains("4")); Assert.IsTrue(values.Contains("5")); Assert.IsTrue(values.Contains("6")); Assert.IsTrue(values.Contains("7")); }
/// <summary> /// Optimizes this index once it's fully loaded. /// </summary> public void Optimize() { // sort array. Itinero.Algorithms.Sorting.QuickSort.Sort(i => { return(_data[i * 2]); }, (i, j) => { var t1 = _data[i * 2 + 0]; var t2 = _data[i * 2 + 1]; _data[i * 2 + 0] = _data[j * 2 + 0]; _data[i * 2 + 1] = _data[j * 2 + 1]; _data[j * 2 + 0] = t1; _data[j * 2 + 1] = t2; }, 0, (_pointer / 2) - 1); // remove reverse index. _reverseIndex = null; // reduce array size to exact data size. _data.Resize(_pointer); }
public void HugeDictionary_EnumerateEntries() { HugeDictionary <string, int> dictionary; Dictionary <string, bool> enumerated; dictionary = new HugeDictionary <string, int>(10, 5000); enumerated = new Dictionary <string, bool>(); for (int i = 0; i < 1000; i++) { dictionary.Add(i.ToString(), i); } foreach (var entry in dictionary) { Assert.AreEqual(entry.Key, entry.Value.ToString()); enumerated[entry.Key] = true; } for (int i = 0; i < 1000; i++) { Assert.IsTrue(enumerated.ContainsKey(i.ToString())); } }
/// <summary> /// Creates the coordinate index. /// </summary> public CoordinateIndex() { _coordinates = new HugeDictionary<long, ICoordinate>(); }
public CoreNodeIdMap() { this._firstMap = new HugeDictionary <long, uint>(); this._secondMap = new HugeDictionary <long, CoreNodeIdMap.LinkedListNode>(); }
public void TestHugeDictionaryEnumeration() { // create the huge dictionary. var hugeDictionary = new HugeDictionary<long, long>(100); for (long idx = 0; idx < 1000; idx++) { hugeDictionary.Add(idx, idx); } var items = new List<KeyValuePair<long, long>>( hugeDictionary); Assert.AreEqual(hugeDictionary.Count, items.Count); }
/// <summary> /// Creates the coordinate index. /// </summary> public CoordinateIndex() { _coordinates = new HugeDictionary <long, ICoordinate>(); }
/// <summary> /// Creates a new osm edge data processing target. /// </summary> /// <param name="dynamicGraph"></param> /// <param name="interpreter"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="vehicles">The vehicle profiles to build routing information for.</param> /// <param name="collectIntermediates"></param> public LiveGraphOsmStreamTarget(IDynamicGraphRouterDataSource <LiveEdge> dynamicGraph, IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations, IEnumerable <Vehicle> vehicles, bool collectIntermediates) : base(dynamicGraph, interpreter, null, tagsIndex, idTransformations, collectIntermediates) { _vehicles = new HashSet <Vehicle>(); if (vehicles != null) { foreach (Vehicle vehicle in vehicles) { _vehicles.Add(vehicle); } } }
/// <summary> /// Creates a new osm edge data processing target. /// </summary> /// <param name="dynamicGraph"></param> /// <param name="interpreter"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> public LiveGraphOsmStreamTarget(IDynamicGraphRouterDataSource <LiveEdge> dynamicGraph, IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations) : this(dynamicGraph, interpreter, tagsIndex, idTransformations, null, true) { }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> protected DynamicGraphOsmStreamWriter(IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations) : this(dynamicGraph, interpreter, edgeComparer, tagsIndex, idTransformations, false) { }