LIST delete_d(LIST list, void *key, TessResultCallback2<int, void*, void*>* is_equal) { LIST result = NIL_LIST; LIST last_one = NIL_LIST; while (list != NIL_LIST) { if (!(*is_equal).Run (first_node (list), key)) { if (last_one == NIL_LIST) { last_one = list; list = list_rest (list); result = last_one; set_rest(last_one, NIL_LIST); } else { set_rest(last_one, list); last_one = list; list = list_rest (list); set_rest(last_one, NIL_LIST); } } else { list = pop (list); } } return (result); }
/********************************************************************** * d e l e t e d * * Delete all the elements out of the current list that match the key. * This operation destroys the original list. The caller will supply a * routine that will compare each node to the * key, and return a non-zero value when they match. If the value * NULL is supplied for is_equal, the is_key routine will be used. **********************************************************************/ LIST delete_d(LIST list, void *key, int_compare is_equal) { LIST result = NIL_LIST; LIST last_one = NIL_LIST; if (is_equal == NULL) is_equal = is_same; while (list != NIL_LIST) { if (!(*is_equal) (first_node (list), key)) { if (last_one == NIL_LIST) { last_one = list; list = list_rest (list); result = last_one; set_rest(last_one, NIL_LIST); } else { set_rest(last_one, list); last_one = list; list = list_rest (list); set_rest(last_one, NIL_LIST); } } else { list = pop (list); } } return (result); }
/********************************************************************** * i n s e r t * * Create a list element and rearange the pointers so that the first * element in the list is the second aurgment. **********************************************************************/ void insert(LIST list, void *node) { LIST element; if (list != NIL_LIST) { element = push (NIL_LIST, node); set_rest (element, list_rest (list)); set_rest(list, element); node = first_node (list); list->node = first_node (list_rest (list)); list->next->node = (LIST) node; } }
int smallest(list_t list) // REQUIRES: list is not empty // EFFECTS: returns smallest element in list { return compare_help(list_first(list), list_rest(list), min); }
int largest(list_t list) // REQUIRES: list is not empty // EFFECTS: returns largest element in list { return compare_help(list_first(list), list_rest(list), max); }
/** Processing commands for dbname combobox (hwndCtl). */ void processDbCombobox(HWND hwnd, HWND hwndCtl, UINT codeNotify) { switch(codeNotify) { /* Loading list and adjust its height if button clicked and on user input */ case(CBN_DROPDOWN): { FillParameters(hwnd, pParams); LIST *dbs= mygetdatabases(hwnd, pParams); LIST *dbtmp= dbs; ComboBox_ResetContent(hwndCtl); adjustDropdownHeight(hwndCtl,list_length(dbs)); for (; dbtmp; dbtmp= list_rest(dbtmp)) ComboBox_AddString(hwndCtl, (SQLWCHAR *)dbtmp->data); list_free(dbs, 1); ComboBox_SetText(hwndCtl,pParams->database); break; } } }
/** Processing commands for charset combobox (hwndCtl). */ void processCharsetCombobox(HWND hwnd, HWND hwndCtl, UINT codeNotify) { switch(codeNotify) { /* Loading list and adjust its height if button clicked and on user input */ case(CBN_DROPDOWN): { //FillParameters(hwnd, *pParams); LIST *csl= mygetcharsets(hwnd, pParams); LIST *cstmp= csl; ComboBox_ResetContent(hwndCtl); adjustDropdownHeight(hwndCtl,list_length(csl)); for (; cstmp; cstmp= list_rest(cstmp)) ComboBox_AddString(hwndCtl, (SQLWCHAR *)cstmp->data); list_free(csl, 1); ComboBox_SetText(hwndCtl,pParams->charset); break; } } }
void thr_print_locks(void) { LIST *list; uint count=0; pthread_mutex_lock(&THR_LOCK_lock); puts("Current locks:"); for (list= thr_lock_thread_list; list && count++ < MAX_THREADS; list= list_rest(list)) { THR_LOCK *lock=(THR_LOCK*) list->data; VOID(pthread_mutex_lock(&lock->mutex)); printf("lock: 0x%lx:",(ulong) lock); if ((lock->write_wait.data || lock->read_wait.data) && (! lock->read.data && ! lock->write.data)) printf(" WARNING: "); if (lock->write.data) printf(" write"); if (lock->write_wait.data) printf(" write_wait"); if (lock->read.data) printf(" read"); if (lock->read_wait.data) printf(" read_wait"); puts(""); thr_print_lock("write",&lock->write); thr_print_lock("write_wait",&lock->write_wait); thr_print_lock("read",&lock->read); thr_print_lock("read_wait",&lock->read_wait); VOID(pthread_mutex_unlock(&lock->mutex)); puts(""); } fflush(stdout); pthread_mutex_unlock(&THR_LOCK_lock); }
static void free_files(List list) { while (list) { free(list->data); list = list_rest(list); } }
/********************************************************************** * d e s t r o y * * Return the space taken by a list to the heap. **********************************************************************/ LIST destroy(LIST list) { LIST next; while (list != NIL_LIST) { next = list_rest (list); free_cell(list); list = next; } return (NIL_LIST); }
/********************************************************************** * p o p * * Return the list with the first element removed. Destroy the space * that it occupied in the list. **********************************************************************/ LIST pop(LIST list) { LIST temp; temp = list_rest (list); if (list != NIL_LIST) { free_cell(list); } return (temp); }
int list_walk(LIST *list, list_walk_action action, gptr argument) { int error=0; while (list) { if ((error = (*action)(list->data,argument))) return error; list=list_rest(list); } return 0; }
bool Dict::AlternativeChoicesWorseThan(FLOAT32 Threshold) { LIST Alternatives; VIABLE_CHOICE Choice; Alternatives = list_rest (best_choices_); iterate(Alternatives) { Choice = (VIABLE_CHOICE) first_node (Alternatives); if (Choice->AdjustFactor <= Threshold) return false; } return true; }
static void sol_cmd_enq_deferred(void) { List l, r; /* Reverse the list to preserve original command order. */ for (r = NULL, l = deferred_cmds; l; r = list_cons(l->data, r), l = list_rest(l)); /* Enqueue commands. */ for (; r; r = list_rest(r)) { if (cmd_enq_fn) cmd_enq_fn(r->data); free(r->data); } deferred_cmds = NULL; }
/** * This routine deallocates all of the memory consumed by * a micro-feature outline. * @param arg micro-feature outline to be freed * @return none */ void FreeMFOutline(void *arg) { //MFOUTLINE Outline) MFOUTLINE Start; MFOUTLINE Outline = (MFOUTLINE) arg; /* break the circular outline so we can use std. techniques to deallocate */ Start = list_rest (Outline); set_rest(Outline, NIL_LIST); while (Start != nullptr) { free(first_node(Start)); Start = pop (Start); } } /* FreeMFOutline */
static int compare_help(int so_far, list_t list, int (*fn)(int, int)) { if (list_isEmpty(list)) { return so_far; } else { so_far = fn(so_far, list_first(list)); return compare_help(so_far, list_rest(list), fn); } }
/** * This routine deallocates all of the memory consumed by * a micro-feature outline. * @param arg micro-feature outline to be freed * @return none * @note Exceptions: none * @note History: 7/27/89, DSJ, Created. */ void FreeMFOutline(void *arg) { //MFOUTLINE Outline) MFOUTLINE Start; MFOUTLINE Outline = (MFOUTLINE) arg; /* break the circular outline so we can use std. techniques to deallocate */ Start = list_rest (Outline); set_rest(Outline, NIL_LIST); while (Start != NULL) { free_struct (first_node (Start), sizeof (MFEDGEPT), "MFEDGEPT"); Start = pop (Start); } } /* FreeMFOutline */
bool Dict::AcceptableResult(const WERD_CHOICE &BestChoice) { float CertaintyThreshold = stopper_nondict_certainty_base - reject_offset_; int WordSize; if (stopper_debug_level >= 1) { tprintf("\nRejecter: %s (word=%c, case=%c, unambig=%c)\n", BestChoice.debug_string(getUnicharset()).string(), (valid_word(BestChoice) ? 'y' : 'n'), (case_ok(BestChoice, getUnicharset()) ? 'y' : 'n'), ((list_rest (best_choices_) != NIL_LIST) ? 'n' : 'y')); } if (BestChoice.length() == 0 || CurrentWordAmbig()) return false; if (BestChoice.fragment_mark()) { if (stopper_debug_level >= 1) { cprintf("AcceptableResult(): a choice with fragments beats BestChoice\n"); } return false; } if (valid_word(BestChoice) && case_ok(BestChoice, getUnicharset())) { WordSize = LengthOfShortestAlphaRun(BestChoice); WordSize -= stopper_smallword_size; if (WordSize < 0) WordSize = 0; CertaintyThreshold += WordSize * stopper_certainty_per_char; } if (stopper_debug_level >= 1) cprintf ("Rejecter: Certainty = %4.1f, Threshold = %4.1f ", BestChoice.certainty(), CertaintyThreshold); if (BestChoice.certainty() > CertaintyThreshold && !stopper_no_acceptable_choices) { if (stopper_debug_level >= 1) cprintf("ACCEPTED\n"); return true; } else { if (stopper_debug_level >= 1) cprintf("REJECTED\n"); return false; } }
bool Dict::CurrentWordAmbig() { return (list_rest (best_choices_) != NIL_LIST); }
/********************************************************************** * l a s t * * Return the last list item (this is list type). **********************************************************************/ LIST last(LIST var_list) { while (list_rest (var_list) != NIL_LIST) var_list = list_rest (var_list); return (var_list); }
static list_t filter_even_helper(list_t list, list_t filteredList) { if (list_isEmpty(list)) return filteredList; if (!list_first(list)%2) return filter_even_helper(list_rest(list), list_make(list_first(list), filteredList)); return filter_even_helper(list_rest(list), filteredList); }
static list_t filter_helper(list_t list, bool (*fn)(int), list_t filteredList) { if (list_isEmpty(list)) return filteredList; if (fn(list_first(list))) return filter_helper(list_rest(list), fn, list_make(list_first(list), filteredList)); return filter_helper(list_rest(list), fn, filteredList); }
static list_t rotate_helper(list_t list, unsigned int n, list_t rotated) { if (!n) return append(list, reverse(rotated)); if (list_isEmpty(list) && n) rotate_helper(reverse(rotated), n-1, list_make()); return rotate_helper(list_rest(list), n-1, list_make(list_first(list), rotated)); }
static list_t insert_helper(list_t first, list_t second, list_t holder, unsigned int n) { if (!n) return append((append(reverse(holder), second)), first); return insert_helper(list_rest(first), second, list_make(list_first(first), holder), n-1); }
static int sum_helper(list_t list, int sum) { if (list_isEmpty(list)) return sum; return sum_helper(list_rest(list), sum + list_first(list)); }
static int product_helper(list_t list, int product) { if (list_isEmpty(list)) return product; return product_helper(list_rest(list), product * list_first(list)); }
static list_t chop_helper(list_t l, unsigned int n) { if (!n) return reverse(l); return chop_helper(list_rest(l), n-1); }
static int accumulate_helper(list_t list, int (*fn)(int, int), int result) { if (list_isEmpty(list)) return result; return accumulate_helper(list_rest(list), fn, fn(result, list_first(list))); }
static list_t reverse_helper(list_t list, list_t reversed) { if (list_isEmpty(list)) return reversed; return reverse_helper(list_rest(list), list_make(list_first(list), reversed)); }
static list_t append_helper(list_t first, list_t appended) { if (list_isEmpty(first)) return appended; return append_helper(list_rest(first), list_make(list_first(first), appended)); }