liveBook · Manning

Node

As explained in Go in Action, Second Edition

A node is a data-structure element that stores a value and links to neighboring elements in a linked list.

A node is an element in a linked list that stores a value and a pointer to the next node. Unlike slice elements, nodes need not occupy contiguous memory, allowing insertion and removal without shifting other elements. section 6.1

Go can make the node generic: node[T any] accepts any value type while preserving type safety. The same type parameter can flow into the stored value and the next-node pointer. section 6.1

Listing 6.1 A generic node implementation
type node[T any] struct { #1
	value T #2
	next  *node[T] #3
}

Inspect the minimal generic node definition, including its type parameter, stored value, and pointer to the next node. section 6.1

Nodes are useful for teaching generic data structures, although slices usually provide the simpler production choice in Go. section 6.1

How Go in Action, Second Edition covers it

How deep it goes
Defines the node fields and explains linked-list memory behavior, but stops short of a complete list implementation.
Examples
Uses node[T any] with value T and next *node[T] as the concrete implementation.
What you can do after
Build it from scratch: Define a generic node that links values into a type-safe linked-list structure.
How it connects
Connects nodes to linked lists, generics, type parameters, constraints, interfaces, and slices.

Also explained in

Compare how 19 books explain node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.