7 /* circular list management
11 /* void ring_init(list)
14 /* void ring_prepend(list, element)
18 /* void ring_append(list, element)
22 /* RING *ring_pred(element)
25 /* RING *ring_succ(element)
28 /* void ring_detach(element)
31 /* RING_FOREACH(RING *element, RING *head)
33 /* This module manages circular, doubly-linked, lists. It provides
34 /* operations to initialize a list, to add or remove an element,
35 /* and to iterate over a list. Although the documentation appears
36 /* to emphasize the special role of the list head, each operation
37 /* can be applied to each list member.
39 /* Examples of applications: any sequence of objects such as queue,
40 /* unordered list, or stack. Typically, an application embeds a RING
41 /* structure into its own data structure, and uses the RING primitives
42 /* to maintain the linkage between application-specific data objects.
44 /* ring_init() initializes its argument to a list of just one element.
46 /* ring_append() appends the named element to the named list head.
48 /* ring_prepend() prepends the named element to the named list head.
50 /* ring_succ() returns the list element that follows its argument.
52 /* ring_pred() returns the list element that precedes its argument.
54 /* ring_detach() disconnects a list element from its neighbors
55 /* and closes the hole. This routine performs no implicit ring_init()
56 /* on the removed element.
58 /* RING_FOREACH() is a macro that expands to a for (... ; ... ; ...)
59 /* statement that iterates over each list element in forward order.
60 /* Upon completion, the \fIelement\fR variable is set equal to
61 /* \fIhead\fR. The list head itself is not treated as a list member.
65 /* The Secure Mailer license must be distributed with this software.
68 /* IBM T.J. Watson Research
70 /* Yorktown Heights, NY 10598, USA
73 /* System libraries. */
75 /* Application-specific. */
79 /* ring_init - initialize ring head */
84 ring
->pred
= ring
->succ
= ring
;
87 /* ring_append - insert entry after ring head */
89 void ring_append(ring
, entry
)
93 entry
->succ
= ring
->succ
;
95 ring
->succ
->pred
= entry
;
99 /* ring_prepend - insert new entry before ring head */
101 void ring_prepend(ring
, entry
)
105 entry
->pred
= ring
->pred
;
107 ring
->pred
->succ
= entry
;
111 /* ring_detach - remove entry from ring */
113 void ring_detach(entry
)
116 RING
*succ
= entry
->succ
;
117 RING
*pred
= entry
->pred
;
122 entry
->succ
= entry
->pred
= 0;