#include "oldlist.h"
#include "structures.h"
#include <stdio.h>
#include "freelist.h"
Go to the source code of this file.
#define add_on | ( | l, | |||
x | ) | l = push (l,first (x)) |
To implement a STACK use: push To add to the Stack l = push (l, (LIST) "jim"); pop To remove items from the Stack l = pop (l); first To access the head name = (char *) first (l); To implement a QUEUE use: push_last To add to the Queue l = push_last (l, (LIST) "jim"); pop Remove items from the Queue l = pop (l); first To access the head name = (char *) first (l); To implement LISP like functions use: first CAR x = (int) first (l); rest CDR l = rest (l); push CONS l = push (l, (LIST) this); last LAST x = last (l); concat APPEND l = concat (r, s); count LENGTH x = count (l); search MEMBER if (search (l, x, NULL)) To implement SETS use: adjoin l = adjoin (l, x); set_union l = set_union (r, s); intersection l = intersection (r, s); set_difference l = set_difference (r, s); delete l = delete (s, x, NULL); search if (search (l, x, NULL)) To Implement Associated LISTS use: lpush l = lpush (l, p); assoc s = assoc (l, x); adelete l = adelete (l, x); The following rules of closure exist for the functions provided. a = first (push (a, b)) b = rest (push (a, b)) a = push (pop (a), a)) For all a <> NIL a = reverse (reverse (a))
# (c) Copyright 1987, Hewlett-Packard Company. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License.
Definition at line 91 of file oldlist.cpp.
#define next_one | ( | l | ) | l = rest (l) |
Definition at line 92 of file oldlist.cpp.
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(), ELIST2::internal_de_dump(), ELIST::internal_de_dump(), CLIST::internal_de_dump(), ELIST2::length(), ELIST::length(), CLIST::length(), LogNewWordChoice(), POLY_BLOCK::overlap(), ELIST2::prep_serialise(), ELIST::prep_serialise(), CLIST::prep_serialise(), PrintAdaptedTemplates(), read_next_box(), ELIST2::sort(), ELIST::sort(), CLIST::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.
list | The list | |
key | Key | |
is_equal | Routine that will compare each node to the key |
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 }
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 }
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().
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().
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 }
Return the last list item (this is list type).
Definition at line 235 of file oldlist.cpp.
Referenced by AddLargeSpeckleTo(), CLIST::CLIST(), cutline(), ELIST::ELIST(), ELIST2::ELIST2(), ELIST2::empty(), ELIST::empty(), CLIST::empty(), ELIST2::First(), ELIST::First(), CLIST::First(), join(), push_last(), ELIST2::shallow_copy(), ELIST::shallow_copy(), CLIST::shallow_copy(), ELIST2::singleton(), ELIST::singleton(), and CLIST::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 }
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 }
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 }
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 }
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 }
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().
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 }