Table of Contents

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

T

Value type.

Inherited Members
Extension Methods

Properties

Count

Gets the number of entries contained in this dictionary.

public readonly int Count { get; }

Property Value

int

IsEmpty

Specifies whether this dictionary is empty.

public bool IsEmpty { get; }

Property Value

bool

SegmentCount

Gets the number of segments contained in this dictionary.

public int SegmentCount { get; }

Property Value

int

SegmentLength

Specifies the length of each segment.

public readonly int SegmentLength { get; }

Property Value

int

Methods

AddOrUpdate(int, T)

Adds a new entry or updates existing if key already exists.

public AddOrUpdateResult AddOrUpdate(int key, T item)

Parameters

key int

Entry's key.

item T

Entry's value.

Returns

AddOrUpdateResult

Added when new entry has been added (provided key did not exist), otherwise Updated.

Exceptions

ArgumentOutOfRangeException

When key is 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

key int

Entry'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

minSegmentLength int

Minimum 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

key int

Key of a value to get or add.

exists bool

An out parameter that returns true when entry exists, otherwise false.

Returns

T

Reference to existing value or added default value.

Exceptions

ArgumentOutOfRangeException

When key is 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

key int

Key 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

key int

Key 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

key int

Key of an entry to remove.

removed T

An 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

key int

Entry's key.

item T

Entry's value.

Returns

bool

true when entry has been added (provided key did 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

key int

Key of a value to get.

result T

An out parameter that returns a value associated with the key, if it exists.

Returns

bool

true when entry exists, otherwise false.