void print(Table_T files){ int i; void **array = Table_toArray(files, NULL); qsort(array, Table_length(files), 2 * sizeof(*array), compare); for (i = 0; array[i]; i += 2){ if (*(char *)array[i] != '\0'){ printf("\t%s:", (char *)array[i]); } // print the line numbers in the set array[i+1] { int j; void **lines = Set_toArray(array[i + 1], NULL); qsort(lines, Set_length(array[i+1], sizeof(*lines), cmpint); for (j = 0; lines[j]; j++){ printf(" %d", *(int *)lines[j]); } FREE(lines); } printf("\n"); } FREE(array); }
void print(Table_T files) { int i; void **array = Table_toArray(files, NULL); qsort(array, Table_length(files), 2*sizeof (*array), compare); for (i = 0; array[i]; i += 2) { if (*(char *)array[i] != '\0') printf("\t%s:", (char *)array[i]); { void **lines = Set_toArray(array[i+1], NULL); qsort(lines, Set_length(array[i+1]), sizeof (*lines), cmpint); int j, c; for (j = 0; lines[j]; j++) { printf(" %d", *(int *)lines[j]); c = 0; while (lines[j+1] && *(int *)lines[j+1] == *(int *)lines[j] + 1) { j++; c = 1; } if (c) printf("-%d", *(int *)lines[j]); } FREE(lines); } printf("\n"); } FREE(array); }
/*prints all values contained in a set*/ void print_set(Set_T* set) { int set_len = Set_length(*set); void **set_array = Set_toArray(*set, NULL); for (int i=0; i<set_len; i++) { printf("%s\n", (char *)set_array[i]); } free(set_array); }
/*finds and returns the number of sets with more than one value*/ int num_fgroups(Table_T* table) { int table_len = Table_length(*table); void **table_array = Table_toArray(*table, NULL); int counter = 0; for (int i=1; i<(2*table_len); i += 2) { if (Set_length((Set_T)table_array[i]) > 1) { counter++; } } free(table_array); return counter; }
static void _remove_item(Table_T items, item_ *rmitem, bool timeout) { if (rmitem == NULL) { return; } if (rmitem->group) { // get each item from the list, null out the list field and // recursively call this until the whole set is removed _remove_group(items, rmitem->group, timeout); return; } Set_T s = rmitem->items; item_ *item = NULL; if (s) { item = Set_remove(s, (void *) rmitem); //if this was a dummy item from a timeout, get the real one } if (!item) return; if (item->timer_event) { timeout_del(item->timer_event); Mem_free(item->timer_event, __FILE__, __LINE__); } if ( timeout && item->timeout_handler!=NULL ) { _process_fun(item->timeout_handler, item->args); } if (rmitem != item) { Mem_free(rmitem, __FILE__, __LINE__); //a clone } if (item->key_idx) { oe_scalar key = item->object[item->key_idx]; if (s) if (key && Set_length(s) <= 0) { if (items) { Table_remove(items, key); } if (s) { Set_free( &s ); } } } Mem_free(item, __FILE__, __LINE__); }
/* prints the sets in the table that have more than 1 value*/ void print_table(Table_T* table) { int table_len = Table_length(*table); void **table_array = Table_toArray(*table, NULL); int counter = num_fgroups(table); for (int i=1; i<(2*table_len); i += 2) { if(Set_length((Set_T)table_array[i]) > 1) { print_set((Set_T *)&table_array[i]); counter--; if (counter != 0) { printf("\n"); } } Set_free((Set_T *)&table_array[i]); } free(table_array); }
//calculate the most unique fld in item against the map of lists of templates //put the tuple in that list associated with the most unique key static int _add_template(T _this_, item_ *item) { Table_T items = _this_->items; //calc most unique key oe_scalar key = NULL; int key_idx = 0; int set_size = 0; Set_T curset = NULL; for ( int i = 0; item->object[i]; i++ ) { oe_scalar tmpkey = item->object[i]; if (strcmp("_", tmpkey) == 0) continue; //don't index by wildcard Set_T s = (Set_T) Table_get( items, tmpkey ); if (s) { int size = Set_length( s ); if ( !key || size < set_size ) { key = tmpkey; key_idx = i; set_size = size; curset = s; } } else { //found an unused key key = tmpkey; key_idx = i; set_size = 0; curset = Set_new( 10, _itemcmp, _itemhash ); Table_put( items, key, curset ); break; } } if (!curset) { OE_ERR(0, "Dispatcher can not add template, make sure it is not all '_' fields\n"); //i18n return -1; } item->items = curset; item->key_idx = key_idx; //for self remove of empty sets Set_put( curset, item ); return 0; }