Exemplo n.º 1
0
        public ImmutableMap <TKey, TValue> Set(TKey key, TValue value)
        {
            var map = innerMap.Remove(key);

            map = map.Add(key, value);
            return(map);
        }
Exemplo n.º 2
0
        public void Performance()
        {
            //Var.pushThreadBindings(RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref()));
            var m1 = new RecordedMapModel <string, Item>();
            //var m2 = new ClojureRecordedMapModel<string, Item>();
            var m3 = new Dictionary <string, Item>();
            var m4 = new FSharpMap <string, Item>(Enumerable.Empty <Tuple <string, Item> >());
            //var m5 = new PersistentTreeMap();

            const int size = 10000;
            var       s    = new Stopwatch();

            s.Start();
            for (var i = 0; i < size; i++)
            {
                m1.Set(i.ToString(), new Item(i, i.ToString()));
            }
            for (var i = 0; i < size * 100; i++)
            {
                m1.Get((i % size).ToString());
            }
            for (var i = 0; i < size; i++)
            {
                m1.Remove(i.ToString());
            }
            s.Stop();
            Console.WriteLine("RecordedMapModel took " + s.Elapsed);

            /*
             * s.Restart();
             * for (var i = 0; i < size; i++)
             *  m2.Set(i.ToString(), new Item(i, i.ToString()));
             * for (var i = 0; i < size * 100; i++)
             *  m2.Get((i % size).ToString());
             * for (var i = 0; i < size; i++)
             *  m2.Remove(i.ToString());
             * s.Stop();
             * Console.WriteLine("ClojureRecordedMapModel took " + s.Elapsed);
             */

            s.Restart();
            for (var i = 0; i < size; i++)
            {
                m3[i.ToString()] = new Item(i, i.ToString());
            }
            Item o;

            for (var i = 0; i < size * 100; i++)
            {
                m3.TryGetValue((i % size).ToString(), out o);
            }
            for (var i = 0; i < size; i++)
            {
                m3.Remove(i.ToString());
            }
            s.Stop();
            Console.WriteLine("Dictionary took " + s.Elapsed);

            m3.Clear();
            s.Restart();
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary <string, Item>(m3);
                tmp[i.ToString()] = new Item(i, i.ToString());
                m3 = tmp;
            }
            for (var i = 0; i < size * 100; i++)
            {
                m3.TryGetValue((i % size).ToString(), out o);
            }
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary <string, Item>(m3);
                tmp.Remove(i.ToString());
                m3 = tmp;
            }
            s.Stop();
            Console.WriteLine("Copy Dictionary took " + s.Elapsed);

            s.Restart();
            for (var i = 0; i < size; i++)
            {
                m4 = m4.Add(i.ToString(), new Item(i, i.ToString()));
            }
            for (var i = 0; i < size * 100; i++)
            {
                m4.TryFind((i % size).ToString());
            }
            for (var i = 0; i < size; i++)
            {
                m4 = m4.Remove(i.ToString());
            }
            s.Stop();
            Console.WriteLine("FSharpMap took " + s.Elapsed);

            /*
             * s.Restart();
             * for (var i = 0; i < size; i++)
             *  m5 = (PersistentTreeMap)m5.assoc(i.ToString(), new Item(i, i.ToString()));
             * object obj;
             * for (var i = 0; i < size * 100; i++)
             *  m5.TryGetValue((i % size).ToString(), out obj);
             * for (var i = 0; i < size; i++)
             *  m5 = (PersistentTreeMap)RT.dissoc(m5, i.ToString());
             * s.Stop();
             * Console.WriteLine("PersistentTreeMap took " + s.Elapsed);
             */
        }
 public void Remove(TKeyType key)
 {
     Map = Map.Remove(key);
 }
Exemplo n.º 4
0
 public void Remove(TKeyType key)
 {
     _indHistory.OnSet();
     Map = Map.Remove(key);
 }
Exemplo n.º 5
0
        public void Performance()
        {
            //Var.pushThreadBindings(RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref()));
            var m1 = new RecordedMapModel<string, Item>();
            //var m2 = new ClojureRecordedMapModel<string, Item>();
            var m3 = new Dictionary<string, Item>();
            var m4 = new FSharpMap<string, Item>(Enumerable.Empty<Tuple<string, Item>>());
            //var m5 = new PersistentTreeMap();

            const int size = 10000;
            var s = new Stopwatch();
            s.Start();
            for (var i = 0; i < size; i++)
                m1.Set(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m1.Get((i % size).ToString());
            for (var i = 0; i < size; i++)
                m1.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("RecordedMapModel took " + s.Elapsed);

            /*
            s.Restart();
            for (var i = 0; i < size; i++)
                m2.Set(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m2.Get((i % size).ToString());
            for (var i = 0; i < size; i++)
                m2.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("ClojureRecordedMapModel took " + s.Elapsed);
             */

            s.Restart();
            for (var i = 0; i < size; i++)
                m3[i.ToString()] = new Item(i, i.ToString());
            Item o;
            for (var i = 0; i < size * 100; i++)
                m3.TryGetValue((i % size).ToString(), out o);
            for (var i = 0; i < size; i++)
                m3.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("Dictionary took " + s.Elapsed);

            m3.Clear();
            s.Restart();
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary<string, Item>(m3);
                tmp[i.ToString()] = new Item(i, i.ToString());
                m3 = tmp;
            }
            for (var i = 0; i < size * 100; i++)
                m3.TryGetValue((i % size).ToString(), out o);
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary<string, Item>(m3);
                tmp.Remove(i.ToString());
                m3 = tmp;
            }
            s.Stop();
            Console.WriteLine("Copy Dictionary took " + s.Elapsed);

            s.Restart();
            for (var i = 0; i < size; i++)
                m4 = m4.Add(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m4.TryFind((i % size).ToString());
            for (var i = 0; i < size; i++)
                m4 = m4.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("FSharpMap took " + s.Elapsed);

            /*
            s.Restart();
            for (var i = 0; i < size; i++)
                m5 = (PersistentTreeMap)m5.assoc(i.ToString(), new Item(i, i.ToString()));
            object obj;
            for (var i = 0; i < size * 100; i++)
                m5.TryGetValue((i % size).ToString(), out obj);
            for (var i = 0; i < size; i++)
                m5 = (PersistentTreeMap)RT.dissoc(m5, i.ToString());
            s.Stop();
            Console.WriteLine("PersistentTreeMap took " + s.Elapsed);
             */
        }