当前位置: 首页>>代码示例>>C++>>正文


C++ set_new函数代码示例

本文整理汇总了C++中set_new函数的典型用法代码示例。如果您正苦于以下问题:C++ set_new函数的具体用法?C++ set_new怎么用?C++ set_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: libcrange_new

libcrange* libcrange_new(apr_pool_t* pool, const char* config_file)
{
    libcrange* lr;

    if (!initd) {
        initd = 1;
        apr_initialize();
        atexit(apr_terminate);
    }

    lr = apr_palloc(pool, sizeof(libcrange));
    lr->pool = pool;
    lr->caches = set_new(pool, 0);
    lr->default_domain = NULL;
    lr->funcdir = LIBCRANGE_FUNCDIR;
    lr->want_caching = 1;
    lr->config_file = config_file ? config_file : LIBCRANGE_CONF;
    lr->functions = set_new(pool, 0);
    lr->perl_functions = NULL;
    lr->vars = set_new(pool, 0);

    if (access(lr->config_file, R_OK) != 0)
        return lr; /* no config file, don't load any modules */

    if (parse_config_file(lr) < 0)
        return NULL;

    return lr;
}
开发者ID:realpdm,项目名称:libcrange,代码行数:29,代码来源:libcrange.c

示例2: test_set

static void
test_set(void) {
    char *keys1[] = {"a", "b", "r", "a", "c", "a", "d", "a", "b", "r", "a"};
    char *keys2[] = {"a", "l", "a", "c", "a", "z", "a", "m"};
    SetObject *a = set_new();
    SetObject *b = set_new();
    set_addfrom(a, (void**)keys1, 11);
    set_addfrom(b, (void**)keys2, 8);
    set_print(a); // { 'c', 'd', 'r', 'a', 'b', }
    set_print(b); // { 'c', 'l', 'm', 'a', 'z', }
    set_print(set_rsub(a, b)); //{ 'd', 'b', 'r', }
    set_print(set_ror(a, b)); //{ 'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z', }
    set_print(set_rand(a, b)); //{ 'c', 'a', }
    set_print(set_rxor(a, b)); //{ 'b', 'd', 'l', 'm', 'r', 'z', }
    set_ior(a, b);
    set_print(a);
    set_isub(a, b);
    set_print(a);
    set_ixor(a, b);
    set_print(a);
    set_iand(a, b);
    set_print(a);
    set_free(a);
    set_free(b);
    char *keys3[] = {"a", "b"};
    char *keys4[] = {"a", "b", "d", "c", "e", "f", "g", "h"};
    SetObject *c = set_new();
    SetObject *d = set_new();
    set_addfrom(c, (void**)keys3, 2);
    set_addfrom(d, (void**)keys4, 8);
    set_print(set_xor(c, d));
    set_print(set_and(c, d));
    set_print(set_sub(c, d));
}
开发者ID:pronan,项目名称:c_data_structures,代码行数:34,代码来源:main.c

示例3: new_flowvar

static flowvar_t *
new_flowvar (void)
{
	flowvar_t *var;
	ALLOC (256, flowvar_t, vars, var);
	var->use = set_new ();
	var->define = set_new ();
	return var;
}
开发者ID:EIREXE,项目名称:Quakeforge-gcw0,代码行数:9,代码来源:flow.c

示例4: main

int main()
{
    printf("Hello world!\n");
    set_t * set_A = set_new(10);
    set_t * set_B = set_new(7);
    set_t * set_C;
    set_add_range(set_A,0,11);
    set_add_range(set_B,3,5);
    puts("\n\n Set_A after add");
    set_print_out(set_A);
    set_delete_range(set_A,3,11);
    puts("\n\n Set_A after delete");
    set_print_out(set_A);
    puts("\n\n Set_B after add");
    set_print_out(set_B);
    set_C = set_merge(set_A,set_B,"none");
    puts("\n\n Set_C - result of merge");
    set_print_out(set_C);
    set_delete_range(set_A,0,10);
    set_add_range(set_A,4,7);
    puts("\n\n another set_A");
    set_print_out(set_A);
    set_delete(set_C);
    set_A = _set_intersection(set_A,set_B,"del 1");
    puts("\n\n set_A after intersection with set_B");
    set_print_out(set_A);
    puts("\n\n set_A size after intersection \n");
    set_print_size(set_A);
    set_delete_range(set_A,4,5);
    set_add_range(set_A,1,1);
        set_add_range(set_A,3,4);
    puts("\n\n another set_A");
    set_print_out(set_A);
     puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_absolute_complement(set_A,set_B,"none");
    puts("\n\n set_C - absolute_complement of set_A and set_B");
    set_print_out(set_C);

    printf("\n Power of set_C = %i",set_measure_power(set_C));
    set_delete(set_C);
    set_add_range(set_A,0,10);
    puts("\n\n set_A");
    set_print_out(set_A);
    set_delete_range(set_B,3,5);
    set_add_range(set_B,2,4);
    puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_relative_complement(set_A,set_B,"none");
    puts("\n\n set_C - relative_complement of set_A and set_B");
    set_print_out(set_C);
    set_delete(set_A);
    set_delete(set_B);
    set_delete(set_C);
    return 0;
}
开发者ID:lorvis,项目名称:study,代码行数:56,代码来源:main.c

示例5: flow_uninit_scan_statements

static void
flow_uninit_scan_statements (flownode_t *node, set_t *defs, set_t *uninit)
{
	set_t      *stuse;
	set_t      *stdef;
	statement_t *st;
	set_iter_t *var_i;
	flowvar_t  *var;
	operand_t  *op;

	// defs holds only reaching definitions. make it hold only reaching
	// uninitialized definitions
	set_intersection (defs, uninit);
	stuse = set_new ();
	stdef = set_new ();
	for (st = node->sblock->statements; st; st = st->next) {
		flow_analyze_statement (st, stuse, stdef, 0, 0);
		for (var_i = set_first (stuse); var_i; var_i = set_next (var_i)) {
			var = node->graph->func->vars[var_i->element];
			if (set_is_intersecting (defs, var->define)) {
				def_t      *def = flowvar_get_def (var);
				if (def) {
					if (options.warnings.uninited_variable) {
						warning (st->expr, "%s may be used uninitialized",
								 def->name);
					}
				} else {
					bug (st->expr, "st %d, uninitialized temp %s",
						 st->number, operand_string (var->op));
				}
			}
			// avoid repeat warnings in this node
			set_difference (defs, var->define);
		}
		for (var_i = set_first (stdef); var_i; var_i = set_next (var_i)) {
			var = node->graph->func->vars[var_i->element];
			// kill any reaching uninitialized definitions for this variable
			set_difference (defs, var->define);
			if (var->op->op_type == op_temp) {
				op = var->op;
				if (op->o.tempop.alias) {
					var = op->o.tempop.alias->o.tempop.flowvar;
					if (var)
						set_difference (defs, var->define);
				}
				for (op = op->o.tempop.alias_ops; op; op = op->next) {
					var = op->o.tempop.flowvar;
					if (var)
						set_difference (defs, var->define);
				}
			}
		}
	}
	set_delete (stuse);
	set_delete (stdef);
}
开发者ID:EIREXE,项目名称:Quakeforge-gcw0,代码行数:56,代码来源:flow.c

示例6: PNEW

//设置优惠活动 
struct sales_promotion *get_promotion() 
{
	static struct sales_promotion *promotions;
        struct promotion_one_info *p; //临时变量  
    	struct set_t *pset; //临时变量
    	int i;  
    	static struct sales_products discount_promotion[] = { //折扣商品信息
		{"ITEM00002", 1},
		{"ITEM00001", 1}
		//{"ITEM00003", 0},
		//{"ITEM00004", 0}
	};
	static struct sales_products one_free_promotion[] = { //买二送一商品信息
		{"ITEM00001", 1},
		{"ITEM00003", 1}
		//{"ITEM00003", 0}
	};
	 
    	PNEW(promotions, 1, struct sales_promotion *);
	promotions->promotion_all_info = NULL;
	
        /*假设当前有以下两种活动*
         *  1. 买二送一活动
         *  2. 9.5折优惠 */
    	promotions->priority = FREE_ONE;  //当某种商品满足两种优惠时,优先选则活动一
     
        /*首先设置优惠活动1信息*/
     	PNEW(p, 1, struct promotion_one_info *);
     	p->next_promotion = promotions->promotion_all_info;
     	promotions->promotion_all_info = p;
     	p->type = FREE_ONE;
     	strcpy(p->statement, "买二送一活动");
     	pset = set_new(100, compare_product, hashcode);
     	p->sales_set = pset; 

     	for(i = 0; i < array_len(one_free_promotion); i++) {
     		set_put(pset, &one_free_promotion[i]);		 		 
     	}
 
     	/*其次设置优惠活动2信息*/ 
	 PNEW(p, 1, struct promotion_one_info *); //分配活动2商品所需的内存
	 //链表头插法
	 p->next_promotion = promotions->promotion_all_info;
	 promotions->promotion_all_info = p;
	 p->type = DISCOUNT;
	 strcpy(p->statement, "9.5折优惠");
	 pset = set_new(100, compare_product, hashcode);
	 p->sales_set = pset;

	 for(i = 0; i < array_len(discount_promotion); i++) {
		 set_put(pset, &discount_promotion[i]);
	 }
	 
	 return promotions;
}
开发者ID:Alberne,项目名称:tinyprograme,代码行数:56,代码来源:tw.c

示例7: test_set_intersection

void test_set_intersection (void) {
  int numbers1[] = {1, 2, 3, 4, 5, 6, 7};
  int numbers2[] = {5, 6, 7, 8, 9, 10, 11};
  int result[] = {5, 6, 7};
  int i;
  Set* set1;
  Set* set2;
  Set* result_set;
  size_t allocated;

  /* Create the first set */

  set1 = set_new (int_hash, int_equal);

  for (i = 0; i < 7; ++i) {
    set_insert (set1, &numbers1[i]);
    }

  /* Create the second set */

  set2 = set_new (int_hash, int_equal);

  for (i = 0; i < 7; ++i) {
    set_insert (set2, &numbers2[i]);
    }

  /* Perform the intersection */

  result_set = set_intersection (set1, set2);

  assert (set_num_entries (result_set) == 3);

  for (i = 0; i < 3; ++i) {
    assert (set_query (result_set, &result[i]) != 0);
    }

  /* Test out of memory scenario */

  alloc_test_set_limit (0);
  assert (set_intersection (set1, set2) == NULL);

  /* Can allocate set, can't copy all values */

  alloc_test_set_limit (2 + 2);
  allocated = alloc_test_get_allocated();
  assert (set_intersection (set1, set2) == NULL);
  assert (alloc_test_get_allocated() == allocated);

  set_free (set1);
  set_free (set2);
  set_free (result_set);
  }
开发者ID:dlove24,项目名称:dl-calg,代码行数:52,代码来源:test-set.c

示例8: aoi_create

struct aoi_space * 
aoi_create(aoi_Alloc alloc, void *ud) {
	struct aoi_space *space = alloc(ud, NULL, sizeof(*space));
	space->alloc = alloc;
	space->alloc_ud = ud;
	space->object = map_new(space);
	space->watcher_static = set_new(space);
	space->marker_static = set_new(space);
	space->watcher_move = set_new(space);
	space->marker_move = set_new(space);
	space->hot = NULL;
	return space;
}
开发者ID:ChowZenki,项目名称:aoi,代码行数:13,代码来源:aoi.c

示例9: 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;
}
开发者ID:anthonybishopric,项目名称:libcrange,代码行数:51,代码来源:range.c

示例10: link_update_dnssec_negative_trust_anchors

static int link_update_dnssec_negative_trust_anchors(Link *l) {
        _cleanup_strv_free_ char **ntas = NULL;
        _cleanup_set_free_free_ Set *ns = NULL;
        char **i;
        int r;

        assert(l);

        r = sd_network_link_get_dnssec_negative_trust_anchors(l->ifindex, &ntas);
        if (r == -ENODATA) {
                r = 0;
                goto clear;
        }
        if (r < 0)
                goto clear;

        ns = set_new(&dns_name_hash_ops);
        if (!ns)
                return -ENOMEM;

        STRV_FOREACH(i, ntas) {
                r = set_put_strdup(ns, *i);
                if (r < 0)
                        return r;
        }
开发者ID:nmartensen,项目名称:systemd,代码行数:25,代码来源:resolved-link.c

示例11: list_vconsole_keymaps

static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
        _cleanup_strv_free_ char **l = NULL;
        const char *dir;

        keymaps = set_new(string_hash_func, string_compare_func);
        if (!keymaps)
                return log_oom();

        NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS)
                nftw(dir, nftw_cb, 20, FTW_MOUNT|FTW_PHYS);

        l = set_get_strv(keymaps);
        if (!l) {
                set_free_free(keymaps);
                return log_oom();
        }

        set_free(keymaps);

        if (strv_isempty(l)) {
                log_error("Couldn't find any console keymaps.");
                return -ENOENT;
        }

        strv_sort(l);

        pager_open_if_enabled();

        strv_print(l);

        return 0;
}
开发者ID:ariscop,项目名称:systemd,代码行数:32,代码来源:localectl.c

示例12: list_locales

static int list_locales(sd_bus *bus, char **args, unsigned n) {
        _cleanup_set_free_ Set *locales;
        _cleanup_strv_free_ char **l = NULL;
        int r;

        locales = set_new(string_hash_func, string_compare_func);
        if (!locales)
                return log_oom();

        r = add_locales_from_archive(locales);
        if (r < 0 && r != -ENOENT)
                return r;

        r = add_locales_from_libdir(locales);
        if (r < 0)
                return r;

        l = set_get_strv(locales);
        if (!l)
                return log_oom();

        strv_sort(l);

        pager_open_if_enabled();

        strv_print(l);

        return 0;
}
开发者ID:ariscop,项目名称:systemd,代码行数:29,代码来源:localectl.c

示例13: ace_cube_dup

ace_cube_t * ace_cube_dup(ace_cube_t * cube) {
	int i;
	ace_cube_t * cube_copy;

	assert(cube != NULL);
	assert(cube->num_literals > 0);

	cube_copy = malloc(sizeof(ace_cube_t));
	cube_copy->static_prob = cube->static_prob;
	cube_copy->num_literals = cube->num_literals;
	cube_copy->cube = set_new (2 * cube->num_literals);
	for (i = 0; i < cube->num_literals; i++) {
		switch (node_get_literal (cube->cube, i)) {
		case ZERO:
			set_insert(cube_copy->cube, 2 * i);
			set_remove(cube_copy->cube, 2 * i + 1);
			break;
		case ONE:
			set_remove(cube_copy->cube, 2 * i);
			set_insert(cube_copy->cube, 2 * i + 1);
			break;
		case TWO:
			set_insert(cube_copy->cube, 2 * i);
			set_insert(cube_copy->cube, 2 * i + 1);
			break;
		default:
			fail("Bad literal.");
		}
	}

	return (cube_copy);
}
开发者ID:SpectreV,项目名称:HPowerEstimator,代码行数:32,代码来源:cube.c

示例14: set_new

static Set *new_matches(void) {
        Set *set;
        char *tmp;
        int r;

        set = set_new(trivial_hash_func, trivial_compare_func);
        if (!set) {
                log_oom();
                return NULL;
        }

        tmp = strdup("MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1");
        if (!tmp) {
                log_oom();
                set_free(set);
                return NULL;
        }

        r = set_consume(set, tmp);
        if (r < 0) {
                log_error("failed to add to set: %s", strerror(-r));
                set_free(set);
                return NULL;
        }

        return set;
}
开发者ID:gcampax,项目名称:systemd,代码行数:27,代码来源:coredumpctl.c

示例15: graph_resize

/*
 * graph_resize()
 *
 * Resizes graph g to given size.  If size > g->n, the new vertices are
 * not connected to any others and their weights are set to 1.
 * If size < g->n, the last g->n - size vertices are removed.
 */
void graph_resize(graph_t *g, int size) {
	int i;

	ASSERT(g!=NULL);
	ASSERT(g->n > 0);
	ASSERT(size > 0);

	if (g->n == size)
		return;

	/* Free/alloc extra edge-sets */
	for (i=size; i < g->n; i++)
		set_free(g->edges[i]);
	g->edges=realloc(g->edges, size * sizeof(set_t));
	for (i=g->n; i < size; i++)
		g->edges[i]=set_new(size);

	/* Resize original sets */
	for (i=0; i < MIN(g->n,size); i++) {
		g->edges[i]=set_resize(g->edges[i],size);
	}

	/* Weights */
	g->weights=realloc(g->weights,size * sizeof(int));
	for (i=g->n; i<size; i++)
		g->weights[i]=1;
	
	g->n=size;
	return;
}
开发者ID:AlessiaWent,项目名称:igraph,代码行数:37,代码来源:cliquer_graph.c


注:本文中的set_new函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。