ColaRangeDictionary<TKey, TValue>

Namespace: SnowBank.Collections.CacheOblivious · class

Implements: IEnumerable<Entry>, IEnumerable, IDisposable

Represent an ordered list of ranges, each associated with a specific value, stored in a Cache Oblivious Lookup Array

Constructors

ColaRangeDictionary<TKey, TValue>

ColaRangeDictionary<TKey, TValue>(ArrayPool<Entry> pool = null)

ColaRangeDictionary<TKey, TValue>(ColaRangeDictionary<TKey, TValue> source)

Constructs a new ColaRangeDictionary by copying the contents of another dictionary

ColaRangeDictionary<TKey, TValue>(int capacity, ArrayPool<Entry> pool = null)

ColaRangeDictionary<TKey, TValue>(IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer = null, ArrayPool<Entry> pool = null)

ColaRangeDictionary<TKey, TValue>(int capacity, IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer = null, ArrayPool<Entry> pool = null)

Properties

Bounds

Entry Bounds { get; }

Current bounds of this instance (minimum and maximum value)

Capacity

int Capacity { get; }

Allocated capacity of this instance

Count

int Count { get; }

Number of distinct ranges in this instance

KeyComparer

IComparer<TKey> KeyComparer { get; }

Helper used to compare and sort keys of this instance

ValueComparer

IEqualityComparer<TValue> ValueComparer { get; }

Helper used to check values of this instance for equality

Methods

Clear

void Clear()

Removes all ranges from this instance

Copy

ColaRangeDictionary<TKey, TValue> Copy()

Creates a copy of this dictionary

CopyTo

void CopyTo(ColaRangeDictionary<TKey, TValue> destination)

Copies all the ranges of this dictionary onto another dictionary

  • destination — Destination dictionary that will be modified

Debug_Dump

void Debug_Dump(TextWriter output)

Writes the contents of this dictionary into a log, for debugging purpose [DEBUG ONLY]

Dispose

void Dispose()

FindFirst

bool FindFirst(TKey begin, TKey end, out TValue value)

Checks if there is at least one range in the dictionary that intersects with the specified range, and matches the predicate

  • begin — Lower bound of the intersection
  • end — Higher bound (excluded) of the intersection
  • value — Receives the value of the first matched segment in the range

Returns: true if there was at least one intersecting range, and value received the corresponding value.

GetEnumerator

Enumerator<Entry> GetEnumerator()

GetIterator

Iterator GetIterator()

Returns an iterator that can read the contents of this dictionary

GetValueOrDefault

TValue GetValueOrDefault(TKey key, TValue defaultValue)

Returns the value of the range that contains the specified key, or a default value if there is none.

  • key — Key that is being looked up
  • defaultValue — Value that will be returned if the key is outside the bounds, or falls between two ranges.

Returns: Value of the range that contains key; otherwise, defaultValue

Intersect

bool Intersect(TKey begin, TKey end, out Entry match)

bool Intersect(TKey begin, TKey end, Func<TValue, bool> predicate, out Entry match)

bool Intersect<TArg>(TKey begin, TKey end, TArg arg, Func<TValue, TArg, bool> predicate, out Entry match)

IterateOrdered

IEnumerable<Entry> IterateOrdered()

Returns a sequence of all the ranges in this dictionary, ordered by their keys.

Mark

void Mark((TKey, TKey, TValue) range)

Marks a range with a new value

  • range — Begin key (included), End key (excluded) and new Value for this range

void Mark((TKey, TKey) range, TValue value)

Marks a range with a new value

  • range — Begin key (included) and End key (excluded) of the range
  • value — New value for this range

void Mark(TKey beginInclusive, TKey endExclusive, TValue value)

Marks a range with a new value

  • beginInclusive — Begin key of the range (included)
  • endExclusive — End key of the range (excluded)
  • value — New value for this range

Merge

void Merge<TData>(TKey beginInclusive, TKey endExclusive, TData value, Func<TValue, TData, TValue> combinator)

Marks a range with a new value by updating, merging or overriding any previous values in this range

Remove

void Remove(TKey beginInclusive, TKey endExclusive, TKey offset, Func<TKey, TKey, TKey> applyOffset)

Removes everything between beginInclusive and endExclusive then translates everything

  • beginInclusive — Begin key (inclusive)
  • endExclusive — End key (exclusive)
  • offset — Offset to apply
  • applyOffset — Func to apply offset to a key

Scan

IEnumerable<(TKey, TKey, TValue)> Scan(TKey begin, TKey end)

Enumerate all the keys in the dictionary that are in the specified range

  • begin — Start of the range
  • end — End of the range

Returns: Sequence of the all the ranges in the dictionary that intersect the specified range.

The dictionary should not be modified while iterating over the sequence.

ToString

string ToString()

TryGetValue

bool TryGetValue(TKey key, out TValue value)

Returns the value of the range that contains the specified key, if there is one.

  • key — Key that is being looked up
  • value — If the key intersects a range, receives the value of this range.

Returns: true if there is a range that contains key; otherwise, false (outside the bounds, or between two ranges)