LinkedList

Source: lib/LinkedList.cs

This page is generated from the source by scripts/gen-reference.py.

LinkedList: a doubly linked list of unmanaged items in an Arena, built on Pool, with .NET's names.

var list = LinkedList<int>.Create(arena);
var two = list.AddLast(2);
list.AddFirst(1);
list.AddAfter(two, 3);
list.Remove(two);
foreach (int item in list) ...        // 1, 3

Each Add returns the node's handle, which finds it in O(1) for AddBefore, AddAfter, Remove and list[node] (the node: its Value, Previous and Next). A handle whose node was removed stops the program when used, and Remove returns false for it, instead of unlinking whatever is there now. A removed node's memory is reused by the next Add.

Like every collection, it is a handle to a header in its arena: copies share the same list, and default(LinkedList) is "not created".

A doubly linked list in an arena, with a handle for each node.

Members

Create

public static LinkedList<T> Create(Arena arena, int chunkSize = 64)

Returns a new list in arena, or a not-created one if it is out of memory.

IsCreated

public bool IsCreated

False for default(...): a list that was never created.

Count

public int Count

How many nodes the list holds.

First

public Handle<LinkedListNode<T>> First

The first node, or a null handle if the list is empty.

Last

public Handle<LinkedListNode<T>> Last

The last node, or a null handle if the list is empty.

this[]

public ref LinkedListNode<T> this[Handle<LinkedListNode<T>> node]

The node, to read or change its Value. A removed node stops the program.

AddFirst

public Handle<LinkedListNode<T>> AddFirst(T value)

Adds a node at the start. A null handle if the list isn't created or the arena is full.

AddLast

public Handle<LinkedListNode<T>> AddLast(T value)

Adds a node at the end. A null handle if the list isn't created or the arena is full.

AddAfter

public Handle<LinkedListNode<T>> AddAfter(
    Handle<LinkedListNode<T>> node,
    T value)

Adds a node right after node, which must be in the list.

AddBefore

public Handle<LinkedListNode<T>> AddBefore(
    Handle<LinkedListNode<T>> node,
    T value)

Adds a node right before node, which must be in the list.

Remove

public bool Remove(Handle<LinkedListNode<T>> node)

Takes the node out of the list. False if it was already removed.

RemoveFirst

public bool RemoveFirst()

Removes the first node. False if the list is empty.

RemoveLast

public bool RemoveLast()

Removes the last node. False if the list is empty.

Find

public Handle<LinkedListNode<T>> Find(T value)

The first node whose value equals value (EqualityComparer.Default), or a null handle.

Contains

public bool Contains(T value)

Whether a node's value equals value.

public bool Contains(Handle<LinkedListNode<T>> node)

Whether node is a node of the list that hasn't been removed.

Clear

public void Clear()

Removes every node; their handles are refused from then on.

GetEnumerator

public Enumerator GetEnumerator()

For foreach: the values, first to last, by ref.

LinkedListNode

A node of a LinkedList{T}: its value and its neighbours.

Value

public T Value

The item, to read or change in place.

Previous

public readonly Handle<LinkedListNode<T>> Previous

The node before this one, or a null handle at the start.

Next

public readonly Handle<LinkedListNode<T>> Next

The node after this one, or a null handle at the end.