示例#1
0
        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);
        }
示例#2
0
        /// <summary>
        /// Notifies this calculator that the given vertex was contracted.
        /// </summary>
        public void NotifyContracted(uint vertex)
        {
            // removes the contractions count.
            _contractionCount.Remove(vertex);

            // loop over all neighbours.
            if (_edgeEnumerator == null)
            {
                _edgeEnumerator = _graph.GetEdgeEnumerator();
            }
            _edgeEnumerator.MoveTo(vertex);

            int vertexDepth = 0;

            _depth.TryGetValue(vertex, out vertexDepth);
            _depth.Remove(vertex);
            vertexDepth++;

            // store the depth.
            _edgeEnumerator.Reset();
            while (_edgeEnumerator.MoveNext())
            {
                var neighbour = _edgeEnumerator.Neighbour;

                int depth = 0;
                _depth.TryGetValue(neighbour, out depth);
                if (vertexDepth >= depth)
                {
                    _depth[neighbour] = vertexDepth;
                }

                int count;
                if (!_contractionCount.TryGetValue(neighbour, out count))
                {
                    _contractionCount[neighbour] = 1;
                }
                else
                {
                    count++;
                    _contractionCount[neighbour] = count;
                }

                if (_witnessGraph.VertexCount > vertex &&
                    _witnessGraph.VertexCount > neighbour)
                {
                    _witnessGraph.RemoveEdge(neighbour, vertex);
                }
            }

            if (_witnessGraph.VertexCount > vertex)
            {
                _witnessGraph.RemoveEdges(vertex);
            }
        }
示例#3
0
        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"));
        }
示例#4
0
        /// <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;
            }
        }
示例#5
0
        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);
        }
 /// <summary>
 /// Removes the coordinate at the given index.
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 public bool Remove(long idx)
 {
     return(_coordinates.Remove(idx));
 }