Table of Contents

Class LazyLinkedList<T>

Namespace
Hi.Common.Collections
Assembly
HiGeom.dll

A singly-growable linked list that can lazily materialize nodes from an IEnumerable<T> source.

Without a source it behaves like a regular append-only linked list. With a source, nodes are pulled on demand when Next is accessed on the tail, or when First is accessed on an empty list.
public class LazyLinkedList<T> : IEnumerable<T>, IEnumerable, IDisposable

Type Parameters

T
Inheritance
LazyLinkedList<T>
Implements
Inherited Members
Extension Methods

Examples

// Lazy: nodes materialize as you walk .Next
using var list = new LazyLinkedList<string>(File.ReadLines(path));
var node = list.First;          // materializes line 0
var next = node.Next;           // materializes line 1

// Manual: just like a regular linked list
var list2 = new LazyLinkedList<int>();
list2.AddLast(1);
list2.AddLast(2);

Constructors

LazyLinkedList()

Creates an empty list (no lazy source).

public LazyLinkedList()

LazyLinkedList(IEnumerable<T>)

Creates a list backed by a lazy source. Nodes are materialized on demand via Next or First.

public LazyLinkedList(IEnumerable<T> source)

Parameters

source IEnumerable<T>

Properties

Count

Number of nodes currently materialized in the list.

public int Count { get; }

Property Value

int

First

Gets the first node, materializing from source if the list is empty.

public LazyLinkedListNode<T> First { get; }

Property Value

LazyLinkedListNode<T>

IsExhausted

Whether all items from the source have been materialized (or no source was provided).

public bool IsExhausted { get; }

Property Value

bool

Last

Gets the last materialized node in the list.

public LazyLinkedListNode<T> Last { get; }

Property Value

LazyLinkedListNode<T>

Methods

AddLast(T)

Appends a new node with the specified value to the end of the list.

public LazyLinkedListNode<T> AddLast(T value)

Parameters

value T

The value to add.

Returns

LazyLinkedListNode<T>

The newly created node.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator that can be used to iterate through the collection.