Example #1
0
        /// <summary>
        /// Enumerate over the dictionary
        /// </summary>
        /// <returns></returns>
        public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
        {
            foreach (long firstKeyPosition in _hashCodeLookup)
            {
                long keyPosition = firstKeyPosition;
                while (keyPosition != 0)
                {
                    _keys.Position = keyPosition;
                    int  keyLength = _keys.ReadVInt();
                    TKey key       = _keySerializer.BytesToObject(_keys.MultiRead(keyLength));
                    long valuePos  = _keys.ReadVLong();
                    _values.Position = valuePos;
                    int    valueLength = _values.ReadVInt();
                    TValue value       = _valueSerializer.BytesToObject(_values.MultiRead(valueLength));

                    if (_keys.Position > _largestSeenKeyPosition)
                    {
                        _largestSeenKeyPosition = _keys.Position + 9;
                    }
                    if (_values.Position > _largestSeenValuePosition)
                    {
                        _largestSeenValuePosition = _values.Position;
                    }

                    yield return(new KeyValuePair <TKey, TValue>(key, value));

                    keyPosition = _keys.ReadVLong();
                }
            }
        }
Example #2
0
File: Array.cs Project: wobba/mmf
 public T this[long index]
 {
     get
     {
         if (index < 0)
         {
             throw new IndexOutOfRangeException("Tried to access item outside the array boundaries");
         }
         ValueLock.EnterReadLock();
         if (index >= Capacity)
         {
             if (AutoGrow)
             {
                 ViewManager.Grow(index);
             }
             else
             {
                 throw new IndexOutOfRangeException("Tried to access item outside the array boundaries");
             }
         }
         try
         {
             return(ValueSerializer.BytesToObject(Read(index)));
         }
         finally
         {
             ValueLock.ExitReadLock();
         }
     }
     set
     {
         if (index < 0)
         {
             throw new IndexOutOfRangeException("Tried to access item outside the array boundaries");
         }
         ValueLock.EnterWriteLock();
         try
         {
             if (index >= Capacity)
             {
                 if (AutoGrow)
                 {
                     ViewManager.Grow(index);
                 }
                 else
                 {
                     throw new IndexOutOfRangeException("Tried to access item outside the array boundaries");
                 }
             }
             Write(ValueSerializer.ObjectToBytes(value), index);
         }
         finally
         {
             ValueLock.ExitWriteLock();
         }
     }
 }
Example #3
0
File: Factory.cs Project: wobba/mmf
 private int BenchMarkSerializer(ISerializeDeserialize <T> serDeser)
 {
     object[] args = null;
     if (typeof(T) == typeof(string))
     {
         args = new object[] { new[] { 'T', 'e', 's', 't', 'T', 'e', 's', 't', 'T', 'e', 's', 't' } };
     }
     else if (typeof(T) == typeof(byte[]))
     {
         byte[]    test          = new byte[100];
         T         classInstance = (T)(object)test;
         Stopwatch sw            = Stopwatch.StartNew();
         int       count         = 0;
         while (sw.ElapsedMilliseconds < 500)
         {
             byte[] bytes = serDeser.ObjectToBytes(classInstance);
             serDeser.BytesToObject(bytes);
             count++;
         }
         sw.Stop();
         return(count);
     }
     try
     {
         T classInstance = (T)Activator.CreateInstance(typeof(T), args);
         DataHelper.AssignEmptyData(ref classInstance);
         Stopwatch sw    = Stopwatch.StartNew();
         int       count = 0;
         while (sw.ElapsedMilliseconds < 500)
         {
             byte[] bytes = serDeser.ObjectToBytes(classInstance);
             serDeser.BytesToObject(bytes);
             count++;
         }
         sw.Stop();
         return(count);
     }
     catch (MissingMethodException)
     {
         // Missing default constructor
         return(0);
     }
 }
Example #4
0
        public void BenchmarkDeserializeMethod <T>(ISerializeDeserialize <T> serializer, object instance)
        {
            var bytes = serializer.ObjectToBytes((T)instance);

            serializer.BytesToObject(bytes);

            Stopwatch timed = new Stopwatch();

            timed.Start();

            T value = default(T);

            for (int x = 0; x < Iterations; x++)
            {
                value = serializer.BytesToObject(bytes);
            }

            timed.Stop();

            Trace.WriteLine("Deserialize method: " + serializer.GetType().Name);
            Trace.WriteLine(timed.ElapsedMilliseconds + " ms");
            Trace.WriteLine(value);
            Trace.WriteLine("");
        }