Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 78b5e16d1b
Fetching contributors…

Cannot retrieve contributors at this time

file 160 lines (126 sloc) 3.865 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
zlist(7)
========

NAME
----
zlist - generic type-free list container

SYNOPSIS
--------
----
// Create a new list container
zlist_t *
    zlist_new (void);

// Destroy a list container
void
    zlist_destroy (zlist_t **self_p);

// Return first item in the list, or null
void *
    zlist_first (zlist_t *self);

// Return last item in the list, or null
void *
    zlist_last (zlist_t *self);

// Return first item in the list, or null, leaves the cursor
void *
    zlist_head (zlist_t *self);

// Return last item in the list, or null, leaves the cursor
void *
    zlist_tail (zlist_t *self);

// Return next item in the list, or null
void *
    zlist_next (zlist_t *self);

// Append an item to the end of the list
int
    zlist_append (zlist_t *self, void *item);

// Push an item to the start of the list
int
    zlist_push (zlist_t *self, void *item);

// Pop the item off the start of the list, if any
void *
    zlist_pop (zlist_t *self);

// Remove the specified item from the list if present
void
    zlist_remove (zlist_t *self, void *item);

// Copy the entire list, return the copy
zlist_t *
    zlist_copy (zlist_t *self);

// Return number of items in the list
size_t
    zlist_size (zlist_t *self);

// Self test of this class
void
    zlist_test (int verbose);
----

DESCRIPTION
-----------

Provides a generic container implementing a fast singly-linked list. You
can use this to construct multi-dimensional lists, and other structures
together with other generic containers like zhash.


EXAMPLE
-------
.From zlist_test method
----
    zlist_t *list = zlist_new ();
    assert (list);
    assert (zlist_size (list) == 0);

    // Three items we'll use as test data
    // List items are void *, not particularly strings
    char *cheese = "boursin";
    char *bread = "baguette";
    char *wine = "bordeaux";

    zlist_append (list, cheese);
    assert (zlist_size (list) == 1);
    zlist_append (list, bread);
    assert (zlist_size (list) == 2);
    zlist_append (list, wine);
    assert (zlist_size (list) == 3);

    assert (zlist_head (list) == cheese);
    assert (zlist_next (list) == cheese);

    assert (zlist_first (list) == cheese);
    assert (zlist_tail (list) == wine);
    assert (zlist_next (list) == bread);

    assert (zlist_first (list) == cheese);
    assert (zlist_next (list) == bread);
    assert (zlist_next (list) == wine);
    assert (zlist_next (list) == NULL);
    // After we reach end of list, next wraps around
    assert (zlist_next (list) == cheese);
    assert (zlist_size (list) == 3);

    zlist_remove (list, wine);
    assert (zlist_size (list) == 2);

    assert (zlist_first (list) == cheese);
    zlist_remove (list, cheese);
    assert (zlist_size (list) == 1);
    assert (zlist_first (list) == bread);

    zlist_remove (list, bread);
    assert (zlist_size (list) == 0);

    zlist_append (list, cheese);
    zlist_append (list, bread);
    assert (zlist_last (list) == bread);
    zlist_remove (list, bread);
    assert (zlist_last (list) == cheese);
    zlist_remove (list, cheese);
    assert (zlist_last (list) == NULL);

    zlist_push (list, cheese);
    assert (zlist_size (list) == 1);
    assert (zlist_first (list) == cheese);

    zlist_push (list, bread);
    assert (zlist_size (list) == 2);
    assert (zlist_first (list) == bread);

    zlist_append (list, wine);
    assert (zlist_size (list) == 3);
    assert (zlist_first (list) == bread);

    char *item;
    item = (char *) zlist_pop (list);
    assert (item == bread);
    item = (char *) zlist_pop (list);
    assert (item == cheese);
    item = (char *) zlist_pop (list);
    assert (item == wine);
    assert (zlist_size (list) == 0);

    // Destructor should be safe to call twice
    zlist_destroy (&list);
    zlist_destroy (&list);
    assert (list == NULL);
----

SEE ALSO
--------
linkczmq:czmq[7]
Something went wrong with that request. Please try again.