MISR Toolkit  1.5.1
linklist.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group. *
3  * Copyright by the Board of Trustees of the University of Illinois. *
4  * All rights reserved. *
5  * *
6  * This file is part of HDF. The full HDF copyright notice, including *
7  * terms governing use, modification, and redistribution, is contained in *
8  * the files COPYING and Copyright.html. COPYING can be found at the root *
9  * of the source code distribution tree; Copyright.html can be found at *
10  * http://hdfgroup.org/products/hdf4/doc/Copyright.html. If you do not have *
11  * access to either file, you may request a copy from help@hdfgroup.org. *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id: linklist.h 4932 2007-09-07 17:17:23Z bmribler $ */
15 
16 /*-----------------------------------------------------------------------------
17  * File: linklist.h
18  * Purpose: header file for linked list API
19  * Dependencies:
20  * Invokes:
21  * Contents:
22  * Structure definitions:
23  * Constant definitions:
24  *---------------------------------------------------------------------------*/
25 
26 /* avoid re-inclusion */
27 #ifndef __LINKLIST_H
28 #define __LINKLIST_H
29 
30 #include "hdf.h"
31 
32 /* Definitions for linked-list creation flags */
33 #define HUL_UNSORTED_LIST 0x0000
34 #define HUL_SORTED_LIST 0x0001
35 
36 /* Type of the function to compare objects & keys */
37 typedef intn (*HULsearch_func_t)(const VOIDP obj, const VOIDP key);
38 
39 /* Type of the function to compare two objects */
40 typedef intn (*HULfind_func_t)(const VOIDP obj1, const VOIDP obj2);
41 
42 /* Linked list information structure used */
43 typedef struct node_info_struct_tag {
44  VOIDP *obj_ptr; /* pointer associated with the linked list node */
45  struct node_info_struct_tag *next; /* link to list node */
46  }node_info_t;
47 
48 /* Linked list head structure */
49 typedef struct list_head_struct_tag {
50  uintn count; /* # of nodes in the list */
51  uintn flags; /* list creation flags */
52  HULfind_func_t cmp_func; /* node comparison function */
53  node_info_t *node_list; /* pointer to a linked list of nodes */
54  node_info_t *curr_node; /* pointer to the current node when iterating */
55  }list_head_t;
56 
57 #if defined LIST_MASTER | defined LIST_TESTER
58 
59 /* Define this in only one place */
60 #ifdef LIST_MASTER
61 /* Pointer to the list node free list */
62 static node_info_t *node_free_list=NULL;
63 
64 #endif /* LIST_MASTER */
65 
66 /* Useful routines for generally private use */
67 
68 #endif /* LIST_MASTER | LIST_TESTER */
69 
70 #if defined c_plusplus || defined __cplusplus
71 extern "C"
72 {
73 #endif /* c_plusplus || __cplusplus */
74 
75 /******************************************************************************
76  NAME
77  HULcreate_list - Create a linked list
78 
79  DESCRIPTION
80  Creates a linked list. The list may either be sorted or un-sorted, based
81  on the comparison function.
82 
83  RETURNS
84  Returns a pointer to the list if successful and NULL otherwise
85 
86 *******************************************************************************/
87 list_head_t *HULcreate_list(HULfind_func_t find_func /* IN: object comparison function */
88 );
89 
90 /******************************************************************************
91  NAME
92  HULdestroy_list - Destroys a linked list
93 
94  DESCRIPTION
95  Destroys a linked list created by HULcreate_list(). This function
96  walks through the list and frees all the nodes, then frees the list head.
97  Note: this function does not (currently) free the objects in the nodes,
98  it just leaves 'em hanging.
99 
100  RETURNS
101  Returns SUCCEED/FAIL.
102 
103 *******************************************************************************/
104 intn HULdestroy_list(list_head_t *lst /* IN: list to destroy */
105 );
106 
107 /******************************************************************************
108  NAME
109  HULadd_node - Adds an object to a linked-list
110 
111  DESCRIPTION
112  Adds an object to the linked list. If the list is sorted, the comparison
113  function is used to determine where to insert the node, otherwise it is
114  inserted at the head of the list.
115 
116  RETURNS
117  Returns SUCCEED/FAIL.
118 
119 *******************************************************************************/
120 intn HULadd_node(list_head_t *lst, /* IN: list to modify */
121  VOIDP obj /* IN: object to add to the list */
122 );
123 
124 /******************************************************************************
125  NAME
126  HULsearch_node - Search for an object in a linked-list
127 
128  DESCRIPTION
129  Locate an object in a linked list using a key and comparison function.
130 
131  RETURNS
132  Returns a pointer to the object found in the list, or NULL on failure.
133 
134 *******************************************************************************/
135 VOIDP HULsearch_node(list_head_t *lst, /* IN: list to search */
136  HULsearch_func_t srch_func, /* IN: function to use to find node */
137  VOIDP key /* IN: key of object to search for */
138 );
139 
140 /******************************************************************************
141  NAME
142  HULfirst_node - Get the first object in a linked-list
143 
144  DESCRIPTION
145  Returns the first object in a linked-list and prepares the list for
146  interating through.
147 
148  RETURNS
149  Returns a pointer to the first object found in the list, or NULL on failure.
150 
151 *******************************************************************************/
152 VOIDP HULfirst_node(list_head_t *lst /* IN: list to search */
153 );
154 
155 /******************************************************************************
156  NAME
157  HULnext_node - Get the next object in a linked-list
158 
159  DESCRIPTION
160  Returns the next object in a linked-list by walking through the list
161 
162  RETURNS
163  Returns a pointer to the next object found in the list, or NULL on failure.
164 
165 *******************************************************************************/
166 VOIDP HULnext_node(list_head_t *lst /* IN: list to search */
167 );
168 
169 /******************************************************************************
170  NAME
171  HULremove_node - Removes an object from a linked-list
172 
173  DESCRIPTION
174  Remove an object from a linked list. The key and comparison function are
175  provided locate the object to delete.
176 
177  RETURNS
178  Returns a pointer to the object deleted from the list, or NULL on failure.
179 
180 *******************************************************************************/
181 VOIDP HULremove_node(list_head_t *lst, /* IN: list to modify */
182  HULsearch_func_t srch_func, /* IN: function to use to find node to remove */
183  VOIDP key /* IN: object to add to the list */
184 );
185 
186 /*--------------------------------------------------------------------------
187  NAME
188  HULshutdown
189  PURPOSE
190  Terminate various global items.
191  USAGE
192  intn HULshutdown()
193  RETURNS
194  Returns SUCCEED/FAIL
195  DESCRIPTION
196  Free various buffers allocated in the HUL routines.
197  GLOBAL VARIABLES
198  COMMENTS, BUGS, ASSUMPTIONS
199  Should only ever be called by the "atexit" function HDFend
200  EXAMPLES
201  REVISION LOG
202 --------------------------------------------------------------------------*/
203 intn
204 HULshutdown(void);
205 
206 #if defined c_plusplus || defined __cplusplus
207 }
208 #endif /* c_plusplus || __cplusplus */
209 
210 #endif /* __LINKLIST_H */
211 
node_info_t * node_list
Definition: linklist.h:53
HULfind_func_t cmp_func
Definition: linklist.h:52
node_info_t * curr_node
Definition: linklist.h:54
struct node_info_struct_tag * next
Definition: linklist.h:45

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:52