Struct SegmentedSparseDictionary<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a segmented collection of keys and values, where keys are of int type, greater than or equal to 0.
public struct SegmentedSparseDictionary<T>
Type Parameters
TValue type.
- Inherited Members
- Extension Methods
Properties
Count
Gets the number of entries contained in this dictionary.
public readonly int Count { get; }
Property Value
IsEmpty
Specifies whether this dictionary is empty.
public bool IsEmpty { get; }
Property Value
SegmentCount
Gets the number of segments contained in this dictionary.
public int SegmentCount { get; }
Property Value
SegmentLength
Specifies the length of each segment.
public readonly int SegmentLength { get; }
Property Value
Methods
AddOrUpdate(int, T)
Adds a new entry or updates existing if key already exists.
public AddOrUpdateResult AddOrUpdate(int key, T item)
Parameters
keyintEntry's key.
itemTEntry's value.
Returns
- AddOrUpdateResult
Added when new entry has been added (provided
keydid not exist), otherwise Updated.
Exceptions
- ArgumentOutOfRangeException
When
keyis less than 0.
Clear()
Removes all elements from this dictionary.
public void Clear()
ContainsKey(int)
Checks whether an entry with the provided key exists.
[Pure]
public bool ContainsKey(int key)
Parameters
keyintEntry's key to check.
Returns
- bool
true when entry exists, otherwise false.
Create(int)
Creates a new empty SegmentedSparseDictionary<T> instance.
[Pure]
public static SegmentedSparseDictionary<T> Create(int minSegmentLength)
Parameters
minSegmentLengthintMinimum length of each segment. Actual SegmentLength will be rounded up to the nearest power of two.
Returns
- SegmentedSparseDictionary<T>
New SegmentedSparseDictionary<T> instance.
GetEnumerator()
Creates a new SegmentedSparseDictionary<T>.Enumerator instance for this dictionary.
[Pure]
public SegmentedSparseDictionary<T>.Enumerator GetEnumerator()
Returns
- SegmentedSparseDictionary<T>.Enumerator
New SegmentedSparseDictionary<T>.Enumerator instance.
GetValueRefOrAddDefault(int, out bool)
Attempts to get a reference to a value associated with the specified key.
Adds a new entry with default value and returns a reference to it, if entry does not exist.
public ref T? GetValueRefOrAddDefault(int key, out bool exists)
Parameters
keyintKey of a value to get or add.
existsboolAn out parameter that returns true when entry exists, otherwise false.
Returns
- T
Reference to existing value or added default value.
Exceptions
- ArgumentOutOfRangeException
When
keyis less than 0.
GetValueRefOrNullRef(int)
Attempts to get a reference to a value associated with the specified key.
Returns a null reference, if entry does not exist.
public ref T GetValueRefOrNullRef(int key)
Parameters
keyintKey of a value to get.
Returns
- T
Reference to existing value or null reference.
Remove(int)
Attempts to remove an entry with the specified key.
public bool Remove(int key)
Parameters
keyintKey of an entry to remove.
Returns
- bool
true when entry has been removed, otherwise false.
Remove(int, out T)
Attempts to remove an entry with the specified key and to return a value associated with that key.
public bool Remove(int key, out T removed)
Parameters
keyintKey of an entry to remove.
removedTAn out parameter that returns a value associated with the
key, if it exists.
Returns
- bool
true when entry has been removed, otherwise false.
TrimExcess()
Attempts to remove unused segments from this dictionary.
public void TrimExcess()
TryAdd(int, T)
Attempts to add a new entry.
public bool TryAdd(int key, T item)
Parameters
keyintEntry's key.
itemTEntry's value.
Returns
- bool
true when entry has been added (provided
keydid not exist), otherwise false.
TryGetValue(int, out T)
Attempts to get a value associated with the specified key.
public bool TryGetValue(int key, out T result)
Parameters
keyintKey of a value to get.
resultTAn out parameter that returns a value associated with the
key, if it exists.
Returns
- bool
true when entry exists, otherwise false.