/* Ah ha! A leaf is actually made up of two smaller files with an lr or a tb * merge. Turn a leaf node into a join node. Propogate the transform down * arg2's side of the tree. */ static int make_join( SymbolTable *st, JoinType type, JoinNode *arg1, JoinNode *arg2, JoinNode *out, double a, double b, double dx, double dy, int mwidth ) { Transformation trn; /* Check output is ok. */ if( out->type != JOIN_LEAF ) { im_error( "im_global_balance", _( "image \"%s\" used twice as output" ), out->name ); return( -1 ); } /* Fill fields. */ out->type = type; out->mwidth = mwidth; out->a = a; out->b = b; out->dx = dx; out->dy = dy; out->arg1 = arg1; out->arg2 = arg2; out->thistrn.a = a; out->thistrn.b = -b; out->thistrn.c = b; out->thistrn.d = a; out->thistrn.dx = dx; out->thistrn.dy = dy; /* Clean the table and propogate the transform down the RHS of the * graph. */ clean_table( st ); if( propogate_transform( arg2, &out->thistrn ) ) return( -1 ); /* Find the position and size of our output. */ calc_geometry( out ); /* Now normalise the result, so that out is at (0,0) again. */ trn.a = 1.0; trn.b = 0.0; trn.c = 0.0; trn.d = 1.0; trn.dx = -out->cumtrn.oarea.left; trn.dy = -out->cumtrn.oarea.top; clean_table( st ); if( propogate_transform( out, &trn ) ) return( -1 ); return( 0 ); }
/* Scan the symbol table, looking for a node which no node references. */ static JoinNode * find_root( SymbolTable *st ) { JoinNode *root; JoinNode *notroot; /* Clean the table, then scan it, setting all pointed-to nodes dirty. */ clean_table( st ); im__map_table( st, set_referenced, NULL, NULL ); /* Look for the first clean symbol. */ root = (JoinNode *) im__map_table( st, is_root, NULL, NULL ); /* No root? Hot dang! */ if( !root ) { im_error( "im_global_balance", _( "mosaic root not found in desc file\n" "is this really a mosaiced image?" ) ); return( NULL ); } /* Now dirty that - then if there are any more clean symbols, we have * more than one root. */ root->dirty = 1; if( (notroot = im__map_table( st, is_root, NULL, NULL )) ) { im_error( "im_global_balance", _( "more than one root" ) ); return( NULL ); } return( root ); }
int main() { char* keyList[] = { "Jaga", "Jesse", "Cos", "Kate", "Nash", "Vera", "Bob" }; int valList[] = { 24, 78, 86, 28, 11, 99, 38 }; int i; for( i=0; i<NUM_INPUTS; ++i ) insert( keyList[i], valList[i] ); char *name = "Bob"; int data; if( find( name, &data )) printf( "Found %s. (S)he's %i\n\n", name, data ); else printf( "\nCouldn't find %s\n\n", name ); /* what does the table look like here? */ clean_table(); return( 0 ); }
/******************************************************************************* * @fn void *compute_routes_thread( void *rp_tables ) * * @brief Thread that takes care of routing * ****************************************************************************/ void *compute_routes_thread( void *rp_tables ) { static uint32_t index; uint8_t node_index; uint8_t *route_table = &((uint8_t*)rp_tables)[0]; uint8_t *power_table = &((uint8_t*)rp_tables)[MAX_DEVICES]; // loop forever for (;;) { // Block until next table is ready pthread_mutex_lock ( &mutex_route_start ); // Assuming rssi_table has been updated clean_table( rssi_table ); add_links_from_table( rssi_table ); // Run dijkstra's algorithm with 0 being the access point dijkstra( AP_NODE_ID, c_factor ); // Display shortest paths and update energies for( node_index = 1; node_index < (MAX_DEVICES + 1); node_index++ ) { compute_shortest_path( node_index ); print_shortest_path( node_index ); } // Compute routing table compute_rp_tables( route_table, link_powers ); // Debug memcpy( previous_powers_debug, previous_powers, sizeof(previous_powers) ); memcpy( route_table_debug, route_table, sizeof(route_table_debug) ); // Compute power table compute_required_powers( link_powers, power_table ); print_rssi_table(); print_node_energy( AP_NODE_ID, fp_energies ); index++; printf("\nRound %d\n", index); // Block until next table is ready pthread_mutex_unlock ( &mutex_route_done ); } return NULL; }
int main() { char* keyList[] = { "Jaga", "Jesse", "Cos", "Kate", "Nash", "Vera", "Bob" }; int valList[] = { 24, 78, 86, 28, 11, 99, 38 }; int i; for( i=0; i<NUM_INPUTS; ++i ) insert( keyList[i], valList[i] ); /* what does the table look like here? */ clean_table(); return( 0 ); }
/** The return value is the number of disjuncts deleted. * Implementation notes: * Normally all the identical disjunct-jets are memory shared. * The suffix_id of each connector serves as its reference count * in the power table. Each time when a connector that cannot match * is discovered, its reference count is decreased, and its * nearest_word field is assigned BAD_WORD. Due to the memory sharing, * each such an assignment affects immediately all the identical * disjunct-jets. * */ static int power_prune(Sentence sent, Parse_Options opts) { power_table pt; prune_context pc; int N_deleted[2] = {0}; /* [0] counts first deletions, [1] counts dups. */ int total_deleted = 0; power_table_alloc(sent, &pt); power_table_init(sent, &pt); pc.pt = &pt; pc.power_cost = 0; pc.null_links = (opts->min_null_count > 0); pc.N_changed = 1; /* forces it always to make at least two passes */ pc.sent = sent; while (1) { /* left-to-right pass */ for (WordIdx w = 0; w < sent->length; w++) { for (Disjunct **dd = &sent->word[w].d; *dd != NULL; /* See: NEXT */) { Disjunct *d = *dd; /* just for convenience */ if (d->left == NULL) { dd = &d->next; /* NEXT */ continue; } bool is_bad = d->left->nearest_word == BAD_WORD; if (is_bad || left_connector_list_update(&pc, d->left, w, true) < 0) { mark_connector_sequence_for_dequeue(d->left, true); mark_connector_sequence_for_dequeue(d->right, false); /* discard the current disjunct */ *dd = d->next; /* NEXT - set current disjunct to the next one */ N_deleted[(int)is_bad]++; continue; } dd = &d->next; /* NEXT */ } clean_table(pt.r_table_size[w], pt.r_table[w]); } total_deleted += N_deleted[0] + N_deleted[1]; lgdebug(D_PRUNE, "Debug: l->r pass changed %d and deleted %d (%d+%d)\n", pc.N_changed, N_deleted[0]+N_deleted[1], N_deleted[0], N_deleted[1]); if (pc.N_changed == 0 && N_deleted[0] == 0 && N_deleted[1] == 0) break; pc.N_changed = N_deleted[0] = N_deleted[1] = 0; /* right-to-left pass */ for (WordIdx w = sent->length-1; w != (WordIdx) -1; w--) { for (Disjunct **dd = &sent->word[w].d; *dd != NULL; /* See: NEXT */) { Disjunct *d = *dd; /* just for convenience */ if (d->right == NULL) { dd = &d->next; /* NEXT */ continue; } bool is_bad = d->right->nearest_word == BAD_WORD; if (is_bad || right_connector_list_update(&pc, d->right, w, true) >= sent->length) { mark_connector_sequence_for_dequeue(d->right, true); mark_connector_sequence_for_dequeue(d->left, false); /* Discard the current disjunct. */ *dd = d->next; /* NEXT - set current disjunct to the next one */ N_deleted[(int)is_bad]++; continue; } dd = &d->next; /* NEXT */ } clean_table(pt.l_table_size[w], pt.l_table[w]); } total_deleted += N_deleted[0] + N_deleted[1]; lgdebug(D_PRUNE, "Debug: r->l pass changed %d and deleted %d (%d+%d)\n", pc.N_changed, N_deleted[0]+N_deleted[1], N_deleted[0], N_deleted[1]); if (pc.N_changed == 0 && N_deleted[0] == 0 && N_deleted[1] == 0) break; pc.N_changed = N_deleted[0] = N_deleted[1] = 0; } power_table_delete(&pt); lgdebug(D_PRUNE, "Debug: power prune cost: %d\n", pc.power_cost); print_time(opts, "power pruned"); if (verbosity_level(D_PRUNE)) { prt_error("\n\\"); prt_error("Debug: After power_pruning:\n\\"); print_disjunct_counts(sent); } #ifdef DEBUG for (WordIdx w = 0; w < sent->length; w++) { for (Disjunct *d = sent->word[w].d; NULL != d; d = d->next) { for (Connector *c = d->left; NULL != c; c = c->next) assert(c->nearest_word != BAD_WORD); for (Connector *c = d->right; NULL != c; c = c->next) assert(c->nearest_word != BAD_WORD); } } #endif return total_deleted; }