public LinearSearch(CustomSortedList <T, K> parent, K startKey) { if (parent == null) { throw new ArgumentNullException(); } _parent = parent; // possible outcomes for binarysearch: // index >= 0: meaning, start there // index < 0: start at ~index _index = parent.BinarySearch(0, parent.Count, startKey); if (_index < 0) { _index = ~_index; } if (_index >= _parent.Count) { if (parent.Count == 0) { _currentItem = default(T); } else { _currentItem = _parent[parent.Count - 1]; } } else { var cmp = _parent.CompareFunction(startKey, _parent[_index]); if (cmp < 0) { if (_index == 0) { _currentItem = default(T); } else { _index--; _currentItem = _parent[_index]; } } else { _currentItem = _parent[_index]; } } }
public bool GetExistentValueAt(TimeStamp stamp, out TimeLocatedValue <T> val) { var idx = _values.BinarySearch(0, _values.Count, stamp); if (idx < 0) { idx = ~idx; } idx--; if (idx < 0 || idx >= _values.Count) { val = new TimeLocatedValue <T>(); return(false); } val = _values[idx]; return(true); }