tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
oldlist.h
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: oldlist.h (Formerly list.h)
5  * Description: List processing procedures declarations.
6  * Author: Mark Seaman, SW Productivity
7  *
8  * (c) Copyright 1987, Hewlett-Packard Company.
9  ** Licensed under the Apache License, Version 2.0 (the "License");
10  ** you may not use this file except in compliance with the License.
11  ** You may obtain a copy of the License at
12  ** http://www.apache.org/licenses/LICENSE-2.0
13  ** Unless required by applicable law or agreed to in writing, software
14  ** distributed under the License is distributed on an "AS IS" BASIS,
15  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  ** See the License for the specific language governing permissions and
17  ** limitations under the License.
18  *
19  ********************************************************************************
20  *
21  * This file contains the interface for a set of general purpose list
22  * manipulation routines. For the implementation of these routines see
23  * the file "list.c".
24  *
25  ********************************************************************************
26  *
27  * INDEX
28  * =======
29  *
30  * BASICS:
31  * -------
32  * first_node - Macro to return the first list node (not the cell).
33  * list_rest - Macro the return the second list cell
34  * pop - Destroy one list cell
35  * push - Create one list cell and set the node and next fields
36  *
37  * ITERATION:
38  * -----------------
39  * iterate - Macro to create a for loop to visit each cell.
40  * iterate_list - Macro to visit each cell using a local variable.
41  * for_each - Applies a function to each node.
42  *
43  * LIST CELL COUNTS:
44  * -----------------
45  * count - Returns the number of list cells in the list.
46  * second_node - Returns the second node.
47  * third - Returns the third node.
48  * fourth - Returns the fourth node.
49  * fifth - Returns the fifth node.
50  * last - Returns the last list cell.
51  * pair - Creates a list of two elements.
52  *
53  * COPYING:
54  * -----------------
55  * copy_first - Pushes the first element from list 1 onto list 2.
56  * copy - Create a copy of a list.
57  * concat - Creates a new list that is a copy of both input lists.
58  * delete_n - Creates a new list without the chosen elements.
59  * reverse - Creates a backwards copy of the input list.
60  * sort - Use quick sort to construct a new list.
61  * transform - Creates a new list by transforming each of the nodes.
62  *
63  * TRANSFORMS: (Note: These functions all modify the input list.)
64  * ----------
65  * join - Concatenates list 1 and list 2.
66  * delete_d - Removes the requested elements from the list.
67  * transform_d - Modifies the list by applying a function to each node.
68  * insert - Add a new element into this spot in a list. (not
69  *NIL_LIST) push_last - Add a new element onto the end of a list.
70  * reverse_d - Reverse a list and destroy the old one.
71  *
72  * ASSOCIATED LISTS:
73  * -----------------
74  * adelete - Remove a particular entry from an associated list.
75  * assoc - Find an entry in an associated list that matches a key.
76  * match - Return the data element of an a-list entry.
77  *
78  * DISPLAY:
79  * -----------------
80  * print_cell - Print a hex dump of a list cell.
81  * show - Displays a string and a list (using lprint).
82  *
83  * SETS:
84  * -----
85  * adjoin - Add a new element to list if it does not exist already.
86  * intersection - Create a new list that is the set intersection.
87  * set_union - Create a new list that is the set intersection.
88  * set_difference - Create a new list that is the set difference.
89  * s_adjoin - Add an element to a sort list if it is not there.
90  * s_intersection - Set intersection on a sorted list. Modifies old list.
91  * s_union - Set intersection on a sorted list. Modifies old list.
92  * search - Return the pointer to the list cell whose node matches.
93  *
94  * COMPARISONS:
95  * -----------------
96  * is_same - Compares each node to the key.
97  * is_not_same - Compares each node to the key.
98  * is_key - Compares first of each node to the key.
99  * is_not_key - Compares first of each node to the key.
100  *
101  * CELL OPERATIONS:
102  * -----------------
103  * new_cell - Obtain a new list cell from the free list. Allocate.
104  * free_cell - Return a list cell to the free list.
105  * destroy - Return all list cells in a list.
106  * destroy_nodes - Apply a function to each list cell and destroy the list.
107  * set_node - Assign the node field in a list cell.
108  * set_rest - Assign the next field in a list cell.
109  *
110  ***********************************************************************/
111 
112 #ifndef LIST_H
113 #define LIST_H
114 
115 #include "cutil.h" // for int_compare, void_dest, ...
116 #include "tesscallback.h"
117 
118 /*----------------------------------------------------------------------
119  T y p e s
120 ----------------------------------------------------------------------*/
121 
122 #define NIL_LIST ((LIST)nullptr)
123 
124 struct list_rec
125 {
126  struct list_rec *node;
127  struct list_rec *next;
128 };
129 using LIST = list_rec *;
130 
131 /*----------------------------------------------------------------------
132  M a c r o s
133 ----------------------------------------------------------------------*/
134 /* Predefinitions */
135 #define list_rest(l) ((l) ? (l)->next : NIL_LIST)
136 #define first_node(l) ((l) ? (l)->node : NIL_LIST)
137 
138 /**********************************************************************
139  * c o p y f i r s t
140  *
141  * Do the appropriate kind a push operation to copy the first node from
142  * one list to another.
143  *
144  **********************************************************************/
145 
146 #define copy_first(l1,l2) \
147 (l2=push(l2, first_node(l1)))
148 
149 /**********************************************************************
150  * i t e r a t e
151  *
152  * Visit each node in the list. Replace the old list with the list
153  * minus the head. Continue until the list is NIL_LIST.
154  **********************************************************************/
155 
156 #define iterate(l) \
157 for (; (l) != NIL_LIST; (l) = list_rest (l))
158 
159 /**********************************************************************
160  * i t e r a t e l i s t
161  *
162  * Visit each node in the list (l). Use a local variable (x) to iterate
163  * through all of the list cells. This macro is identical to iterate
164  * except that it does not lose the original list.
165  **********************************************************************/
166 
167 #define iterate_list(x,l) \
168 for ((x)=(l); (x)!=0; (x)=list_rest(x))
169 
170 /**********************************************************************
171  * j o i n o n
172  *
173  * Add another list onto the tail of this one. The list given as an input
174  * parameter is modified.
175  **********************************************************************/
176 
177 #define JOIN_ON(list1,list2) \
178 ((list1) = join ((list1), (list2)))
179 
180 /**********************************************************************
181  * p o p o f f
182  *
183  * Add a cell onto the front of a list. The list given as an input
184  * parameter is modified.
185  **********************************************************************/
186 
187 #define pop_off(list) \
188 ((list) = pop (list))
189 
190 /**********************************************************************
191  * p u s h o n
192  *
193  * Add a cell onto the front of a list. The list given as an input
194  * parameter is modified.
195  **********************************************************************/
196 
197 #define push_on(list,thing) \
198 ((list) = push (list, (LIST) (thing)))
199 
200 /**********************************************************************
201  * s e c o n d
202  *
203  * Return the contents of the second list element.
204  *
205  * #define second_node(l) first_node (list_rest (l))
206  **********************************************************************/
207 
208 #define second_node(l) \
209 first_node (list_rest (l))
210 
211 /**********************************************************************
212  * s e t r e s t
213  *
214  * Change the "next" field of a list element to point to a desired place.
215  *
216  * #define set_rest(l,node) l->next = node;
217  **********************************************************************/
218 
219 #define set_rest(l,cell)\
220 ((l)->next = (cell))
221 
222 /**********************************************************************
223  * t h i r d
224  *
225  * Return the contents of the third list element.
226  *
227  * #define third(l) first_node (list_rest (list_rest (l)))
228  **********************************************************************/
229 
230 #define third(l) \
231 first_node (list_rest (list_rest (l)))
232 
233 /*----------------------------------------------------------------------
234  Public Function Prototypes
235 ----------------------------------------------------------------------*/
236 int count(LIST var_list);
237 
238 LIST delete_d(LIST list, void *key, int_compare is_equal);
239 
240 LIST delete_d(LIST list, void *key,
242 
243 LIST destroy(LIST list);
244 
245 void destroy_nodes(LIST list, void_dest destructor);
246 
247 void insert(LIST list, void *node);
248 
249 int is_same(void *item1, void *item2);
250 
251 LIST join(LIST list1, LIST list2);
252 
253 LIST last(LIST var_list);
254 
255 void *nth_cell(LIST var_list, int item_num);
256 
257 LIST pop(LIST list);
258 
259 LIST push(LIST list, void *element);
260 
261 LIST push_last(LIST list, void *item);
262 
263 LIST reverse(LIST list);
264 
265 LIST reverse_d(LIST list);
266 
267 LIST s_adjoin(LIST var_list, void *variable, int_compare compare);
268 
269 LIST search(LIST list, void *key, int_compare is_equal);
270 
271 LIST search(LIST list, void *key, TessResultCallback2<int, void*, void*>*);
272 
273 #endif
struct list_rec * node
Definition: oldlist.h:126
struct list_rec * next
Definition: oldlist.h:127
Definition: oldlist.h:124
Definition: blamer.h:43