本文整理汇总了C++中set_add函数的典型用法代码示例。如果您正苦于以下问题:C++ set_add函数的具体用法?C++ set_add怎么用?C++ set_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
// Performs a union of two sets, does not allow duplicate values
struct set_t *set_union(struct set_t *set1, struct set_t *set2) {
struct set_t *temp_set_head = NULL;
struct set_t *temp_set_it = NULL;
struct set_t *set_it = set1;
// Add each element of set1
while(set_it != NULL) {
if(temp_set_head == NULL) {
temp_set_head = new_set(set_it->value);
temp_set_it = temp_set_head;
} else {
temp_set_it->next = set_add(temp_set_head, set_it->value);
if(temp_set_it->next != NULL)
temp_set_it = temp_set_it->next;
}
set_it = set_it->next;
}
// Add each element of set2
set_it = set2;
while(set_it != NULL) {
if(temp_set_head == NULL) {
temp_set_head = new_set(set_it->value);
temp_set_it = temp_set_head;
} else {
temp_set_it->next = set_add(temp_set_head, set_it->value);
if(temp_set_it->next != NULL)
temp_set_it = temp_set_it->next;
}
set_it = set_it->next;
}
return temp_set_head;
}
示例2: main
int
main(int argc, char **argv)
{
struct set *set;
const char *str1 = "test1";
const char *str2 = "test2";
const char *str3 = "test3";
set = set_create(badhash, string_key_equals);
/* Unlike the hash table equivalent of this test, use an extra
* string so that the rehash happens at the right time.
*/
set_add(set, str1);
set_add(set, str2);
set_add(set, str3);
set_remove(set, str2);
set_add(set, str3);
set_remove(set, str3);
assert(!set_contains(set, str3));
set_destroy(set, NULL);
return 0;
}
示例3: steam_init
/**
* Implements #prpl->init(). This initializes the an account.
*
* @param acc The #account_t.
**/
static void steam_init(account_t *acc)
{
set_t *s;
s = set_add(&acc->set, "authcode", NULL, steam_eval_accounton, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_NOSAVE;
s = set_add(&acc->set, "captcha", NULL, steam_eval_accounton, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_NOSAVE;
s = set_add(&acc->set, "esid", NULL, NULL, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_NOSAVE;
s = set_add(&acc->set, "cgid", NULL, NULL, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_NOSAVE;
s = set_add(&acc->set, "umqid", NULL, NULL, acc);
s->flags = SET_NULL_OK | SET_HIDDEN;
s = set_add(&acc->set, "token", NULL, NULL, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_PASSWORD;
s = set_add(&acc->set, "sessid", NULL, NULL, acc);
s->flags = SET_NULL_OK | SET_HIDDEN | SET_PASSWORD;
s = set_add(&acc->set, "show_playing", "%", steam_eval_show_playing, acc);
s->flags = SET_NULL_OK;
set_add(&acc->set, "game_status", "false", steam_eval_game_status, acc);
set_add(&acc->set, "password", NULL, steam_eval_password, acc);
}
示例4: main
int main(int argc,
char *argv[]) {
void *a = new(String, "a");
void *b = new(String, "bbb");
void *s = new(Set);
printf("LENGTH A: %lu\n", string_length(a));
printf("LENGTH B: %lu\n", string_length(b));
printf("Prev: %s\n", string_get(a));
string_set(a, "New String");
printf("New: %s\n", string_get(a));
set_add(s, a);
set_add(s, b);
printf("CONTAINS A: %u\n", set_contains(s, a));
printf("CONTAINS B: %u\n", set_contains(s, b));
printf("DROP B: %p\n", set_drop(s, b));
printf("DROP B: %p\n", set_drop(s, b));
printf("ADD B: %p\n", set_add(s, b));
delete(s);
delete(a);
delete(b);
return 0;
}
示例5: g_new0
irc_channel_t *irc_channel_new(irc_t *irc, const char *name)
{
irc_channel_t *ic;
set_t *s;
if (!irc_channel_name_ok(name) || irc_channel_by_name(irc, name)) {
return NULL;
}
ic = g_new0(irc_channel_t, 1);
ic->irc = irc;
ic->name = g_strdup(name);
strcpy(ic->mode, CMODE);
irc_channel_add_user(ic, irc->root);
irc->channels = g_slist_append(irc->channels, ic);
set_add(&ic->set, "auto_join", "false", set_eval_bool, ic);
s = set_add(&ic->set, "type", "control", set_eval_channel_type, ic);
s->flags |= SET_NOSAVE; /* Layer violation (XML format detail) */
if (name[0] == '&') {
set_setstr(&ic->set, "type", "control");
} else { /* if( name[0] == '#' ) */
set_setstr(&ic->set, "type", "chat");
}
return ic;
}
示例6: insert_loop_node
static void
insert_loop_node (flowloop_t *loop, unsigned n, set_t *stack)
{
if (!set_is_member (loop->nodes, n)) {
set_add (loop->nodes, n);
set_add (stack, n);
}
}
示例7: main
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;
}
示例8: __hamt_new_node
static struct hamt_node *__hamt_new_node2(struct hamt_root *root,
void *item1, int slice1,
void *item2, int slice2)
{
struct hamt_node *node = \
__hamt_new_node(root,
set_add(set_add(0ULL, slice1), slice2),
2);
node->slots[set_slot_number(node->mask, slice1)] = item_to_slot(item1);
node->slots[set_slot_number(node->mask, slice2)] = item_to_slot(item2);
return node;
}
示例9: msn_init
static void msn_init( account_t *acc )
{
set_t *s;
s = set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY;
set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
set_add( &acc->set, "switchboard_keepalives", "false", set_eval_bool, acc );
acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE |
ACC_FLAG_HANDLE_DOMAINS;
}
示例10: set_test
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);
}
示例11: range_from_braces
range* range_from_braces(range_request* rr,
const range* r1, const range* r2, const range* r3)
{
int i, j, k;
set_element** m1;
set_element** m2;
set_element** m3;
set* temp = NULL;
range* bigrange;
char* bundle;
apr_pool_t* pool = range_request_pool(rr);
if(r1->nodes->members == 0) {
if(!temp) {
temp = set_new(pool, 1);
set_add(temp, "", NULL);
}
m1 = set_members(temp);
} else m1 = set_members(r1->nodes);
if(r2->nodes->members == 0) {
if(!temp) {
temp = set_new(pool, 1);
set_add(temp, "", NULL);
}
m2 = set_members(temp);
} else m2 = set_members(r2->nodes);
if(r3->nodes->members == 0) {
if(!temp) {
temp = set_new(pool, 1);
set_add(temp, "", NULL);
}
m3 = set_members(temp);
} else m3 = set_members(r3->nodes);
bigrange = range_new(rr);
for(i = 0; m1[i]; i++)
for(j = 0; m2[j]; j++)
for(k = 0; m3[k]; k++) {
bundle = apr_pstrcat(pool,
m1[i]->name, m2[j]->name,
m3[k]->name, NULL);
range_add(bigrange, bundle);
}
if (temp) set_destroy(temp);
bigrange->quoted = r1->quoted || r2->quoted || r3->quoted;
return bigrange;
}
示例12: set_add
void set_add(set_t** set, void* object)
{
assert(set != NULL);
if (*set == NULL) {
*set = malloc(sizeof(set_t));
(*set)->data = object;
(*set)->left = NULL;
(*set)->right = NULL;
} else if ((*set)->data > object) {
set_add(&(*set)->left, object);
} else if ((*set)->data < object) {
set_add(&(*set)->right, object);
}
}
示例13: main
int main()
{
std::vector<int> set({10});
set_add(set, 16);
set_add(set, 16);
set_add(set, 10);
set_add(set, 5);
set_add(set, 5);
print(set.begin(), set.end());
std::cout << count_of_equals(set.begin(), set.end(), 16) << std::endl;
return 0;
}
示例14: set_intersect_int
STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) {
if (update) {
check_set(self_in);
} else {
check_set_or_frozenset(self_in);
}
if (self_in == other) {
return update ? mp_const_none : set_copy(self_in);
}
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_set_t *out = MP_OBJ_TO_PTR(mp_obj_new_set(0, NULL));
mp_obj_t iter = mp_getiter(other, NULL);
mp_obj_t next;
while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) {
set_add(MP_OBJ_FROM_PTR(out), next);
}
}
if (update) {
m_del(mp_obj_t, self->set.table, self->set.alloc);
self->set.alloc = out->set.alloc;
self->set.used = out->set.used;
self->set.table = out->set.table;
}
return update ? mp_const_none : MP_OBJ_FROM_PTR(out);
}
示例15: ro2sslose
int
ro2sslose (struct assocblk *acb, int result)
{
int len;
char *base;
PE pe;
struct SSAPindication sis;
base = NULL, len = 0;
/* begin AbortInformation PSDU (pseudo) */
if (pe = pe_alloc (PE_CLASS_UNIV, PE_FORM_CONS, PE_CONS_SET)) {
if (set_add (pe, num2prim ((integer) result, PE_CLASS_CONT, 0))
!= NOTOK)
pe2ssdu (pe, &base, &len);
PLOGP (rosap_log,OACS_AbortInformation, pe, "AbortInformation",
0);
pe_free (pe);
}
/* end AbortInformation PSDU */
SUAbortRequest (acb -> acb_fd, base, len, &sis);
acb -> acb_fd = NOTOK;
if (base)
free (base);
}