Instead of using a ringbuffer for a polygon, where I need to copy elements when removing one item, I’d like to do this efficiently with a list, with O(1) overhead for removing any item and O(1) access to the currently updated next element without requiring special cases such as ringbuffer wrapping. No allocations are required.
This means, I’d like to have a closed-loop list. I’d like to know, if C# has a method for obtaining a node reference (or “node view”) element which allows me to obtain the next node element, access the node’s value, and without the arbitrary limitation of an immutable list.
In C++ e.g., it could look like this:
template<typename T> struct ListNode {
struct List *list;
struct ListNode *next, *previous;
T *value;
ListNode* insert(T *newValue);
ListNode* insertBefore(T *newValue);
void removeFromList();
void destroy();
};
struct List {
ListNode *firstNode, *lastNode;
unsigned int length;
};
(Don’t mind the code or the memory management, I only wrote it for better understanding.)
I could also write my own generic list type but I a custom implementation is not what I want. I’d like to know if .NET provides a solution here.