public void CollisionCheck()
        {
            Formatter <DefaultResolver, HashCollision> .Register(new TestFormatter());

            ZeroFormatterEqualityComparer <HashCollision> .Register(new HashCollisionEqualityComparer());

            var dict = new DictionarySegment <DefaultResolver, HashCollision, int>(new DirtyTracker(), 5);

            dict.Add(new HashCollision(10, 999), 6);
            dict.Add(new HashCollision(99, 999), 9);

            dict[new HashCollision(10, 999)].Is(6);
            dict[new HashCollision(99, 999)].Is(9);
        }
Beispiel #2
0
        public override int Serialize(ref byte[] bytes, int offset, ILazyReadOnlyDictionary <TKey, TValue> value)
        {
            if (value == null)
            {
                BinaryUtil.WriteInt32(ref bytes, offset, -1);
                return(4);
            }

            var dictionary = value as DictionarySegment <TKey, TValue>;

            if (dictionary == null)
            {
                dictionary = new DictionarySegment <TKey, TValue>(new DirtyTracker(offset), value.Count);
                foreach (var item in value)
                {
                    dictionary.Add(item.Key, item.Value);
                }
            }

            return(dictionary.Serialize(ref bytes, offset));
        }