Table of Contents

Class PartitionedSet<T>

Namespace
Jitter2.DataStructures
Assembly
Jitter2.dll

Represents a collection of objects that can be partitioned into active and inactive subsets.

public class PartitionedSet<T> : IEnumerable<T>, IEnumerable where T : class, IPartitionedSetIndex

Type Parameters

T

The type of elements in the set, which must implement IPartitionedSetIndex.

Inheritance
PartitionedSet<T>
Implements
Inherited Members

Remarks

The methods Add(T, bool), Remove(T), Contains(T), IsActive(T), MoveToActive(T), and MoveToInactive(T) all operate in O(1) time complexity.

Constructors

PartitionedSet(int)

Initializes a new instance of the PartitionedSet<T> class.

public PartitionedSet(int initialSize = 1024)

Parameters

initialSize int

The initial capacity of the internal array.

Properties

Active

Returns a span of active elements in the set.

public ReadOnlySpan<T> Active { get; }

Property Value

ReadOnlySpan<T>

ActiveCount

Gets the number of active elements in the set.

public int ActiveCount { get; }

Property Value

int

Count

Gets the total number of elements in the set.

public int Count { get; }

Property Value

int

Elements

Returns a span of all elements in the set.

public ReadOnlySpan<T> Elements { get; }

Property Value

ReadOnlySpan<T>

Inactive

Returns a span of inactive elements in the set.

public ReadOnlySpan<T> Inactive { get; }

Property Value

ReadOnlySpan<T>

this[int]

Gets the element at the specified index.

public T this[int i] { get; }

Parameters

i int

Property Value

T

Methods

Add(T, bool)

Adds an element to the set.

public void Add(T element, bool active = false)

Parameters

element T

The element to add.

active bool

If true, the element is added to the active partition.

AsSpan()

Returns a span of all elements in the set.

public Span<T> AsSpan()

Returns

Span<T>

Clear()

Removes all elements from the set.

public void Clear()

Contains(T)

Determines whether the set contains the specified element.

public bool Contains(T element)

Parameters

element T

The element to locate.

Returns

bool

true if the element is found; otherwise, false.

GetEnumerator()

public PartitionedSet<T>.Enumerator GetEnumerator()

Returns

PartitionedSet<T>.Enumerator

IsActive(T)

Determines whether the specified element is in the active partition.

public bool IsActive(T element)

Parameters

element T

The element to check.

Returns

bool

true if the element is active; otherwise, false.

MoveToActive(T)

Moves an element to the active partition.

public bool MoveToActive(T element)

Parameters

element T

The element to move.

Returns

bool

true if the element was moved; false if it was already active.

MoveToInactive(T)

Moves an element to the inactive partition.

public bool MoveToInactive(T element)

Parameters

element T

The element to move.

Returns

bool

true if the element was moved; false if it was already inactive.

Remove(T)

Removes the specified element from the set.

public void Remove(T element)

Parameters

element T

The element to remove.