private bool TryAddInternal(byte[] key, int value)
        {
            var h     = ByteArrayGetHashCode(key);
            var entry = new Entry {
                Key = key, Value = value
            };

            Entry[] array = this.buckets[h & this.indexFor];
            if (array == null)
            {
                this.buckets[h & this.indexFor] = new[] { entry };
            }
            else
            {
                // check duplicate
                for (int i = 0; i < array.Length; i++)
                {
                    Memory <byte> e = array[i].Key;
                    if (ByteArrayComparer.Equals(key, e.Span))
                    {
                        return(false);
                    }
                }

                var newArray = new Entry[array.Length + 1];
                Array.Copy(array, newArray, array.Length);
                array = newArray;
                array[array.Length - 1]         = entry;
                this.buckets[h & this.indexFor] = array;
            }

            return(true);
        }
        bool TryAddInternal(byte[] key, int value)
        {
            var h     = ByteArrayGetHashCode(key, 0, key.Length);
            var entry = new Entry {
                Key = key, Value = value
            };

            var array = buckets[h & (indexFor)];

            if (array == null)
            {
                buckets[h & (indexFor)] = new[] { entry };
            }
            else
            {
                // check duplicate
                for (int i = 0; i < array.Length; i++)
                {
                    var e = array[i].Key;
                    if (ByteArrayComparer.Equals(key, 0, key.Length, e))
                    {
                        return(false);
                    }
                }

                var newArray = new Entry[array.Length + 1];
                Array.Copy(array, newArray, array.Length);
                array = newArray;
                array[array.Length - 1] = entry;
                buckets[h & (indexFor)] = array;
            }

            return(true);
        }
예제 #3
0
        public bool TryGetValue(ReadOnlySpan <byte> key, out int value)
        {
            var table = buckets;
            var hash  = ByteArrayGetHashCode(key);
            var entry = table[hash & indexFor];

            if (entry == null)
            {
                goto NOT_FOUND;
            }

            {
#if !UNITY
                ref var v = ref entry[0];
#else
                var v = entry[0];
#endif
                if (ByteArrayComparer.Equals(key, v.Key.Span))
                {
                    value = v.Value;
                    return(true);
                }
            }
        public bool TryGetValue(ArraySegment <byte> key, out int value)
        {
            var table = buckets;
            var hash  = ByteArrayGetHashCode(key.Array, key.Offset, key.Count);
            var entry = table[hash & indexFor];

            if (entry == null)
            {
                goto NOT_FOUND;
            }

            {
#if NETSTANDARD
                ref var v = ref entry[0];
#else
                var v = entry[0];
#endif
                if (ByteArrayComparer.Equals(key.Array, key.Offset, key.Count, v.Key))
                {
                    value = v.Value;
                    return(true);
                }
            }
 public bool Equals(byte[] x, ArraySegment <byte> y)
 {
     return(ByteArrayComparer.Equals(y.Array, y.Offset, y.Count, x));
 }
예제 #6
0
 public bool Equals(byte[] x, ArraySegment <byte> y)
 {
     return(ByteArrayComparer.Equals(y, x));
 }