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> /// Adds a node that is at least part of one road. /// </summary> /// <param name="nodeId"></param> /// <returns></returns> private uint?AddRoadNode(long nodeId) { uint id; // try and get existing node. if (!_idTransformations.TryGetValue(nodeId, out id)) { // get coordinates. GeoCoordinateSimple coordinates; if (_coordinates.TryGetValue(nodeId, out coordinates)) { // the coordinate is present. id = _dynamicGraph.AddVertex( coordinates.Latitude, coordinates.Longitude); _coordinates.Remove(nodeId); // free the memory again! if (_relevantNodes.Contains(nodeId)) { _idTransformations[nodeId] = id; } return(id); } return(null); } return(id); }
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> /// Switches the two id's. /// </summary> public void Switch(uint id1, uint id2) { if (_reverseIndex == null) { this.MakeWriteable(); } // remove the two from the index and keep their pointers. int pointer1, pointer2; if (!_reverseIndex.TryGetValue(id1, out pointer1)) { pointer1 = -1; } else { _reverseIndex.Remove(id1); } if (!_reverseIndex.TryGetValue(id2, out pointer2)) { pointer2 = -1; } else { _reverseIndex.Remove(id2); } // add them again but in reverse. if (pointer1 != -1) { _data[pointer1] = id2; _reverseIndex[id2] = pointer1; } if (pointer2 != -1) { _data[pointer2] = id1; _reverseIndex[id1] = pointer2; } }
/// <summary> /// Updates the vertex info object with the given vertex. /// </summary> /// <returns>True if succeeded, false if a witness calculation is required.</returns> private bool UpdateVertexInfo(uint v) { var contracted = 0; var depth = 0; // update vertex info. _vertexInfo.Clear(); _vertexInfo.Vertex = v; _contractionCount.TryGetValue(v, out contracted); _vertexInfo.ContractedNeighbours = contracted; _depth.TryGetValue(v, out depth); _vertexInfo.Depth = depth; // add neighbours. _vertexInfo.AddRelevantEdges(_graph.GetEdgeEnumerator()); // check if any of neighbours are in witness queue. if (_witnessQueue.Count > 0) { for (var i = 0; i < _vertexInfo.Count; i++) { var m = _vertexInfo[i]; if (_witnessQueue.Contains(m.Neighbour)) { //this.DoWitnessQueue(); //break; return(false); } } } // build shortcuts. _vertexInfo.BuildShortcuts(_weightHandler); // remove witnessed shortcuts. _vertexInfo.RemoveShortcuts(_witnessGraph, _weightHandler); return(true); }
/// <summary> /// Returns true if the given node has an actual road node, meaning a relevant vertex, and outputs the vertex id. /// </summary> /// <param name="nodeId">The node id.</param> /// <param name="id">The vertex id.</param> /// <returns></returns> private bool TryGetRoadNode(long nodeId, out uint id) { return(_idTransformations.TryGetValue(nodeId, out id)); }
/// <summary> /// Tries to the the coordinate for the given idx. /// </summary> /// <param name="idx"></param> /// <param name="coordinate"></param> /// <returns></returns> public bool TryGet(long idx, out ICoordinate coordinate) { return(_coordinates.TryGetValue(idx, out coordinate)); }