-
Notifications
You must be signed in to change notification settings - Fork 16
CircularList
ikopylov edited this page Jan 15, 2016
·
1 revision
CircularList<T>
is the collection that has similar interface as BCL List<T>
, but internally uses a circullar buffer to store the items. That means that adding and removing items from both side of the collection has O(1) cost.
Sample:
var circularList = new CircularList<int>();
// Adding
circularList.Add(0);
circularList.AddLast(1);
circularList.AddFirst(2);
circularList.Insert(0, 3);
// Removing
int val = circularList.RemoveLast();
int val2 = circularList.RemoveFirst();
circularList.RemoveAt(0);
// Reading
int rVal = circularList[0];
int index = circularList.IndexOf(1);
bool hasItem = circularList.Contains(1);
// Updating
circularList[0] = 100;