Coda Distributed File System
ds_list.h
Go to the documentation of this file.
1/*
2** The "list" data structure.
3*/
4
5#ifndef _DS_LIST_H_
6#define _DS_LIST_H_
7
8#include <odytypes.h>
9
10/*
11 Lists are an ordered set of elements of type T*.
12 They are generic containers. The only restriction on elements
13 is that they not be NULL.
14 They are not thread safe.
15 They can be ordered or not.
16 Ordered lists contain an sense of "orderedness", called order(i,j)
17 order(i,j) should form a total order, with equivalences
18 0 if i and j are "equivalent"
19 <0 if i should be before j
20 >0 if i should be after j
21 The "orderfulness" of a list affects it's mutators
22
23 Lists can be "safe" or "unsafe". Safe lists cannot be destroyed
24 unless they are empty.
25
26 Ordered lists can contain "duplicates," or "duplicates" can be
27 forbidden. If the list is unordered, two elements i,j are
28 "duplicates" iff they are pointer-equal. If the list is ordered,
29 two elements i,j are "duplicates" if order(i,j) == 0.
30
31 All list clients are responsible for allocation and deallocation of
32 list items.
33*/
34
35typedef struct ds_list_t ds_list_t; /* opaque list */
36
37/*
38 The following operations are allowed on lists:
39*/
40
41/*** Observers ***/
42
43/*
44 ds_list_valid returns TRUE if l has a valid list magic number.
45 ds_list_count returns the number of items in l.
46 ds_list_first returns the first element of l, or NULL if l is empty.
47 ds_list_first returns the last element of l, or NULL if l is empty.
48 ds_list_member returns e if l contains the argument e, NULL otherwise.
49 If the list is sorted, the ordering function is used to
50 test equality. If the list is unsorted, pointer-equality
51 of elements is used.
52*/
53
54extern bool ds_list_valid(ds_list_t *l); /* TRUE => looks like a list */
55extern int ds_list_count(ds_list_t *l); /* number of elements in list */
56extern void *ds_list_first(ds_list_t *l); /* return head element */
57extern void *ds_list_last(ds_list_t *l); /* return tail element */
58extern void *ds_list_member(ds_list_t *l, /* is e in l? */
59 void *e);
60
61/*** Mutators ***/
62
63/*
64 ds_list_create: create a new list
65 c is the comparison function for this list.
66 If c is NULL, the list is said to be "unordered"
67 If c is non-null, c should point to a valid comparison
68 function; it's a good idea for c to dynamically
69 typecheck it's arguments.
70 safe_destroy == FALSE; okay to delete a list without
71 checking to see that it is empty first.
72 dups_ok == TRUE; okay to insert duplicates.
73
74 ds_list_destroy: destroy the list. Asserts if list is safe and nonempty.
75 ds_list_insert: If l is unordered, insert i in l.
76 If l is ordered, inserts i s.t. all elements j
77 before i in l obey order(j,i) < 0.
78 returns it's argument if successful, or
79 NULL if list is a no-dup list, and i would be a dup.
80 ds_list_append: If l is unordered, append i to l.
81 If l is ordered, inserts i s.t. all elements j
82 after i in l obey order(i,j) < 0.
83 returns it's argument if successful, or
84 NULL if list is a no-dup list, and i would be a dup.
85 ds_list_get_first: Remove and return first element in l, or NULL if empty.
86 ds_list_get_first: Remove and return last element in l, or NULL if empty.
87 ds_list_remove: Remove the element denoted by it's argument.
88 The comparison function is used to test equality if
89 the list is sorted. If the list is unsorted, pointer
90 equality is used.
91 Returns its argument if successful, NULL if p not on l.
92*/
93
94extern ds_list_t *ds_list_create(COMPFN c, bool safe_destroy, bool dups_ok);
95extern void ds_list_destroy(ds_list_t *l);
96extern void *ds_list_insert(ds_list_t *l, void *i);
97extern void *ds_list_append(ds_list_t *l, void *i);
98extern void *ds_list_get_first(ds_list_t *l);
99extern void *ds_list_get_last(ds_list_t *l);
100extern void *ds_list_remove(ds_list_t *l, void *p);
101extern void ds_list_print(ds_list_t *l, bool forward, void (*printer)(void *));
102
103/*** Iterators ***/
104
105typedef struct ds_list_iter_t ds_list_iter_t; /* opaque */
106
107/*
108 You can create an interator, destroy an iterator,
109 or ask for the "next" element in the sequence. Iterators and
110 lists communicate with one another: if an iterator's "next" element
111 is removed from the iterator's list, the iterator will be advanced
112 one element. Once an iterator has reached the end of the list (i.e.
113 ds_list_iter_next returns NULL) it is considered closed: new items
114 added to the end of the list will not be picked up by the iterator.
115 New items added before an iterator's concpetion of "next" will also
116 not be picked up by the iterator. Frankly, twiddling the list while
117 the iterator is hooked up is kinda silly anyway.
118*/
119
122extern void *ds_list_iter_next(ds_list_iter_t *i);
123
124#endif /* _DS_LIST_H_ */
void ds_list_print(ds_list_t *l, bool forward, void(*printer)(void *))
Definition: ds_list.c:364
void ds_list_destroy(ds_list_t *l)
Definition: ds_list.c:136
bool ds_list_valid(ds_list_t *l)
Definition: ds_list.c:42
void * ds_list_append(ds_list_t *l, void *i)
Definition: ds_list.c:203
void * ds_list_first(ds_list_t *l)
Definition: ds_list.c:56
ds_list_iter_t * ds_list_iter_create(ds_list_t *l)
Definition: ds_list.c:386
void ds_list_iter_destroy(ds_list_iter_t *i)
Definition: ds_list.c:403
void * ds_list_remove(ds_list_t *l, void *p)
Definition: ds_list.c:317
void * ds_list_member(ds_list_t *l, void *e)
Definition: ds_list.c:106
void * ds_list_get_first(ds_list_t *l)
Definition: ds_list.c:269
void * ds_list_insert(ds_list_t *l, void *i)
Definition: ds_list.c:151
int ds_list_count(ds_list_t *l)
Definition: ds_list.c:50
void * ds_list_get_last(ds_list_t *l)
Definition: ds_list.c:293
ds_list_t * ds_list_create(COMPFN c, bool safe_destroy, bool dups_ok)
Definition: ds_list.c:119
void * ds_list_last(ds_list_t *l)
Definition: ds_list.c:67
void * ds_list_iter_next(ds_list_iter_t *i)
Definition: ds_list.c:436
typdef int(* COMPFN)()
Definition: odytypes.h:54
Definition: ds_list.private.h:52
Definition: ds_list.private.h:41
char c
Definition: tdb.c:54