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); }
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 || NETFRAMEWORK 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)); }