public void Push(TKey key, TValue value, ref int collisionCount) { if (First == null) { First = new BucketEntryOld <TKey, TValue>(key, value); return; } else { var entry = First; collisionCount++; while (true) { if (entry.Key.Equals(key)) { throw new ArgumentException($"Key {key} already exists on storage"); } if (entry.Next == null) { break; } else { entry = entry.Next; } } entry.Append(key, value); } }
public bool TryPush(TKey key, TValue value, int maxLength, ref int collisionCount) { if (First == null) { First = new BucketEntryOld <TKey, TValue>(key, value); return(true); } else { var entry = First; collisionCount++; var counter = 1; while (true) { if (entry.Key.Equals(key)) { throw new ArgumentException($"Key {key} already exists on storage"); } if (entry.Next == null) { break; } else { counter++; entry = entry.Next; } } if (counter <= maxLength) { entry.Append(key, value); return(true); } else { return(false); } } }
public void Append(TKey key, TValue value) { Next = new BucketEntryOld <TKey, TValue>(key, value); }