int main(void) { set s1, s2; int m = 10; s1 = set_init(m); set_add(s1, 1); set_add(s1, 3); set_add(s1, 5); s2 = set_init(m + 2); set_add(s2, 0); set_add(s2, 2); set_add(s2, 3); set_add(s2, 4); set_add(s2, 5); set_add(s2, 11); set_print(s1); printf("\n"); set_print(s2); printf("\nIntersection: "); set_print(set_intersection(s1, s2)); printf("\nUnion: "); set_print(set_union(s1, s2)); printf("\nComplement for s2: "); set_print(set_complement(s2)); printf("\n"); return 0; }
QAP_solution_t *ant_build_solution(QAP_t *p){ int i, j, lct, flt; set_t set_lct, set_flt; QAP_solution_t *sol; sol = Malloc(sizeof(QAP_solution_t)); set_init(&set_lct, p->size); set_init(&set_flt, p->size); /* flt: facility */ for (i = 0; i < p->size; i++){ lct = next_location(&set_lct); flt = next_facility(p, &set_flt, lct); sol->perm[lct] = flt; } sol->cst = 0; for (i = 0; i < p->size; i++){ for (j = i; j < p->size; j++){ sol->cst += p->dist[i][j] * p->flow[sol->perm[i]][sol->perm[j]]; if (i != j){ sol->cst += p->dist[j][i] * p->flow[sol->perm[j]][sol->perm[i]]; } } } return sol; }
void set_test() { printf("SET S: "); set* s = set_init(); set_add(s, (SETDATA*)1); set_add(s, (SETDATA*)2); set_add(s, (SETDATA*)3); set_add(s, (SETDATA*)4); set_add(s, (SETDATA*)5); set_add(s, (SETDATA*)6); set_print(s, set_testcb); printf("S \\ 2, 6: "); set_remove(s, (SETDATA*)6); set_remove(s, (SETDATA*)2); set_print(s, set_testcb); printf("SET T: "); set* t = set_init(); set_add(t, (SETDATA*)1); set_add(t, (SETDATA*)2); set_add(t, (SETDATA*)9); set_add(t, (SETDATA*)4); set_print(t, set_testcb); printf("UNION OF S, T: "); set* u = set_init(); set_union(u, s, t); set_print(u, set_testcb); printf("INTERSECTION OF S, T: "); set* i = set_init(); set_intersection(i, s, t); set_print(i, set_testcb); printf("DIFFERENCE OF S, T: "); set* d = set_init(); set_difference(d, s, t); set_print(d, set_testcb); printf("CLEAR S: "); set_clear(s); set_print(s, set_testcb); set_free(s); set_free(t); set_free(u); set_free(i); set_free(d); }
/* Does not detect loops, but they should not happen anyway */ int grabContent(char *xml, char *url, struct crawlinfo *ci, set *acl_allow, set *acl_deny, char *usersid, CURL **curl, struct loginInfoFormat *login) { acl_allow = malloc(sizeof(*acl_allow)); acl_deny = malloc(sizeof(*acl_deny)); set_init(acl_allow); set_init(acl_deny); getEmailUrls(xml, ci, url, acl_allow, acl_deny, usersid, curl, login); set_free_all(acl_allow); set_free_all(acl_deny); free(acl_allow); free(acl_deny); return 1; }
int main() { char op; while (scanf("%c", &op) != EOF) { if (op < 'a') { op += 'a' - 'A'; } switch (op) { case 'd': { getlinenum(); n = argv[1]; set_init(n); /*if (n > 6000000) { for (;;); }*/ break; } case 'c': { int i, st, ed; getlinenum(); for (i = 1, st = argv[1], ed = argv[2]; (i <= argv[3])/* && (st <= n) && (ed <= n) && (st > 0) && (ed > 0) */; ++i, st += argv[5], ed += argv[4]) { set_connect(st, ed); } break; } case 'q': { int i, st, ed; int s1 = 0; int s2 = 0; getlinenum(); for (i = 1, st = argv[1], ed = argv[2]; (i <= argv[3])/* && (st <= n) && (ed <= n) && (st > 0) && (ed > 0) */; ++i, st += argv[5], ed += argv[4]) { if (set_isconnect(st, ed)) { ++s1; } else { ++s2; } } printf("%d - %d\n", s1, s2); break; } default: { break; } } } return 0; }
int set_intersection(Set *seti, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* * Initialize set */ set_init(seti, set1->match, NULL); /* * Insert elements that are in both sets */ member = list_head(set1); for ( ; member != NULL; member = list_next(member)) { if (set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(seti, list_tail(seti), data) != 0) { set_destroy(seti); return -1; } } } return 0; }
int set_difference(Set *setd, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* * Initialize set */ set_init(setd, set1->match, NULL); /* * Insert elements that are in set1 but not set2 */ member = list_head(set1); for ( ; member != NULL; member = list_next(member)) { if (!set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(setd, list_tail(setd), data) != 0) { set_destroy(setd); return -1; } } } return 0; }
/* add an entry to the map */ static void map_add(map_t *m, const char *key, const char *val) { mapnode_t *tmp; unsigned int idx; if (!m) return; idx = hash_func(key) % m->nbuckets; tmp = m->buckets + idx; while (tmp->next != NULL) { if (strcmp(tmp->key,key) == 0) break; tmp = tmp->next; } /* add new entry to map */ if (tmp->next == NULL) { m->count ++; tmp->key = my_strdup(key); tmp->val = set_init(50); /* XXX: chosen arbitrarily */ tmp->next = (mapnode_t *)malloc(sizeof(mapnode_t)); tmp->next->key = NULL; tmp->next->val = NULL; tmp->next->next = NULL; } set_add(tmp->val,val); }
int set_union(Set *st, const Set *st1, const Set *st2){ set_init(st, st1->destroy, st1->match); Node *pCurrentNode = list_head(st1); while(pCurrentNode){ /* trust use's st1 is a really set(no duplicate node) */ if(list_push(st, list_node_data(pCurrentNode)) != 0){ set_destroy(st); return -1; } pCurrentNode = list_node_next(pCurrentNode); } pCurrentNode = list_head(st2); while(pCurrentNode){ if(!set_is_member(st, list_node_data(pCurrentNode))){ if(list_push(st, list_node_data(pCurrentNode)) != 0){ set_destroy(st); return -1; } } pCurrentNode = list_node_next(pCurrentNode); } return 0; }
int set_union(Set *setu, const Set *set1, const Set *set2) { ListElmt *member; void *data; set_init(setu, set1->match, NULL); for (member = list_head(set1); member != NULL; member = list_next(member)) { data = list_data(member); if (list_ins_next(setu, list_tail(setu), data) != 0) { set_destroy(setu); return -1; } } for (member = list_head(set2); member != NULL; member = list_next(member)) { if (set_is_member(set1, list_data(member))) { continue; } else { data = list_data(member); if (list_ins_next(setu, list_tail(setu), data) != 0) { set_destroy(setu); return -1; } } } return 0; }
/* graph_ins_vertex */ int graph_ins_vertex(Graph *graph, const void *data) { ListElmt *element; AdjList *adjlist; int retval; /* Do not allow the insertion of duplicate vertices. */ for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) { if (graph->match(data, ((AdjList *)list_data(element))->vertex)) { return 1; } } /* Insert the vertex. */ if ((adjlist = (AdjList *)malloc(sizeof(AdjList))) == NULL) { return -1; } adjlist->vertex = (void *)data; set_init(&adjlist->adjacent, graph->match, NULL); if ((retval = list_ins_next(&graph->adjlists, list_tail(&graph->adjlists), adjlist)) != 0) { return retval; } /* Adjust the vertex count to account for the inserted vertex. */ graph->vcount++; return 0; }
int main(int argc, char ** argv) { char * ifilename = "data/sigmafac/sigh.dat"; int ifd = open(ifilename, 0666); void * buf = (void *) malloc(64); set * S, * matches; letter * p = WORDOF("*GAAT*"); letter * _p = p; S = set_init(32); while (read_string(ifd, buf, 64, '\n')) if (*((char *) buf) != '\0') set_add_member(S, WORDOF((char *)buf)); matches = pattern_shortest_matches(S, p, _p); { unsigned int i; range_offset * r; for (i=0; i<matches->members_count; i++) { r = (range_offset *)matches->members[i]; printf("%s %d %d\n", pattern_to_printable(r->_word), r->begin, r->end); } } printf("%d\n", _find_cutoff_len(matches)); }
int graph_ins_vertex(Graph *graph, const void *data) { ListElmt *element; AdjList *adjlist; int retval; // 不允许插入重复顶点 for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) { if (graph->match(data, ((AdjList *)list_data(element))->vertex)) { return 1; } } // 插入顶点 if ((adjlist = (AdjList *)malloc(sizeof(AdjList))) == NULL) { return -1; } adjlist->vertex = (void *)data; set_init(&adjlist->adjacent, graph->match, NULL); if ((retval = list_ins_next(&graph->adjlists, list_tail(&graph->adjlists), adjlist)) != 0) { return retval; } graph->vcount++; return 0; }
/* set_differece */ int set_differece(Set *setd, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* Initialize the set for the difference. */ set_init(setd, set1->match, NULL); /* Insert the member from set1 not in set2. */ for (member = list_head(set1); member != NULL; member = list_next(member)) { if (!set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(setd, list_tail(setd), data) != 0) { set_destroy(setd); return -1; } } } return 0; }
/* set_t */ void _type_init_set(const void* cpv_input, void* pv_output) { bool_t b_result = false; assert(cpv_input != NULL && pv_output != NULL); b_result = _create_set_auxiliary((set_t*)cpv_input, (char*)pv_output); assert(b_result); set_init((set_t*)cpv_input); }
var_t *var_init(u64 /*string_t * */ name) { var_t *var = (var_t*) malloc(sizeof(var_t)); if (var == NULL) return NULL; var->name = name /*== NULL ? string_from_stdin() : name*/; var->def = set_init(); return var; }
static void test_init(){ Set *set = (Set *)malloc(sizeof(Set)); set_init(set, NULL, NULL); assert(0 == set_size(set)); }
int main() { int N = 1000; set_t a, b, c, r; for (N = 100; N < 1000000; N += 2000) { int milli = 0; // add code to start timing struct timeval startTime; struct timeval endTime; long startMillis; long endMillis; gettimeofday(&startTime, NULL); startMillis = startTime.tv_sec * MILLIS_PER_SECOND + startTime.tv_usec / 1000 ; set_init(&a, N); set_init(&b, N); set_init(&c, N) ; set_init(&r, N) ; for (int i = 0; i < N; i++) if ((i % 2) == 0) set_add_elem(&a, i); for (int i = 0; i < N; i++) if ((i % 2) == 1) set_add_elem(&b, i); set_union(&a, &b, &a); set_intersection(&b, &c, &b); for (int i = 0; i < N; i++) if ((i % 2) == 0) set_add_elem(&b, i); for (int i = 0; i < N; i++) if ((i % 4) == 0) set_add_elem(&c, i); set_intersection(&a, &b, &r); set_intersection(&r, &c, &r); // add code to stop timing and compute the run-time in milliseconds // in variable milli // gettimeofday(&endTime, NULL); endMillis = endTime.tv_sec * MILLIS_PER_SECOND + endTime.tv_usec / 1000 ; milli = (int) (endMillis - startMillis); printf("%d\t%d\n", N, milli); } return 0; }
/************************************************************************* * *N bounding_select * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function reads the bounding rectangle table to weed out the * local primitives. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * path <input> == (char *) path to the bounding rectangle table. * mapextent <input> == (extent_type) map extent to compare. * dec_degrees <input> == (int) flag to indicate if data is in decimal * degrees. * bounding_select <output> == (set_type) set of bounding rectangle ids. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type bounding_select( char *path, extent_type mapextent, int dec_degrees ) { vpf_table_type table; set_type set; rspf_int32 i, count; extent_type box, pextent; double x1,y1,x2,y2; row_type row; int XMIN_,YMIN_,XMAX_,YMAX_; /* Project all extents to plate-carree for cartesian comparisons */ /* (decimal degree coordinate systems) */ x1 = mapextent.x1; y1 = mapextent.y1; x2 = mapextent.x2; y2 = mapextent.y2; if (dec_degrees) { set_plate_carree_parameters( central_meridian(x1,x2), 0.0, 1.0 ); pcarree_xy(&x1,&y1); pcarree_xy(&x2,&y2); } pextent.x1 = x1; pextent.y1 = y1; pextent.x2 = x2; pextent.y2 = y2; table = vpf_open_table(path,disk,"rb",NULL); XMIN_ = table_pos("XMIN",table); YMIN_ = table_pos("YMIN",table); XMAX_ = table_pos("XMAX",table); YMAX_ = table_pos("YMAX",table); set = set_init(table.nrows+1); for (i=1;i<=table.nrows;i++) { row = read_next_row(table); get_table_element(XMIN_,row,table,&box.x1,&count); get_table_element(YMIN_,row,table,&box.y1,&count); get_table_element(XMAX_,row,table,&box.x2,&count); get_table_element(YMAX_,row,table,&box.y2,&count); free_row(row,table); x1 = box.x1; y1 = box.y1; x2 = box.x2; y2 = box.y2; if (dec_degrees) { pcarree_xy(&x1,&y1); pcarree_xy(&x2,&y2); } box.x1 = x1; box.y1 = y1; box.x2 = x2; box.y2 = y2; if ( contained(box,pextent) || contained(pextent,box) ) { set_insert(i,set); } } vpf_close_table(&table); return set; }
static void do_depend(llnode_t *head, map_t *deps) { llnode_t *tmp, *lnk; set_t *incl; const char *source; char *target, *ptr; int i,num,ext; tmp = head; while (tmp->next != NULL) { source = tmp->key; target = strrchr(source,'/'); if (target == NULL) { target = my_strdup(source); } else { target = my_strdup(target+1); } ext = 0; ptr = strrchr(target,'.'); if (ptr != NULL) { for (i = 0; i < numextensions; ++i) { if (strcmp(ptr,extensions[i]) == 0) ++ext; } if (ext > 0) { ptr[1] = 'o'; ptr[2] = '\0'; } } if (ext > 0) { fputs(target,stdout); fputs(" : ",stdout); fputs(source,stdout); incl = set_init(50); add_depend(source,incl,deps); num = incl->nbuckets; for (i = 0; i < num; ++i) { lnk = incl->buckets + i; while (lnk->next != NULL) { fputc(' ',stdout); fputs(lnk->key,stdout); lnk = lnk->next; } } fputc('\n',stdout); set_free(incl); } free((void *)target); tmp = tmp->next; } }
void process_initWithIDAndPageCount(Process *process, int processID, int pageCount) { process->processID = processID; process->processPageCount = pageCount; process->set = (Set *)malloc(sizeof(Set)); set_init(process->set); process->isRunning = YES; process->sequence_count = 0; //随机产生序列 srand((unsigned)time(NULL)); process_getSequence(process); }
void edit_typeset_rep::set_data (new_data data) { set_style (data->style); set_init (data->init); set_fin (data->fin); set_att (data->att); notify_page_change (); add_init (data->init); notify_change (THE_DECORATIONS); typeset_invalidate_env (); }
void SceneLevel::init() { if (inited) return; ParseMap("media/maps/map2.txt"); ObjectsFactory * fact = ObjectsFactory::instance(); player = fact->get_player(); //enemy = fact->get_enemy(0); //GameObject* panel1 = new PanelModel(0, Vector3(-3.5, 0.0, 0), 0.7); //GameObject* panel2 = new PanelModel(1, Vector3(3.5, 0.0, 0), 0.7); //GameObject* floor = new PlainModel(2, 0.7); //GameObject* box1 = new BoxModel(3, Vector3(2.5, 1.0, 2.5), 1); //player = new PlayerModel(4); bullet = new BulletModel(5, Vector3(1.0, 1.0, 1.0)); //enemy = new EnemyModel(6); //game_objects.push_back(panel1); //game_objects.push_back(panel2); //game_objects.push_back(floor); //game_objects.push_back(box1); //game_objects.push_back(player); //game_objects.push_back(bullet); //game_objects.push_back(enemy); camera = new Camera(player, 1.2); camera->set_behind(); //camera->set_infront(); //camera->set_ontop(); //game_objects, &plane, &cData, camera //fact->add_obstacle(panel1); //fact->add_obstacle(panel2); //fact->add_obstacle(floor); //fact->add_obstacle(box1); //fact->add_player(player); //fact->add_enemy(enemy); fact->add_bulet(bullet); fact->add_camera(camera); fact->set_plane(&plane); fact->set_collision_data(&cData); set_init(); lstatus = LevelStatus::PLAY; };
int main(int argc, char *argv[]) { set *s = set_init(10); set *t = set_init(3); set *r; set_iter i; char *p; set_add(s, "calvin"); set_add(s, "hobbes"); set_add(s, "alfred"); set_add(s, "hobbes"); set_add(t, "batman"); set_add(t, "robin"); set_add(t, "calvin"); set_add(t, "kevin bacon"); set_add(t, "alfred"); /*printf("len: %d\n", set_size(s)); printf("calvin: %d\nhobz: %d\n", set_ismember(s, "calvin"), set_ismember(s, "hobz"));*/ r = set_xor(s, t); set_iter_init(r, &i); while((p = set_iterate(r, &i)) != NULL) { printf("member: %s\n", p); } set_destroy(s); set_destroy(t); set_destroy(r); return 0; }
void _modinit(module_t *m) { mygroups_init(); groupsvs = service_add("groupserv", NULL, &conf_gs_table); add_uint_conf_item("MAXGROUPS", &conf_gs_table, 0, &maxgroups, 0, 65535, 5); add_uint_conf_item("MAXGROUPACS", &conf_gs_table, 0, &maxgroupacs, 0, 65535, 0); add_bool_conf_item("ENABLE_OPEN_GROUPS", &conf_gs_table, 0, &enable_open_groups, false); gs_db_init(); gs_hooks_init(); basecmds_init(); set_init(); }
set *set_diff(set *s1, set *s2) { set_iter itr; set *new_set = set_init(set_size(s1) + set_size(s2) / 2); char *elm; for(set_iter_init(s1, &itr); (elm = set_iterate(s1, &itr)) != NULL; ) { if(!set_ismember(s2, elm)) set_add(new_set, elm); } return new_set; }
int set_intersection(Set *seti, const Set *set1, const Set *set2) { SetElm *member; set_init(seti, set1->match, NULL); for (member=set_head(set1); member != NULL; member = set_next(member)) { if (set_is_member(set2, set_data(member))) { if (set_insert(seti, set_data(member)) != 0) { set_destory(seti); return -1; } } } return 0; }
inline void write_syms(table *t, FILE *o) { int cmp(void *a, void *b) { return strcmp((char *) a, (char *) b); } out = o; optional opt = set_init(cmp); if (opt.e) { s = opt.val; fputs("Symbols found: \n", out); arr_foreach(t->syms, sort); set_foreach(s, print); set_free(s); } fputs("Temporaries used: \n", out); arr_foreach(t->tmps, print); opt = set_init(cmp); if (opt.e) { s = opt.val; fputs("Literals found: \n", out); arr_foreach(t->lits, sort); set_foreach(s, print); set_free(s); } opt = set_init(cmp); if (opt.e) { s = opt.val; int i = 0; fputs("Symbol Table Operators: \n", out); //This is where we need to output the operators //Example: ++ POSTPP 1 1 LEFT_TO_RIGHT INTEGER NONE } }
static int set_enter(void) { int w = config_get_d(CONFIG_WIDTH); int h = config_get_d(CONFIG_HEIGHT); int id, jd, kd; int i; if (do_init) { total = set_init(); first = MIN(first, (total - 1) - ((total - 1) % SET_STEP)); audio_music_fade_to(0.5f, "bgm/inter.ogg"); audio_play(AUD_START, 1.f); } else do_init = 1; if ((id = gui_vstack(0))) { if ((jd = gui_hstack(id))) { gui_label(jd, _("Level Set"), GUI_SML, GUI_ALL, gui_yel, gui_red); gui_filler(jd); gui_navig(jd, first > 0, first + SET_STEP < total); } gui_space(id); if ((jd = gui_harray(id))) { shot_id = gui_image(jd, set_shot(first), 7 * w / 16, 7 * h / 16); if ((kd = gui_varray(jd))) { for (i = first; i < first + SET_STEP; i++) gui_set(kd, i); } } gui_space(id); desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht); gui_layout(id, 0, 0); } return id; }
int set_difference(Set *st, const Set *st1, const Set *st2){ set_init(st, st1->destroy, st1->match); Node *pCurrentNode = list_head(st1); while(pCurrentNode){ if(!set_is_member(st2, list_node_data(pCurrentNode))){ if(set_insert(st, list_node_data(pCurrentNode))!=0){ set_destroy(st); return -1; } } pCurrentNode = list_node_next(pCurrentNode); } return 0; }