IndexedList<TItem, TIndexer> Class

Summary

A System.Collections.Generic.List`1 which can remove items in O(1) time without searching and an inbuilt enumerator which supports modifications at any time (including during enumeration).
Assembly
Animancer.dll
Namespace
Animancer
Interfaces
Base Types
  • Object
Derived Types
graph BT Type-->Base0["Object"] Type-.->Interface0["IList<TItem>"] Type-.->Interface1["IReadOnlyIndexedList<TItem>"] Type-.->Interface2["IReadOnlyList<TItem>"] Type-.->Interface3["ICollection"] Type["IndexedList<TItem, TIndexer>"] class Type type-node Derived0["IUpdatable.List"]-->Type click Derived0 "/animancer/api/Animancer/List"

Syntax

public class IndexedList<TItem, TIndexer> : IList<TItem>, IReadOnlyIndexedList<TItem>, 
    IReadOnlyList<TItem>, ICollection
    where TItem : class where TIndexer : IIndexer<TItem>

Remarks

This implementation has several restrictions compared to a regular System.Collections.Generic.List`1:
  • Items cannot be null.
  • Items can only be in one at a time and cannot appear multiple times in it.

Type Parameters

Name Description
TItem
TIndexer

Constructors

Name Summary
IndexedList(int, TIndexer) Creates a new Animancer.IndexedList`2 with the specified initial `capacity`.
IndexedList(TIndexer) Creates a new Animancer.IndexedList`2 using the default System.Collections.Generic.List`1 constructor.

Fields

Name Constant Value Summary
DefaultCapacity
The default Animancer.IndexedList`2.Capacity which lists will expand to when their first item is added.
static
Indexer
The Animancer.IIndexer`1 used to access the details of items.
NotInList -1
The index which indicates that an item isn't in a list.
static

Properties

Name Value Summary
Capacity int
The number of items this list can contain before resizing is required.
Count int
The number of items currently in the list.
Current TItem
The item at the Animancer.IndexedList`2.CurrentIndex.
CurrentIndex int
If something is currently enumerating through this list, this value holds the index it's currently up to. Otherwise, this value will be negative.
IsEnumerating bool
Has Animancer.IndexedList`2.BeginEnumeraton been called and Animancer.IndexedList`2.TryEnumerateNext not yet been called enough times to go through all items?
this[int] TItem
The item at the specified `index`.

Methods

Name Value Summary
Add(TItem) bool
Adds the `item` to the end of this list if it wasn't already in it and returns true if successful.
BeginEnumeraton() void
Sets the Animancer.IndexedList`2.CurrentIndex to the end of this list so that Animancer.IndexedList`2.TryEnumerateNext can iterate backwards to the start.
CancelEnumeration() void
Clears the Animancer.IndexedList`2.CurrentIndex so that Animancer.IndexedList`2.BeginEnumeraton can be used again without needing to call Animancer.IndexedList`2.TryEnumerateNext repeatedly until it returns false.
Clear() void
Removes all items from this list.
Contains(TItem) bool
Is the `item` currently in this list?
Contains(TItem, int) bool
Is the `item` currently in this list at the specified `index`?
CopyTo(TItem[], int) void
Copies all the items from this list into the `array`, starting at the specified `index`.
DeepToString(string) string
Returns a string describing this list and its contents.
GetEnumerator() FastEnumerator<TItem>
Returns an enumerator which iterates through this list.
IndexOf(TItem) int
Returns the index of the `item` in this list or -1 if it's not in this list.
Insert(int, TItem) void
Adds the `item` to this list at the specified `index`.
Remove(TItem) bool
Removes the `item` by swapping the last item in this list into its place.
RemoveAt(int) void
Removes the item at the specified `index` by swapping the last item in this list into its place.
TryEnumerateNext() bool
Moves the Animancer.IndexedList`2.CurrentIndex so the Animancer.IndexedList`2.Current property points to the next item in this list.