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
TThe type of elements in the set, which must implement IPartitionedSetIndex.
- Inheritance
-
PartitionedSet<T>
- Implements
-
IEnumerable<T>
- 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
initialSizeintThe 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
Count
Gets the total number of elements in the set.
public int Count { get; }
Property Value
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
iint
Property Value
- T
Methods
Add(T, bool)
Adds an element to the set.
public void Add(T element, bool active = false)
Parameters
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
elementTThe element to locate.
Returns
GetEnumerator()
public PartitionedSet<T>.Enumerator GetEnumerator()
Returns
IsActive(T)
Determines whether the specified element is in the active partition.
public bool IsActive(T element)
Parameters
elementTThe element to check.
Returns
MoveToActive(T)
Moves an element to the active partition.
public bool MoveToActive(T element)
Parameters
elementTThe element to move.
Returns
MoveToInactive(T)
Moves an element to the inactive partition.
public bool MoveToInactive(T element)
Parameters
elementTThe element to move.
Returns
Remove(T)
Removes the specified element from the set.
public void Remove(T element)
Parameters
elementTThe element to remove.