cutil/oldlist.h File Reference

#include "cutil.h"

Go to the source code of this file.

Classes

Defines

Typedefs

Functions


Define Documentation

#define copy_first ( l1,
l2   )     (l2=push(l2, first(l1)))

Do the appropriate kind a push operation to copy the first node from one list to another.

Definition at line 155 of file oldlist.h.

Referenced by reverse().

#define first (  )     ((l) ? (l)->node : NIL)

Definition at line 149 of file oldlist.h.

Referenced by AddToNormProtosList(), AlternativeChoicesWorseThan(), AmbigsFound(), append_number_choices(), BlobMicroFeatures(), CleanUpUnusedData(), ComputeChiSquared(), ComputeNormMatch(), ComputeOutlineStats(), ComputePrototypes(), copy_choices(), CurrentBestChoiceAdjustFactor(), CurrentBestChoiceIs(), cutline(), dawg_permute(), dawg_permute_and_select(), DebugWordChoices(), delete_d(), destroy_nodes(), display_edgepts(), ExtractMicros(), ExtractOutlineFeatures(), ExtractPicoFeatures(), FilterWordChoices(), FindClass(), FindClassifierErrors(), FindList(), FreeClusterer(), FreeLabeledClassList(), FreeMFOutline(), FreeNormProtoList(), FreeTrainingSamples(), GetBuckets(), insert(), LogNewSplit(), LogNewWordChoice(), MainSignalHandler(), NextSample(), NormalizeOutlines(), number_permute(), number_permute_and_select(), NumberOfProtos(), permute_compound_words(), permute_top_choice(), print_matrix(), read_variables(), RemoveInsignificantProtos(), s_adjoin(), search(), SetUpForClustering(), SetUpForFloat2Int(), word_associator(), WriteAdaptedClass(), WriteMergedTrainingSamples(), WriteMicrofeat(), WriteNormProtos(), WriteProtoList(), WriteProtos(), and WriteTrainingSamples().

#define iterate (  )     for (; (l) != NIL; (l) = rest (l))

Visit each node in the list.

Replace the old list with the list minus the head. Continue until the list is NIL.

Definition at line 164 of file oldlist.h.

Referenced by AddToNormProtosList(), AlternativeChoicesWorseThan(), AmbigsFound(), BlobMicroFeatures(), CleanUpUnusedData(), ComputeNormMatch(), ComputeOutlineStats(), count(), DebugWordChoices(), display_edgepts(), ExtractMicros(), ExtractOutlineFeatures(), ExtractPicoFeatures(), FindClass(), FindList(), FreeClusterer(), FreeLabeledClassList(), FreeNormProtoList(), FreeTrainingSamples(), LogNewSplit(), LogNewWordChoice(), MainSignalHandler(), NormalizeOutlines(), nth_cell(), NumberOfProtos(), print_choices(), read_variables(), RemoveInsignificantProtos(), reverse(), s_adjoin(), search(), SetUpForClustering(), SetUpForFloat2Int(), SmearBulges(), WriteAdaptedClass(), WriteMergedTrainingSamples(), WriteMicrofeat(), WriteNormProtos(), WriteProtoList(), WriteProtos(), and WriteTrainingSamples().

#define iterate_list ( x,
 )     for ((x)=(l); (x)!=0; (x)=rest(x))

Visit each node in the list (l).

Use a local variable (x) to iterate through all of the list cells. This macro is identical to iterate except that it does not lose the original list.

Definition at line 174 of file oldlist.h.

Referenced by copy_choices(), dawg_permute(), number_permute(), and permute_top_choice().

#define JOIN_ON ( list1,
list2   )     ((list1) = join ((list1), (list2)))

Add another list onto the tail of this one.

The list given as an input parameter is modified.

Definition at line 182 of file oldlist.h.

Referenced by append_next_choice(), and append_number_choices().

#define NIL   (LIST) 0

Definition at line 122 of file oldlist.h.

Referenced by AcceptableResult(), AdaptiveClassifier(), AddLargeSpeckleTo(), AddSignalMenuItem(), BlobMicroFeatures(), CharNormalizeOutline(), ComputePrototypes(), ConvertBlob(), ConvertMatchesToChoices(), ConvertOutline(), copy_choices(), CurrentBestChoiceAdjustFactor(), CurrentBestChoiceIs(), CurrentWordAmbig(), dawg_permute(), dawg_permute_and_select(), delete_d(), destroy(), destroy_nodes(), draw_blob_edges(), evaluate_chunks(), FillAmbigTable(), FilterWordChoices(), FindClassifierErrors(), free_variables(), FreeMFOutline(), get_match_by_bounds(), improve_one_blob(), InitChoiceAccum(), insert(), join(), last(), LogNewWordChoice(), MainSignalHandler(), NewAdaptedClass(), NewLabeledList(), NewTempConfig(), NormalizeOutline(), number_permute(), number_permute_and_select(), pop(), print_choices(), push_last(), rating_priority(), read_list(), ReadAdaptedClass(), ReadNormProtos(), ReadTrainingSamples(), record_piece_ratings(), RemoveInsignificantProtos(), reverse(), search(), select_blob_to_split(), and SmearExtremities().

#define pop_off ( list   )     ((list) = pop (list))

Add a cell onto the front of a list.

The list given as an input parameter is modified.

Definition at line 190 of file oldlist.h.

Referenced by append_number_choices(), dawg_permute_and_select(), and number_permute_and_select().

#define push_on ( list,
thing   )     ((list) = push (list, (LIST) (thing)))

Add a cell onto the front of a list.

The list given as an input parameter is modified.

Definition at line 198 of file oldlist.h.

Referenced by append_next_choice(), append_number_choices(), and draw_blob_edges().

#define rest (  )     ((l) ? (l)->next : NIL)

Definition at line 148 of file oldlist.h.

Referenced by AcceptableResult(), AlternativeChoicesWorseThan(), CurrentWordAmbig(), delete_d(), destroy(), FilterWordChoices(), FreeMFOutline(), insert(), last(), LogNewWordChoice(), permute_top_choice(), and pop().

#define second (  )     first (rest (l))

Return the contents of the second list element.

#define second(l) first (rest (l))

Definition at line 206 of file oldlist.h.

Referenced by FilterWordChoices(), and print_matrix().

#define set_rest ( l,
cell   )     ((l)->next = (cell))

Change the "next" field of a list element to point to a desired place.

#define set_rest(l,node) l->next = node;

Definition at line 214 of file oldlist.h.

Referenced by delete_d(), FilterWordChoices(), FreeMFOutline(), insert(), join(), LogNewWordChoice(), and push().

#define third (  )     first (rest (rest (l)))

Return the contents of the third list element.

#define third(l) first (rest (rest (l)))

Definition at line 222 of file oldlist.h.

Referenced by print_matrix().


Typedef Documentation

_LIST_

Type of list_rec, pointers to node and next node.

LIST

Pointer to _LIST_ which holds one node of a list, pointers to node and next node.

Definition at line 142 of file oldlist.h.


Function Documentation

int count ( LIST  var_list  ) 

Recursively count the elements in a list.

Return the count.

Definition at line 102 of file oldlist.cpp.

References iterate.

Referenced by REJMAP::accept_count(), AdaptiveClassifier(), apply_box_testing(), apply_box_training(), STATS::cluster(), POLY_BLOCK::contains(), count_alphanums(), count_alphas(), edgesteps_to_edgepts(), ExtractMicros(), find_modal_font(), fix_rep_char(), font_recognition_pass(), CLIST::internal_de_dump(), ELIST::internal_de_dump(), ELIST2::internal_de_dump(), CLIST::length(), ELIST::length(), ELIST2::length(), LogNewWordChoice(), POLY_BLOCK::overlap(), CLIST::prep_serialise(), ELIST::prep_serialise(), ELIST2::prep_serialise(), PrintAdaptedTemplates(), read_next_box(), CLIST::sort(), ELIST::sort(), ELIST2::sort(), POLY_BLOCK::winding_number(), and WriteAdaptedClass().

00102                          {
00103   int temp = 0;
00104 
00105   iterate (var_list) temp += 1;
00106   return (temp);
00107 }

LIST delete_d ( LIST  list,
void *  key,
int_compare  is_equal 
)

Delete all the elements out of the current list that match the key.

Parameters:
list The list
key Key
is_equal Routine that will compare each node to the key
Returns:
last value deleted ??
This operation destroys the original list. is_equal compares each node to the key, and returns a non-zero value when they match. If the value NULL is supplied for is_equal, the is_key routine will be used.

Definition at line 123 of file oldlist.cpp.

References first, is_same(), NIL, NULL, pop(), rest, and set_rest.

Referenced by FilterWordChoices(), GetBuckets(), LogNewWordChoice(), and MakePermanent().

00123                                                           {
00124   LIST result = NIL;
00125   LIST last_one = NIL;
00126 
00127   if (is_equal == NULL)
00128     is_equal = is_same;
00129 
00130   while (list != NIL) {
00131     if (!(*is_equal) (first (list), key)) {
00132       if (last_one == NIL) {
00133         last_one = list;
00134         list = rest (list);
00135         result = last_one;
00136         set_rest(last_one, NIL);
00137       }
00138       else {
00139         set_rest(last_one, list);
00140         last_one = list;
00141         list = rest (list);
00142         set_rest(last_one, NIL);
00143       }
00144     }
00145     else {
00146       list = pop (list);
00147     }
00148   }
00149   return (result);
00150 }

LIST destroy ( LIST  list  ) 

Return the space taken by a list to the heap.

Definition at line 156 of file oldlist.cpp.

References free_cell(), NIL, and rest.

Referenced by draw_blob_edges(), FreeLabeledClassList(), FreeLabeledList(), FreeNormProtoList(), FreeTrainingSamples(), reverse_d(), and IMAGE::~IMAGE().

00156                         {
00157   LIST next;
00158 
00159   while (list != NIL) {
00160     next = rest (list);
00161     free_cell(list);
00162     list = next;
00163   }
00164   return (NIL);
00165 }

void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Return the space taken by the LISTs of a list to the heap.

Definition at line 171 of file oldlist.cpp.

References first, memfree(), NIL, NULL, and pop().

Referenced by convert_choice_list(), EndDangerousAmbigs(), free_adapted_class(), free_variables(), FreeMicroFeatures(), FreeOutlines(), FreeProtoList(), FreeTempConfig(), init_match_table(), InitChoiceAccum(), and LogNewWordChoice().

00171                                                     {
00172   if (destructor == NULL)
00173     destructor = memfree;
00174 
00175   while (list != NIL) {
00176     (*destructor) (first (list));
00177     list = pop (list);
00178   }
00179 }

void insert ( LIST  list,
void *  node 
)

Create a list element and rearange the pointers so that the first element in the list is the second aurgment.

Definition at line 186 of file oldlist.cpp.

References first, NIL, push(), rest, and set_rest.

Referenced by s_adjoin().

00186                                    {
00187   LIST element;
00188 
00189   if (list != NIL) {
00190     element = push (NIL, node);
00191     set_rest (element, rest (list));
00192     set_rest(list, element);
00193     node = first (list);
00194     list->node = first (rest (list));
00195     list->next->node = (LIST) node;
00196   }
00197 }

int is_same ( void *  item1,
void *  item2 
)

Compare the list node with the key value return TRUE (non-zero) if they are equivalent strings. (Return FALSE if not).

Definition at line 213 of file oldlist.cpp.

Referenced by delete_d(), and search().

00213                                       {
00214   return (!strcmp ((char *) item1, (char *) item2));
00215 }

int is_same_node ( void *  item1,
void *  item2 
)

Compare the list node with the key value return TRUE (non-zero) if they are equivalent strings. (Return FALSE if not).

Definition at line 204 of file oldlist.cpp.

Referenced by LogNewWordChoice().

00204                                            {
00205   return (item1 == item2);
00206 }

LIST join ( LIST  list1,
LIST  list2 
)

Join the two lists together.

This function is similar to concat except that concat creates a new list. This function returns the first list updated.

Definition at line 224 of file oldlist.cpp.

References last(), NIL, and set_rest.

Referenced by h_edge(), and v_edge().

00224                                   {
00225   if (list1 == NIL)
00226     return (list2);
00227   set_rest (last (list1), list2);
00228   return (list1);
00229 }

LIST last ( LIST  var_list  ) 

Return the last list item (this is list type).

Definition at line 235 of file oldlist.cpp.

References NIL, and rest.

Referenced by AddLargeSpeckleTo(), CLIST::CLIST(), cutline(), ELIST::ELIST(), ELIST2::ELIST2(), CLIST::empty(), ELIST::empty(), ELIST2::empty(), CLIST::First(), ELIST::First(), ELIST2::First(), join(), push_last(), CLIST::shallow_copy(), ELIST::shallow_copy(), ELIST2::shallow_copy(), CLIST::singleton(), ELIST::singleton(), and ELIST2::singleton().

00235                          {
00236   while (rest (var_list) != NIL)
00237     var_list = rest (var_list);
00238   return (var_list);
00239 }

void* nth_cell ( LIST  var_list,
int  item_num 
)

Return nth list cell in the list.

Definition at line 245 of file oldlist.cpp.

References iterate.

Referenced by LogNewWordChoice().

00245                                             {
00246   int x = 0;
00247   iterate(var_list) {
00248     if (x++ == item_num)
00249       return (var_list);
00250   }
00251   return (var_list);
00252 }

LIST pop ( LIST  list  ) 

Return the list with the first element removed & destroys the space that it occupied in the list.

Definition at line 259 of file oldlist.cpp.

References free_cell(), NIL, and rest.

Referenced by ComputePrototypes(), delete_d(), destroy_nodes(), FreeMFOutline(), and NextSample().

00259                     {
00260   LIST temp;
00261 
00262   temp = rest (list);
00263 
00264   if (list != NIL) {
00265     free_cell(list);
00266   }
00267   return (temp);
00268 }

LIST push ( LIST  list,
void *  element 
)

Create a list element.

Push the second parameter (the node) onto the first parameter (the list). Return the new list to the caller.

Definition at line 277 of file oldlist.cpp.

References new_cell(), list_rec::node, and set_rest.

Referenced by add_32bit_variable(), add_ptr_variable(), AddToNormProtosList(), ComputeChiSquared(), ComputePrototypes(), ConvertOutline(), ConvertOutlines(), ConvertToMicroFeatures(), copy_choices(), FreeBuckets(), insert(), MakeNewAdaptedClass(), MakeNewTempProtos(), NextSample(), push_last(), read_list(), and ReadTrainingSamples().

00277                                     {
00278   LIST t;
00279 
00280   t = new_cell ();
00281   t->node = (LIST) element;
00282   set_rest(t, list);
00283   return (t);
00284 }

LIST push_last ( LIST  list,
void *  item 
)

Create a list element.

Add the element onto the end of the list.

Definition at line 292 of file oldlist.cpp.

References last(), list_rec::next, NIL, and push().

Referenced by append_choice(), FillAmbigTable(), ReadAdaptedClass(), ReadNormProtos(), and s_adjoin().

00292                                       {
00293   LIST t;
00294 
00295   if (list != NIL) {
00296     t = last (list);
00297     t->next = push (NIL, item);
00298     return (list);
00299   }
00300   else
00301     return (push (NIL, item));
00302 }

LIST reverse ( LIST  list  ) 

Create a new list with the elements reversed.

The old list is not destroyed.

Definition at line 310 of file oldlist.cpp.

References copy_first, iterate, and NIL.

Referenced by ELISTIZE_S(), and reverse_d().

00310                         {
00311   LIST newlist = NIL;
00312 
00313   iterate (list) copy_first (list, newlist);
00314   return (newlist);
00315 }

LIST reverse_d ( LIST  list  ) 

Create a new list with the elements reversed.

The old list is destroyed.

Definition at line 323 of file oldlist.cpp.

References destroy(), and reverse().

Referenced by copy_choices(), and read_list().

00323                           {
00324   LIST result = reverse (list);
00325   destroy(list);
00326   return (result);
00327 }

LIST s_adjoin ( LIST  var_list,
void *  variable,
int_compare  compare 
)

Adjoin an element to an assorted list.

The original list is modified. Returns the modified list.

Definition at line 335 of file oldlist.cpp.

References first, insert(), iterate, NULL, and push_last().

Referenced by AddSignalMenuItem(), and LogNewWordChoice().

00335                                                                   {
00336   LIST l;
00337   int result;
00338 
00339   if (compare == NULL)
00340     compare = (int_compare) strcmp;
00341 
00342   l = var_list;
00343   iterate(l) {
00344     result = (*compare) (variable, first (l));
00345     if (result == 0)
00346       return (var_list);
00347     else if (result < 0) {
00348       insert(l, variable);
00349       return (var_list);
00350     }
00351   }
00352   return (push_last (var_list, variable));
00353 }

LIST search ( LIST  list,
void *  key,
int_compare  is_equal 
)

Search list, return NIL if not found.

Return the list starting from the item if found. The compare routine "is_equal" is passed in as the third paramter to this routine. If the value NULL is supplied for is_equal, the is_key routine will be used.

Definition at line 364 of file oldlist.cpp.

References first, is_same(), iterate, NIL, and NULL.

Referenced by ComputeChiSquared(), GetBuckets(), and read_variables().

00364                                                         {
00365   if (is_equal == NULL)
00366     is_equal = is_same;
00367 
00368   iterate (list) if ((*is_equal) (first (list), key))
00369   return (list);
00370   return (NIL);
00371 }


Generated on Wed Feb 28 19:49:22 2007 for Tesseract by  doxygen 1.5.1