static void gui_set(int id, int i) { if (set_exists(i)) gui_state(id, set_name(i), GUI_SML, i, 0); else gui_label(id, "", GUI_SML, GUI_ALL, 0, 0); }
/*@ set_union - find the union of two sets Input arguments: + s - The first set - t - The second set Output arguments: None Returns: A new set that is the union of the two input sets if successful, NULL otherwise. Notes: s and t must contain the same types of elements @*/ struct set *set_union(struct set *s, struct set *t) { void * e; struct set *tmp, *u, *v; /* Try to make sure that these two sets contain the same types */ if (s->cmp != t->cmp || s->elemsize != t->elemsize) return NULL; /* Whichever set we iterate over should be smaller because iteration is O(n) */ /* while bsearch is O(log n) */ if (s->size < t->size) u = s, v = t; else u = t, v = s; tmp = set_copy(v); if (tmp == NULL) return NULL; /* Insert all the elements of u not in v */ for (set_reset(u), e = set_next(u); e != NULL; e = set_next(u)){ if (!set_exists(v, e)) set_insert(tmp, e); } return tmp; }
static void set_stick(int id, int a, int v) { int jd = shared_stick_basic(id, a, v); int i = gui_token(jd); if (jd && set_exists(i)) set_over(i); }
static void set_point(int id, int x, int y, int dx, int dy) { int jd = shared_point_basic(id, x, y); int i = gui_token(jd); if (jd && set_exists(i)) set_over(i); }
const struct score *set_score(int i, int s) { if (set_exists(i)) { if (s == SCORE_TIME) return &SET_GET(sets, i)->time_score; if (s == SCORE_COIN) return &SET_GET(sets, i)->coin_score; } return NULL; }
void depth_first_traversal(Graph *g, int vertex, Set *s_visited) { int i; if(set_exists(s_visited, vertex) > 0) { return; } set_add(s_visited, vertex); for(i = 0; i < g->size; i++) { if(i == vertex || !is_connected(g, vertex, i)) continue; depth_first_traversal(g, i, s_visited); } printf("Visiting %d\n", vertex); }
void Version::from_bip(char*& cursor) { set_label(read_string(cursor)); if(!label().empty()) set_exists(); int num_deps = read_uint(cursor); _deps.clear(); _deps.reserve(num_deps); for(int i=0; i < num_deps; i++) { Package::Ptr pkg = dataset.package(read_uint(cursor)); Version::Ptr dep = pkg->version(time()); add_dep(dep); } }
static int set_action(int i) { audio_play(AUD_MENU, 1.0f); switch (i) { case GUI_BACK: set_quit(); return goto_state(&st_title); break; case GUI_PREV: first -= SET_STEP; do_init = 0; return goto_state(&st_set); break; case GUI_NEXT: first += SET_STEP; do_init = 0; return goto_state(&st_set); break; case GUI_NULL: return 1; break; default: if (set_exists(i)) { set_goto(i); return goto_state(&st_start); } } return 1; }
/*@ set_insert - insert an element into a set Input arguments: + s - The set in which the element will be inserted - elem - The element which will be inserted Output arguments: None Returns: 0 on success, -1 on failure. @*/ int set_insert(struct set * const s, const void * const elem) { if (s == NULL || elem == NULL) return -1; if (s->size >= s->maxsize) return -1; /* Don't insert the same element twice */ if (set_exists(s, elem)) return 0; memcpy(s->buf+(s->size*s->elemsize), elem, s->elemsize); s->size++; /* Don't sort here -- only sort when we need something */ s->need_sort = 1; return 0; }
/*@ set_union - find the difference of two sets Input arguments: + s - The first set - t - The second set Output arguments: None Returns: A new set that contains all the elements of s not in t, NULL otherwise. Notes: s and t must contain the same types of elements @*/ struct set *set_diff(struct set *s, struct set *t) { void * e; struct set *tmp; /* Try to make sure that these two sets contain the same types */ if (s->cmp != t->cmp || s->elemsize != t->elemsize) return NULL; tmp = set_create(s->maxsize+t->maxsize, s->elemsize, s->cmp); if (tmp == NULL) return NULL; /* Insert all the elements of s not in t */ for (set_reset(s), e = set_next(s); e != NULL; e = set_next(s)){ if (!set_exists(t, e)) set_insert(tmp, e); } return tmp; }
const char *set_shot(int i) { return set_exists(i) ? SET_GET(sets, i)->shot : NULL; }
const char *set_desc(int i) { return set_exists(i) ? _(SET_GET(sets, i)->desc) : NULL; }
const char *set_name(int i) { return set_exists(i) ? _(SET_GET(sets, i)->name) : NULL; }
const char *set_id(int i) { return set_exists(i) ? SET_GET(sets, i)->id : NULL; }