static void getCount_void_countIsOk(void **state) { list_t *list = list_new(); town tw, tw1, tw2; list_put(list, tw, 0); list_put(list, tw1, 0); list_put(list, tw2, 0); assert_int_equal(list_getCount(list), 2); list_delete(list); }
static void add_town_townAdded(void **state) { list_t *list = list_new(); town tw, tw1; tw.place.x = 5; tw.place.y = 5; list_put(list, tw, 0); list_put(list, tw1, 0); assert_int_equal(list_getCount(list), 1); list_delete(list); }
static void remove_position_townRemoved(void **state) { list_t *list = list_new(); town tw, tw1; list_status_t *status; tw1.place.x = 5; tw1.place.y = 5; list_put(list, tw, 0); list_put(list, tw1, 1); list_pop(list, 0, status); assert_int_equal(list_getCount(list), 0); list_delete(list); }
static void distance_indexes_distanceIsOk(void **state) { list_t *list = list_new(); town tw, tw1; double checkDistance = 5; tw.place.x = 4; tw.place.y = 5; tw1.place.x = 1; tw1.place.y = 1; list_put(list, tw, 0); list_put(list, tw1, 0); assert_true(list_distance(list, 0, 1) == checkDistance); list_delete(list); }
static void remove_position_townIsOk(void **state) { list_t *list = list_new(); town tw, tw1, check; list_status_t *status; check.place.x = tw1.place.x = 5; check.place.y= tw1.place.y = 5; list_put(list, tw, 0); list_put(list, tw1, 1); check = list_pop(list, 1, status); assert_int_equal(tw1.place.x, check.place.x); assert_int_equal(tw1.place.y, check.place.y); list_delete(list); }
void ben_dict(BEN * node, BEN * key, BEN * val) { TUPLE *tuple = NULL; if (node == NULL) { fail("ben_dict( 1 )"); } if (node->t != BEN_DICT) { fail("ben_dict( 2 )"); } if (node->v.d == NULL) { fail("ben_dict( 3 )"); } if (key == NULL) { fail("ben_dict( 4 )"); } if (key->t != BEN_STR) { fail("ben_dict( 5 )"); } if (val == NULL) { fail("ben_dict( 6 )"); } tuple = tuple_init(key, val); if (list_put(node->v.d, tuple) == NULL) { fail("ben_dict( 7 )"); } }
int list_add_out(list_ptr_t *list, TIME_PROTOCOL duration, DADDRESS address, MESSAGE *message){ struct timeval time_interval; pthread_mutex_lock(&mutex_list_out); list_put(list, address, time(NULL) + duration, duration,message); pthread_mutex_unlock(&mutex_list_out); time_interval.tv_sec = ((*list)->data)->duration; time_interval.tv_usec = 0; set_timer(time_interval); return 0; }
static void getTown_position_TownIsOk(void **state) { list_t *list = list_new(); town tw; tw.place.x = 5; tw.place.y = 5; list_put(list, tw, 0); town check = list_getTown(list, 0); assert_int_equal(check.place.x, tw.place.x); assert_int_equal(check.place.y, tw.place.y); list_delete(list); }
int main(void){ struct sample_list head; struct sample_entry *result_node; LIST_INIT( &head ); list_put( &head, 1 ); list_put( &head, 2 ); list_put( &head, 3 ); list_put( &head, 4 ); list_put( &head, 5 ); list_put( &head, 6 ); LIST_PRINT( &head, struct sample_entry, list, smpl_print ); LIST_EXISTS( &head, struct sample_entry, list, data, 3, result_node ); if( result_node ){ printf( "\n 3 exists. Delete the entry. \n" ); LIST_DEL( &head, result_node, list ); LIST_PRINT( &head, struct sample_entry, list, smpl_print ); } LIST_EXISTS( &head, struct sample_entry, list, data, 3, result_node ); if( result_node ){ printf( "\n 3 exists. Delete the entry \n" ); LIST_DEL( &head, result_node, list ); LIST_PRINT( &head, struct sample_entry, list, smpl_print ); } LIST_SORT( &head, struct sample_entry, list, smpl_cmp ); LIST_PRINT( &head, struct sample_entry, list, smpl_print ); LIST_CLEAR( &head, struct sample_entry, list ); LIST_PRINT( &head, struct sample_entry, list, smpl_print ); return 0; }
static void peek_positin_peekedIsOk(void **state) { list_t *list = list_new(); list_status_t *status; town tw, check; tw.place.x = 5; tw.place.y = 5; list_put(list, tw, 0); check = list_peek(list, 0, status); assert_int_equal(check.place.x, tw.place.x); assert_int_equal(check.place.y, tw.place.y); list_delete(list); }
static void add_town_townIsOk(void **state) { list_t *list = list_new(); town tw, check; tw.place.x = 5; tw.place.y = 5; check.place.x = 5; check.place.y = 5; list_put(list, tw, 0); assert_int_equal(list_getTown(list, 0).place.x, check.place.x); assert_int_equal(list_getTown(list, 0).place.y, check.place.y); list_delete(list); }
int ClassifyOcrSamples_Example() { char *input = Examples::getPath_alloc(ocrSamples); char *output = Examples::getPath_alloc(ocrSamplesOutput); Image *img = ReadImage_STB(input); if (img == NULL) { NConsolePrint("\nClassify OCR Samples failed! input image not found!"); return -1; } Image *subimage = 0; Image *subImageEdges = NULL; ImageClassificationData *icdTemp = 0; List *classes = list_create(); int si = 0; for (int x = 0; x < 2000 - 20; x += 20) { for (int y = 700; y < 800; y += 20) { subimage = image_get_area(img, x, y, ocrSubimageSize, ocrSubimageSize); icdTemp = image_classify(subimage, 12); free_image(subimage); if (icdTemp == NULL) continue; list_put(classes, icdTemp); //free_image_classification_data(icdTemp); si++; } } char *csvContent = datas_get_format_csv(classes); file_write(output, csvContent); freeN(csvContent); //list_free_default(classes, free_l); list_free_custom(classes, free_l); freeN(input); freeN(output); free_image(img); return 0; }
int list_add_in(list_ptr_t *list, TIME_PROTOCOL duration, DADDRESS address){ struct timeval time_interval; pthread_mutex_lock(&mutex_list_in); if((list_put(list, address, time(NULL) + duration, duration,NULL)) == NULL){ err_num = PUT_IN_ERR; ErrHandler(); return 1; } pthread_mutex_unlock(&mutex_list_in); time_interval.tv_sec = ((*list)->data)->duration; time_interval.tv_usec = 0; set_timer(time_interval); return 0; }
int List_Example() { NConsolePrint("\nstart List\n"); List *list = list_create(); //list_put(list, "static str"); //list_put(list, "static string"); //list_put(list, "statString"); list_put(list, strmakeN("DynString")); list_put(list, strmakeN("DynamicS")); list_put(list, strmakeN("String dyn")); //print them NConsolePrint("\n"); LIST_FOREACH(list) { NConsolePrint("%s\n", (char *)link->data); } list_free_custom(list, freeN); /* with passed callback for free element */ //list_free(list); /* clear only list. for list with static elements */ NConsolePrint("finish List\n\n"); return 0; }
struct obj_mime *mime_add( const char *key, const char *value ) { struct obj_mime *tuple = (struct obj_mime *) myalloc( sizeof(struct obj_mime) ); strncpy( tuple->key, key, MIME_KEYLEN ); strncpy( tuple->val, value, MIME_VALLEN ); if( list_put( _main->mime->list, tuple) == NULL ) { fail( "mime_add: List exhausted" ); } if( _main->mime->hash != NULL ) { hash_put( _main->mime->hash, (UCHAR *)tuple->key, strlen( tuple->key), tuple->val ); } return tuple; }
void ben_list(BEN * node, BEN * val) { if (node == NULL) { fail("ben_list( 1 )"); } if (node->t != BEN_LIST) { fail("ben_list( 2 )"); } if (node->v.l == NULL) { fail("ben_list( 3 )"); } if (val == NULL) { fail("ben_list( 4 )"); } if (list_put(node->v.l, val) == NULL) { fail("ben_list( 5 )"); } }
void cache_put( UCHAR *target, UCHAR *nodes_compact_list, int nodes_compact_size ) { ITEM *item = NULL; CACHE *cache = cache_find( target ); /* Found in cache, update cache, done */ if( cache != NULL ) { cache_update( cache, target, nodes_compact_list, nodes_compact_size ); return; } cache = (CACHE *) myalloc( sizeof(CACHE) ); cache_update( cache, target, nodes_compact_list, nodes_compact_size ); time_add_30_min( &cache->lifetime ); time_add_5_min_approx( &cache->renew ); item = list_put( _main->cache->list, cache ); hash_put( _main->cache->hash, cache->target, SHA1_SIZE, item ); }
void cache_put( UCHAR *session_id, int type ) { ITEM *item_sk = NULL; struct obj_key *sk = NULL; if( hash_exists( _main->cache->hash, session_id, SHA_DIGEST_LENGTH) ) { return; } sk = (struct obj_key *) myalloc( sizeof(struct obj_key), "cache_put" ); /* Session id */ memcpy( sk->session_id, session_id, SHA_DIGEST_LENGTH ); /* Multicast or Unicast */ sk->type = type; /* Availability */ sk->time = time_add_1_min(); item_sk = list_put( _main->cache->list, sk ); hash_put( _main->cache->hash, sk->session_id, SHA_DIGEST_LENGTH, item_sk ); }
int main() { town tw, tw1, tw2, peeked; list_status_t *popStatus, *peekStatus; list_status_t putStatus; strcmp(tw.name, "city 0"); strcmp(tw1.name, "city 1"); strcmp(tw2.name, "city 2"); tw.place.x = 5; tw.place.y = 5; tw1.place.x = 10; tw1.place.y = 10; tw2.place.x = 11; tw2.place.y = 11; list_t *ls; ls = list_new(); putStatus = list_put(ls, tw, 5); if(putStatus == LIST_FULL) printf("List is full"); if (putStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } putStatus = list_put(ls, tw1, 0); if(putStatus == LIST_FULL) printf("List is full"); if (putStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } putStatus = list_put(ls, tw1, 4); if(putStatus == LIST_FULL) printf("List is full"); if (putStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } putStatus = list_put(ls, tw2, 4); if(putStatus == LIST_FULL) printf("List is full"); if (putStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } list_pop(ls, 2, popStatus); if (*popStatus == LIST_EMPTY) { printf("List is empty"); } if(*popStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } list_print(ls); peeked = list_peek(ls, 1, peekStatus); if(*peekStatus == LIST_EMPTY) printf("List is empty"); if (*peekStatus == ERROR) { printf("Invalid index"); return EXIT_FAILURE; } printf("\nPeeked %d %d", peeked.place.x, peeked.place.y); int c1 = 1, c2 = 2; double dis = distacnce(ls, c1, c2); if(!dis) printf("\nInvalid index"); else printf("\nDistance between %d and %d is %f", c1, c2, dis); printf("\nCount %d", (list_getCount(ls)+1)); list_delete(ls); return 0; }
bool run(struct context *context, struct byte_array *program, struct map *env, bool in_context) { null_check(context); null_check(program); program = byte_array_copy(program); program->current = program->data; struct program_state *state = NULL; enum Opcode inst = VM_NIL; if (context->runtime) { if (in_context) { if (!state) state = (struct program_state*)stack_peek(context->program_stack, 0); env = state->named_variables; // use the caller's variable set in the new state } else state = program_state_new(context, env); } while (program->current < program->data + program->length) { inst = (enum Opcode)*program->current; bool really = inst & VM_RLY; inst &= ~VM_RLY; #ifdef DEBUG display_program_counter(context, program); #endif program->current++; // increment past the instruction int32_t pc_offset = 0; switch (inst) { case VM_COM: case VM_ITR: if (iterate(context, inst, state, program)) goto done; break; case VM_RET: if (ret(context, program)) goto done; break; case VM_TRO: if (tro(context)) goto done; break; case VM_TRY: if (vm_trycatch(context, program)) goto done; break; case VM_EQU: case VM_MUL: case VM_DIV: case VM_ADD: case VM_SUB: case VM_NEQ: case VM_GTN: case VM_LTN: case VM_GRQ: case VM_LEQ: case VM_BND: case VM_BOR: case VM_MOD: case VM_XOR: case VM_INV: case VM_RSF: case VM_LSF: binary_op(context, inst); break; case VM_ORR: case VM_AND: pc_offset = boolean_op(context, program, inst); break; case VM_NEG: case VM_NOT: unary_op(context, inst); break; case VM_SRC: src(context, inst, program); break; case VM_DST: dst(context, really); break; case VM_STX: case VM_SET: set(context, inst, state, program); break; case VM_JMP: pc_offset = jump(context, program); break; case VM_IFF: pc_offset = iff(context, program); break; case VM_CAL: func_call(context, inst, program, NULL); break; case VM_LST: push_list(context, program); break; case VM_MAP: push_map(context, program); break; case VM_NIL: push_nil(context); break; case VM_INT: push_int(context, program); break; case VM_FLT: push_float(context, program); break; case VM_BUL: push_bool(context, program); break; case VM_STR: push_str(context, program); break; case VM_VAR: push_var(context, program); break; case VM_FNC: push_fnc(context, program); break; case VM_GET: list_get(context, really); break; case VM_PTX: case VM_PUT: list_put(context, inst, really); break; case VM_MET: method(context, program, really); break; default: vm_exit_message(context, ERROR_OPCODE); return false; } program->current += pc_offset; } if (!context->runtime) return false; done: if (!in_context) stack_pop(context->program_stack); return inst == VM_RET; }