public Tuple <bool, TValue, long> Search(string key) { var sw = new Stopwatch(); sw.Start(); var hashCode = HashCalculator.Calculate(key); var index = hashCode % _entries.Length; foreach (var ind in _randomNumbersSequence) { var newIndex = (index + ind) % _entries.Length; if (_entries[newIndex] == default(Entry)) { sw.Stop(); return(new Tuple <bool, TValue, long>(false, default(TValue), sw.ElapsedNanoSeconds())); } else { if (_entries[newIndex].Key == key) { sw.Stop(); return(new Tuple <bool, TValue, long>(true, _entries[newIndex].Value, sw.ElapsedNanoSeconds())); } } } sw.Stop(); return(new Tuple <bool, TValue, long>(false, default(TValue), sw.ElapsedNanoSeconds())); }
public Tuple <bool, TValue, long> Search(string key) { var sw = new Stopwatch(); sw.Start(); var hashCode = HashCalculator.Calculate(key); var index = hashCode % _buckets.Length; if (_buckets[index] == -1) { sw.Stop(); return(new Tuple <bool, TValue, long>(false, default(TValue), sw.ElapsedNanoSeconds())); } else if (_entries[_buckets[index]].Key == key) { sw.Stop(); return(new Tuple <bool, TValue, long>(true, _entries[_buckets[index]].Value, sw.ElapsedNanoSeconds())); } else { index = _buckets[index]; while ((index = _entries[index].Next) != -1) { if (_entries[index].Key == key) { sw.Stop(); return(new Tuple <bool, TValue, long>(true, _entries[index].Value, sw.ElapsedNanoSeconds())); } } } return(new Tuple <bool, TValue, long>(false, default(TValue), sw.ElapsedNanoSeconds())); }
public long Add(string key, TValue value) { var sw = new Stopwatch(); sw.Start(); var hashCode = HashCalculator.Calculate(key); var index = hashCode % _buckets.Length; if (_buckets[index] == -1) { _entries.Add(new Entry(key, value)); _buckets[index] = _entries.Count - 1; sw.Stop(); return(sw.ElapsedNanoSeconds()); } else { _entries.Add(new Entry(key, value)); var entry = _entries[_buckets[index]]; index = _buckets[index]; while (true) { if (entry.Next == -1) { break; } index = entry.Next; entry = _entries[index]; } entry.Next = _entries.Count - 1; _entries[index] = entry; sw.Stop(); return(sw.ElapsedNanoSeconds()); } }
public long Add(string key, TValue value) { var sw = new Stopwatch(); sw.Start(); var hashCode = HashCalculator.Calculate(key); var index = hashCode % _entries.Length; foreach (var offset in _randomNumbersSequence) { var newIndex = (index + offset) % _entries.Length; if (_entries[newIndex] == default(Entry)) { _entries[newIndex] = new Entry(key, value); sw.Stop(); return(sw.ElapsedNanoSeconds()); } } throw new Exception("В таблице не осталось свободных ячеек"); }