ColaOrderedDictionary<TKey, TValue>
Namespace: SnowBank.Collections.CacheOblivious · class
Implements: IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDisposable
Represent an ordered set of key/value pairs, stored in a Cache Oblivious Lookahead Array
Constructors
ColaOrderedDictionary<TKey, TValue>
ColaOrderedDictionary<TKey, TValue>(ColaOrderedDictionary<TKey, TValue> source)
Constructs a new ColaOrderedDictionary by copying the content of another dictionary.
ColaOrderedDictionary<TKey, TValue>(int capacity, ArrayPool<KeyValuePair<TKey, TValue>> pool = null)
Constructs a new ColaOrderedDictionary with the given initial capacity
ColaOrderedDictionary<TKey, TValue>(IComparer<TKey> keyComparer = null, IEqualityComparer<TValue> valueComparer = null, ArrayPool<KeyValuePair<TKey, TValue>> pool = null)
Constructs a new ColaOrderedDictionary
ColaOrderedDictionary<TKey, TValue>(int capacity, IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer, ArrayPool<KeyValuePair<TKey, TValue>> pool = null)
Constructs a new ColaOrderedDictionary with the given initial capacity and key/value comparer
Properties
Capacity
int Capacity { get; }
Allocated capacity of this instance
Count
int Count { get; }
Number of distinct ranges in this instance
Item
TValue Item { get; set; }
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
Add
void Add(TKey key, TValue value)
Adds an entry with the specified key and value to the sorted dictionary.
key— The key of the entry to add.value— The value of the entry to add.
AddOrUpdate
bool AddOrUpdate(TKey key, TValue value)
Try to add an entry with the specified key and value to the sorted dictionary, or update its value if it already exists.
key— The key of the entry to add.value— The value of the entry to add.
Returns: true if the key did not previously exist and was inserted; otherwise, false.
Clear
void Clear()
Removes all ranges from this instance
ContainsKey
bool ContainsKey(TKey key)
Tests if there is a range that contains a given key
ContainsValue
bool ContainsValue(TValue value)
Tests if there is a range that is assigned with a given value
Copy
ColaOrderedDictionary<TKey, TValue> Copy()
Creates a new copy of this dictionary
Debug_Dump
void Debug_Dump(TextWriter output)
Writes the contents of this dictionary into a log, for debugging purpose [DEBUG ONLY]
Dispose
void Dispose()
GetEnumerator
Enumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns an enumerator that iterates through the ordered dictionary
GetIterator
Iterator GetIterator()
Returns an iterator that can read the contents of this dictionary
GetOrAdd
bool GetOrAdd(TKey key, TValue value, out TValue actualValue)
Try to add an entry with the specified key and value to the sorted dictionary, if it does not already exist.
key— The key of the entry to add.value— The value of the entry to add.actualValue— Receives the previous value ifkeyalready exists, orvalueif it was inserted
Returns: true if the key did not previously exist and was inserted; otherwise, false.
GetValue
TValue GetValue(TKey key)
Gets the value associated with the specified key
key— Key that is being searched
Returns: Corresponding value
IterateAndRemoveRange
IEnumerable<TKey> IterateAndRemoveRange(TKey begin, bool beginEqual, TKey end, bool endEqual)
Iterates and removes all the keys between two bounds
IterateOrdered
IEnumerable<KeyValuePair<TKey, TValue>> IterateOrdered()
Returns a sequence of all the key/value pairs in this dictionary, ordered by their keys.
Lookup
bool Lookup(TKey key, bool orEqual, out KeyValuePair<TKey, TValue> item)
Finds the closest key in the dictionary
key— Key that is being searchedorEqual— iffalsefind the next keyitem— Receives either the entry forkeyitself (if it exists, andorEqualistrue), or the next key in the dictionary
Returns: true if a key was found; otherwise, false
Remove
bool Remove(TKey key)
Removes the entry with the specified key from the dictionary.
key— The key of the entry to remove.
Returns: true if the value was found and removed from the dictionary; otherwise, false.
It is not allowed to remove keys while iterating on the dictionary at the same time!
RemoveRange
int RemoveRange(IEnumerable<TKey> keys)
Remove the entries with the specified keys from the dictionary.
keys— The keys of the entries to remove.
Returns: Number of entries that were found and removed.
It is not allowed to remove keys while iterating on the dictionary at the same time!
int RemoveRange(TKey begin, bool beginEqual, TKey end, bool endEqual)
Removes all the keys between two bounds
Scan
IEnumerable<KeyValuePair<TKey, TValue>> Scan(TKey begin, bool beginOrEqual, TKey end, bool endOrEqual)
Enumerate all the keys in the dictionary that are in the specified range
begin— Start of the rangebeginOrEqual— If true, thebeginkey is included in the rangeend— End of the rangeendOrEqual— If true, theendkey is included in the range
Returns: Unordered list of the all the keys in the dictionary that are in the range.
There is no guarantee in the actual order of the keys returned. It is also not allowed to remove keys while iterating over the sequence.
ScanReverse
IEnumerable<KeyValuePair<TKey, TValue>> ScanReverse(TKey begin, bool beginOrEqual, TKey end, bool endOrEqual)
Enumerate all the keys in the dictionary that are in the specified range
begin— Start of the rangebeginOrEqual— If true, thebeginkey is included in the rangeend— End of the rangeendOrEqual— If true, theendkey is included in the range
Returns: Unordered list of the all the keys in the dictionary that are in the range.
There is no guarantee in the actual order of the keys returned. It is also not allowed to remove keys while iterating over the sequence.
SetItem
void SetItem(TKey key, TValue value)
Sets the specified key and value in the immutable sorted dictionary, possibly overwriting an existing value for the given key.
key— The key of the entry to add.value— The key value to set.
TryGetKey
bool TryGetKey(TKey equalKey, out TKey actualKey)
Determines whether this dictionary contains a specified key.
equalKey— The key to search for.actualKey— The matching key located in the dictionary if found, orequalKeyif no match is found.
Returns: true if a match for equalKey is found; otherwise, false.
TryGetKeyValue
bool TryGetKeyValue(TKey key, out KeyValuePair<TKey, TValue> entry)
Gets the existing key and value associated with the specified key.
key— The key to search for.entry— The matching key and value pair located in the dictionary if found.
Returns: true if a match for key is found; otherwise, false.
TryGetValue
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
key— The key to search for.
Returns: true if a match for key is found; otherwise, false.