UniversalInsertNode

Inserts a node into a list.

Synopsis

void UniversalInsertNode( List *l, Node *n, bool (*f)(Node *n,Node *m) )

Description

Every node in a list has a priority (a value from 0 to 255 that is stored in the n_Priority field of the node structure). When a new node is inserted with InsertNodeFromHead() or InsertNodeFromTail(), the position at which it is added is determined by its priority. The UniversalInsertNode() procedure allows tasks to arrange list nodes according to values other than priority.

UniversalInsertNode() uses a comparison function provided by the calling task to determine where to insert a new node. It compares the node to be inserted with nodes already in the list, beginning with the first node. If the comparison function returns TRUE, the new node is inserted immediately before the node to which it was compared. If the comparison function never returns TRUE, the new node becomes the last node in the list. The comparison function, whose arguments are pointers to two nodes, can use any data in the nodes for the comparison.

Arguments

l
A pointer to the list into which to insert the node.
n
A pointer to the node to insert. This same pointer is passed as the first argument to the comparison function.
f
A comparison function provided by the calling task that returns TRUE if the node to be inserted (pointed to by the first argument to the function) should be inserted immediately before the node to which it is compared (pointed to by the second argument to the function).
m
A pointer to the node in the list to which to compare the node to insert.

Implementation

Folio call implemented in kernel folio V20.

Associated Files

list.h
ANSI C Prototype
clib.lib
ARM Link Library

Notes

A node can be included only in one list.

See Also

AddHead(), AddTail(), InsertNodeFromHead(), InsertNodeFromTail(), RemHead(), RemNode(), RemTail()