Tesseract  3.02
tesseract-ocr/cutil/oldlist.h
Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        list.h  (Formerly list.h)
00005  * Description:  List processing procedures declarations.
00006  * Author:       Mark Seaman, SW Productivity
00007  * Created:      Fri Oct 16 14:37:00 1987
00008  * Modified:     Wed Dec  5 15:43:17 1990 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Reusable Software Component
00012  *
00013  * (c) Copyright 1987, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  ********************************************************************************
00025  *
00026  * This file contains the interface for a set of general purpose list
00027  * manipulation routines.  For the implementation of these routines see
00028  * the file "list.c".
00029  *
00030  ********************************************************************************
00031  *
00032  *                            INDEX
00033  *                           =======
00034  *
00035  * BASICS:
00036  * -------
00037  * first_node        - Macro to return the first list node (not the cell).
00038  * list_rest         - Macro the return the second list cell
00039  * pop               - Destroy one list cell
00040  * push              - Create one list cell and set the node and next fields
00041  *
00042  * ITERATION:
00043  * -----------------
00044  * iterate           - Macro to create a for loop to visit each cell.
00045  * iterate_list      - Macro to visit each cell using a local variable.
00046  * for_each          - Applies a function to each node.
00047  *
00048  * LIST CELL COUNTS:
00049  * -----------------
00050  * count             - Returns the number of list cells in the list.
00051  * second_node       - Returns the second node.
00052  * third             - Returns the third node.
00053  * fourth            - Returns the fourth node.
00054  * fifth             - Returns the fifth node.
00055  * last              - Returns the last list cell.
00056  * pair              - Creates a list of two elements.
00057  *
00058  * COPYING:
00059  * -----------------
00060  * copy_first        - Pushes the first element from list 1 onto list 2.
00061  * copy              - Create a copy of a list.
00062  * concat            - Creates a new list that is a copy of both input lists.
00063  * delete_n          - Creates a new list without the chosen elements.
00064  * reverse           - Creates a backwards copy of the input list.
00065  * sort              - Use quick sort to construct a new list.
00066  * transform         - Creates a new list by transforming each of the nodes.
00067  *
00068  * TRANFORMS:             (Note: These functions all modify the input list.)
00069  * ----------
00070  * join              - Concatenates list 1 and list 2.
00071  * delete_d          - Removes the requested elements from the list.
00072  * transform_d       - Modifies the list by applying a function to each node.
00073  * insert            - Add a new element into this spot in a list. (not NIL_LIST)
00074  * push_last         - Add a new element onto the end of a list.
00075  * reverse_d         - Reverse a list and destroy the old one.
00076  *
00077  * ASSOCIATED LISTS:
00078  * -----------------
00079  * adelete           - Remove a particular entry from an associated list.
00080  * assoc             - Find an entry in an associated list that matches a key.
00081  * match             - Return the data element of an a-list entry.
00082  *
00083  * DISPLAY:
00084  * -----------------
00085  * print_cell        - Print a hex dump of a list cell.
00086  * show              - Displays a string and a list (using lprint).
00087  *
00088  * SETS:
00089  * -----
00090  * adjoin            - Add a new element to list if it does not exist already.
00091  * intersection      - Create a new list that is the set intersection.
00092  * set_union         - Create a new list that is the set intersection.
00093  * set_difference    - Create a new list that is the set difference.
00094  * s_adjoin          - Add an element to a sort list if it is not there.
00095  * s_intersection    - Set intersection on a sorted list. Modifies old list.
00096  * s_union           - Set intersection on a sorted list. Modifies old list.
00097  * search            - Return the pointer to the list cell whose node matches.
00098  *
00099  * COMPARISONS:
00100  * -----------------
00101  * is_same           - Compares each node to the key.
00102  * is_not_same       - Compares each node to the key.
00103  * is_key            - Compares first of each node to the key.
00104  * is_not_key        - Compares first of each node to the key.
00105  *
00106  * CELL OPERATIONS:
00107  * -----------------
00108  * new_cell          - Obtain a new list cell from the free list. Allocate.
00109  * free_cell         - Return a list cell to the free list.
00110  * destroy           - Return all list cells in a list.
00111  * destroy_nodes     - Apply a function to each list cell and destroy the list.
00112  * set_node          - Assign the node field in a list cell.
00113  * set_rest          - Assign the next field in a list cell.
00114  *
00115  ***********************************************************************/
00116 
00117 #ifndef LIST_H
00118 #define LIST_H
00119 
00120 #include "cutil.h"
00121 #include "tesscallback.h"
00122 
00123 /*----------------------------------------------------------------------
00124                   T y p e s
00125 ----------------------------------------------------------------------*/
00126 #define NIL_LIST  (LIST) 0
00127 struct list_rec
00128 {
00129   struct list_rec *node;
00130   struct list_rec *next;
00131 };
00132 typedef list_rec *LIST;
00133 
00134 /*----------------------------------------------------------------------
00135                   M a c r o s
00136 ----------------------------------------------------------------------*/
00137 /* Predefinitions */
00138 #define list_rest(l)  ((l) ? (l)->next : NIL_LIST)
00139 #define first_node(l) ((l) ? (l)->node : NIL_LIST)
00140 
00141 /**********************************************************************
00142  *  c o p y   f i r s t
00143  *
00144  *  Do the appropriate kind a push operation to copy the first node from
00145  *  one list to another.
00146  *
00147  **********************************************************************/
00148 
00149 #define copy_first(l1,l2)  \
00150 (l2=push(l2, first_node(l1)))
00151 
00152 /**********************************************************************
00153  *  i t e r a t e
00154  *
00155  *  Visit each node in the list.  Replace the old list with the list
00156  *  minus the head.  Continue until the list is NIL_LIST.
00157  **********************************************************************/
00158 
00159 #define iterate(l)             \
00160 for (; (l) != NIL_LIST; (l) = list_rest (l))
00161 
00162 /**********************************************************************
00163  *  i t e r a t e   l i s t
00164  *
00165  *  Visit each node in the list (l).  Use a local variable (x) to iterate
00166  *  through all of the list cells.  This macro is identical to iterate
00167  *  except that it does not lose the original list.
00168  **********************************************************************/
00169 
00170 #define iterate_list(x,l)  \
00171 for ((x)=(l); (x)!=0; (x)=list_rest(x))
00172 
00173 /**********************************************************************
00174  * j o i n   o n
00175  *
00176  * Add another list onto the tail of this one.  The list given as an input
00177  * parameter is modified.
00178  **********************************************************************/
00179 
00180 #define JOIN_ON(list1,list2)    \
00181 ((list1) = join ((list1), (list2)))
00182 
00183 /**********************************************************************
00184  * p o p   o f f
00185  *
00186  * Add a cell onto the front of a list.  The list given as an input
00187  * parameter is modified.
00188  **********************************************************************/
00189 
00190 #define pop_off(list)    \
00191 ((list) = pop (list))
00192 
00193 /**********************************************************************
00194  * p u s h   o n
00195  *
00196  * Add a cell onto the front of a list.  The list given as an input
00197  * parameter is modified.
00198  **********************************************************************/
00199 
00200 #define push_on(list,thing)    \
00201 ((list) = push (list, (LIST) (thing)))
00202 
00203 /**********************************************************************
00204  *  s e c o n d
00205  *
00206  *  Return the contents of the second list element.
00207  *
00208  *  #define second_node(l)    first_node (list_rest (l))
00209  **********************************************************************/
00210 
00211 #define second_node(l)              \
00212 first_node (list_rest (l))
00213 
00214 /**********************************************************************
00215  *  s e t   r e s t
00216  *
00217  *  Change the "next" field of a list element to point to a desired place.
00218  *
00219  *  #define set_rest(l,node)        l->next = node;
00220  **********************************************************************/
00221 
00222 #define set_rest(l,cell)\
00223 ((l)->next = (cell))
00224 
00225 /**********************************************************************
00226  *  t h i r d
00227  *
00228  *  Return the contents of the third list element.
00229  *
00230  *  #define third(l)     first_node (list_rest (list_rest (l)))
00231  **********************************************************************/
00232 
00233 #define third(l)               \
00234 first_node (list_rest (list_rest (l)))
00235 
00236 /*----------------------------------------------------------------------
00237           Public Funtion Prototypes
00238 ----------------------------------------------------------------------*/
00239 int count(LIST var_list);
00240 
00241 LIST delete_d(LIST list, void *key, int_compare is_equal);
00242 
00243 LIST delete_d(LIST list, void *key,
00244               TessResultCallback2<int, void*, void*>* is_equal);
00245 
00246 LIST destroy(LIST list);
00247 
00248 void destroy_nodes(LIST list, void_dest destructor);
00249 
00250 void insert(LIST list, void *node);
00251 
00252 int is_same_node(void *item1, void *item2);
00253 
00254 int is_same(void *item1, void *item2);
00255 
00256 LIST join(LIST list1, LIST list2);
00257 
00258 LIST last(LIST var_list);
00259 
00260 void *nth_cell(LIST var_list, int item_num);
00261 
00262 LIST pop(LIST list);
00263 
00264 LIST push(LIST list, void *element);
00265 
00266 LIST push_last(LIST list, void *item);
00267 
00268 LIST reverse(LIST list);
00269 
00270 LIST reverse_d(LIST list);
00271 
00272 LIST s_adjoin(LIST var_list, void *variable, int_compare compare);
00273 
00274 LIST search(LIST list, void *key, int_compare is_equal);
00275 
00276 LIST search(LIST list, void *key, TessResultCallback2<int, void*, void*>*);
00277 
00278 /*
00279 #if defined(__STDC__) || defined(__cplusplus)
00280 # define _ARGS(s) s
00281 #else
00282 # define _ARGS(s) ()
00283 #endif
00284 
00285 typedef void  (*destructor)   _ARGS((LIST l));
00286 
00287 typedef LIST  (*list_proc)    _ARGS((LIST a));
00288 
00289 int count
00290 _ARGS((LIST var_list));
00291 
00292 LIST delete_d
00293 _ARGS((LIST list,
00294     LIST key,
00295     int_compare is_equal));
00296 
00297 LIST destroy
00298 _ARGS((LIST list));
00299 
00300 LIST destroy_nodes
00301 _ARGS((LIST list,
00302     void_dest destructor));
00303 
00304 void insert
00305 _ARGS((LIST list,
00306     LIST node));
00307 
00308 int is_same_node
00309 _ARGS((LIST s1,
00310     LIST s2));
00311 
00312 int is_same
00313 _ARGS((LIST s1,
00314     LIST s2));
00315 
00316 LIST join
00317 _ARGS((LIST list1,
00318     LIST list2));
00319 
00320 LIST last
00321 _ARGS((LIST var_list));
00322 
00323 LIST nth_cell
00324 _ARGS((LIST var_list,
00325     int item_num));
00326 
00327 LIST pop
00328 _ARGS((LIST list));
00329 
00330 LIST push
00331 _ARGS((LIST list,
00332     LIST element));
00333 
00334 LIST push_last
00335 _ARGS((LIST list,
00336     LIST item));
00337 
00338 LIST reverse
00339 _ARGS((LIST list));
00340 
00341 LIST reverse_d
00342 _ARGS((LIST list));
00343 
00344 LIST s_adjoin
00345 _ARGS((LIST var_list,
00346     LIST variable,
00347     int_compare compare));
00348 
00349 LIST search
00350 _ARGS((LIST list,
00351     LIST key,
00352     int_compare is_equal));
00353 
00354 #undef _ARGS
00355 */
00356 #endif