public RecordedMapModel(IEnumerable <KeyValuePair <TKeyType, TValueType> > keyValuePairs) : this()
        {
            Contract.Requires <ArgumentNullException>(keyValuePairs != null);

            foreach (var e in keyValuePairs)
            {
                Map = Map.Add(e.Key, e.Value);
            }
        }
        public void FSharpMapTest_2_Success()
        {
            var collection = new FSharpMap <int, int>(Enumerable.Empty <Tuple <int, int> >());

            collection = collection.Add(0, 0);
            collection = collection.Add(1, 1);
            var target = this.CreateTarget <FSharpMap <int, int> >();

            using (var buffer = new MemoryStream())
            {
                target.Pack(buffer, collection);
                buffer.Position = 0;
                var unpacked = target.Unpack(buffer);
                buffer.Position = 0;
                Assert.That(unpacked.ToArray(), Is.EqualTo(collection.ToArray()));
            }
        }
        public static FSharpMap<string, string> ConvertCsMapToFSharpMap(Dictionary<string, string> data)
        {
            var map = new FSharpMap<string, string>(new List<Tuple<string, string>>());
            foreach (var elem in data)
            {
                map = map.Add(elem.Key, elem.Value);
            }

            return map;
        }
示例#4
0
 public static FSharpMap <TKey, TValue> WithGuaranteedEntry <TKey, TValue>(this FSharpMap <TKey, TValue> map, TKey key, Func <TValue> toAddIfNotPresent)
 {
     if (map.ContainsKey(key))
     {
         return(map);
     }
     else
     {
         return(map.Add(key, toAddIfNotPresent()));
     }
 }
示例#5
0
        private static FSharpMap <long, long> FSharpMap_Add(long count)
        {
            FSharpMap <long, long> im;

            im = new FSharpMap <long, long>(Enumerable.Empty <Tuple <long, long> >());
            using (Benchmark.Run("Add", count))
            {
                for (int i = 0; i < count; i++)
                {
                    im = im.Add(i, i);
                }
            }

            return(im);
        }
示例#6
0
 public ImmutableMap <TKey, TValue> Add(TKey key, TValue value)
 {
     return(innerMap.Add(key, value));
 }
        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 FSharpMap<string, ProductTypes.Meta> Merge(FSharpMap<string, ProductTypes.Meta> src, MetaData[] update)
        {
            if (src == null) return Convert(update);
            if (update == null) return src;

            foreach (MetaData m in update)
            {
                if(m == null) continue;
                if (src.ContainsKey(m.name))
                {
                    var converted = Merge(src[m.name], m);
                    src = src.Add(converted.key, converted);
                }
                else src = src.Add(m.name, Convert(m));
            }

            return src;
        }
        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);
             */
        }
示例#10
0
 public static Map1 <TKey, TValue> Build(TKey initialKey, TValue initialValue, FSharpMap <TKey, TValue> rest)
 {
     return(new Map1 <TKey, TValue>(rest.Add(initialKey, initialValue)));
 }