snl - Generic Single Linked List

Module Description

The snl module implements a single linked list that can store variable size nodes. It is the base module for more specialised modules, for example the single linked cell list [scl] module.

Module Words

List structure

snl% ( -- n )
Get the required space for a snl variable

List creation, initialisation and destruction

snl-init ( snl -- )
Initialise the snl list

snl-(free) ( xt scl -- )
Free the nodes from the heap using xt

snl-create ( "<spaces>name" -- ; -- snl )
Create a named snl list in the dictionary

snl-new ( -- snl )
Create a new snl list on the heap

snl-free ( snl -- )
Free the list from the heap

Member words

snl-length@ ( snl -- u )
Get the number of nodes in the list

snl-empty? ( snl -- flag )
Check for an empty list

snl-first@ ( snl -- snn | nil )
Get the first node from the list

snl-last@ ( snl -- snn | nil )
Get the last node from the list

List words

snl-append ( snn snl -- )
Append the node snn to the list

snl-prepend ( snn snl -- )
Prepend the node snn in the list

snl-insert-after ( snn1 snn2 snl -- )
Insert the node snn1 after the reference node snn2 in the list

snl-remove-first ( snl -- snn | nil )
Remove the first node from the list, return the removed node

snl-remove-after ( snn1 snl -- snn2 | nil )
Remove the node after the reference node snn1 from the list, return the removed node

Index words

snl-index? ( n snl -- flag )
Check if the index n is valid in the list

snl-get ( n snl -- snn )
Get the nth node from the list

snl-insert ( snn n snl -- )
Insert a node before the nth node in the list

snl-delete ( n snl -- snn )
Delete the nth node from the list, return the deleted node

LIFO words

snl-push ( snn snl -- )
Push the node snn at the top of the stack [= start of the list]

snl-pop ( snl -- snn | nil )
Pop the node at the top of the stack [= start of the list], return the popped node

snl-tos ( snl -- snn | nil )
Get the node at the top of the stack [= start of the list], return this node

FIFO words

snl-enqueue ( snn snl -- )
Enqueue the node snn at the start of the queue [=end of the list]

snl-dequeue ( snl -- snn | nil )
Dequeue the node at the end of the queue [= start of the list], return this node

Special words

snl-execute ( i*x xt snl -- j*x )
Execute xt for every node in list

snl-execute? ( i*x xt snl -- j*x flag )
Execute xt for every node in the list until xt returns true

snl-reverse ( snl -- )
Reverse or mirror the list

Inspection

snl-dump ( snl -- )
Dump the list


generated 10-Apr-2008 by ofcfrth-0.5.0