The LevAWC Project
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
slist.h
Go to the documentation of this file.
1 /*
2  * _____
3  * ANSI / ___/
4  * / /__
5  * \___/
6  *
7  * Filename: slist.h
8  * Author : Kyle Loudon/Dan Levin
9  * Date : Fri Mar 22 12:40:45 GMT 2013
10  * Version : 0.51
11  * ---
12  * Description: A singly-linked list - implemented as a pure, generic ADT.
13  *
14  * Revision history - coming up below:
15  *
16  * Date Revision message
17  * 2012-12-03 Created this file
18  * 2013-02-05 Made following changes to function 'int SLISTremnode(Slist list, void **data)':
19  * - Changed function name to - 'int SLISTfind_remove(Slist list, void **data)'
20  * - Changed return value - for missing "match-callback"(=not set) - from -1 to -2
21  * - Changed return value - for node not found - from -1 to 1.
22  * 2013-02-19 Made some revision to the Doxygen documentation. Enhanced the description of
23  * in/out parameters - i.e. double-pointers.
24  * 2013-04-14 Added a new "getter" function - match_callback SLISTgetmatch(Slist list), that
25  * simply returns the reference to the formerly added match callback stored in
26  * the ADT header. The data type "match_callback" is the following typedef:
27  * typedef int (*match_callback)(const void *, const void *).
28  * 2015-03-31 This code ready for version 0.51
29  *
30  */
31 
36 #ifndef _SLIST_H_
37 #define _SLIST_H_
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <malloc.h>
43 #include <assert.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
53 #define SLIST_FWD 1
54 
58 #define SLIST_BWD -1
59 
65  typedef struct SList_ *Slist;
66 
72  typedef struct SListElmt_ *SlistNode;
73 
80  typedef int (*match_callback)(const void *, const void *);
81 
82  /* FUNCTION DECLARATIONS */
83 
100  Slist SLISTinit(void (*destroy)(void *data));
101 
116  void SLISTdestroy(Slist list);
117 
136  int SLISTinsnext(Slist list, SlistNode node, const void *data);
137 
156  int SLISTremnext(Slist list, SlistNode node, void **data);
157 
165  int SLISTsize(Slist list);
166 
173  SlistNode SLISThead(Slist list);
174 
181  SlistNode SLISTtail(Slist list);
182 
192  int SLISTishead(Slist list, SlistNode node);
193 
203  int SLISTistail(Slist list, SlistNode node);
204 
211  void *SLISTdata(SlistNode node);
212 
220  SlistNode SLISTnext(SlistNode node);
221 
242  SlistNode SLISTfindnode(Slist list, const void *data);
243 
257  void SLISTsetmatch(Slist list, int (*match)(const void *key1,
258  const void *key2));
259 
273  match_callback SLISTgetmatch(Slist list);
274 
309  int SLISTfind_remove(Slist list, void **data);
310 
318  void SLISTreverse(Slist list);
319 
336  void SLISTsort(Slist list, int (*cmp)(const void *key1, const void *key2));
337 
351  void SLISTtraverse(Slist list, void (*callback)(const void *data), int direction);
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 
357 #endif /* _SLIST_H_ */