Exemple #1
0
/* {{{1
 * Create a new node with the given key and value.  Uses the memory allocation
 * scheme outlined above.
 */
static RBTreeNode *
rb_tree_node_new(pointer key,
		 pointer value,
		 RBTreeNode *parent,
		 RBTreeNodeColor color)
{
	RBTreeNode *node;

	G_LOCK(node_free_list);
	if (node_free_list) {
		node = node_free_list;
		node_free_list = node->left;
	} else {
		node = new_struct(RBTreeNode);
	}
	G_UNLOCK(node_free_list);

	node->left = rb_null;
	node->right = rb_null;
	node->parent = parent;
	node->color = color;
	node->key = key;
	node->value = value;

	return node;
}
Exemple #2
0
///////////////////////////////////////////////////////////////////////////////////
//...функци¤ образовани¤ контекста дл¤ базы данных защитного оборудовани¤ проводов;
void * CreateFITTINGContext(int N_sm)
{
	if (N_sm < 0 || N_sm >= NUM_FITTING_SAMPLES) N_sm = 0;

	Context * cont = (Context *)new_struct(sizeof(Context));
	if (! cont) return(NULL);

	cont->N           = N_sm+SHIFT_FITTING_SAMPLES;
	cont->static_char = SPECIAL_STATE;
	cont->sample_name = GetFITTINGSampleName(N_sm);
	cont->GOST_name   = GetFITTINGGOSTName  (N_sm);
	cont->units       = UNIT_WIRE;

	switch (cont->N-SHIFT_FITTING_SAMPLES) {
		case _FITTING1: cont->table = fitting_NS (cont->static_char); break; //Ќ—-;
      case _FITTING2: cont->table = fitting_PS (cont->static_char); break; //ѕ—-;
      case _FITTING3: cont->table = fitting_PZS(cont->static_char); break; //ѕ«—-;
      case _FITTING4: cont->table = fitting_GV (cont->static_char); break; //√¬-;
  }
  set_default    (cont);
  set_table_units(cont->table, UNIT_WIRE);
  
  SetTableIndex(cont, 1);
  SetUnits     (cont, UNIT_WIRE); return (void *)cont;
}
Exemple #3
0
/* {{{1
 * Create a new priority queue with a starting size.  ‘equal’ may be ‹null›,
 * but ‘compare’ must be non-‹null›.
 */
PriorityQueue *
priority_queue_sized_new(CompareFunc compare, EqualFunc equal, size_t size)
{
	invariant(compare != null);

	PriorityQueue *q = new_struct(PriorityQueue);
	q->compare = compare;
	q->equal = equal;
	q->size = size;
	q->heap = new_array(pointer, q->size + 1);
	q->len = 0;

	return q;
}
VALUE
rb_struct_define(const char *name, ...)
{
    va_list ar;
    VALUE st, ary;
    char *mem;

    ary = rb_ary_tmp_new(0);

    va_start(ar, name);
    while ((mem = va_arg(ar, char*)) != 0) {
        ID slot = rb_intern(mem);
        rb_ary_push(ary, ID2SYM(slot));
    }
    va_end(ar);

    if (!name) st = anonymous_struct(rb_cStruct);
    else st = new_struct(rb_str_new2(name), rb_cStruct);
    return setup_struct(st, ary);
}
static VALUE
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
{
    VALUE name, rest;
    long i;
    VALUE st;
    ID id;

    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
    name = argv[0];
    if (SYMBOL_P(name)) {
        name = Qnil;
    }
    else {
        --argc;
        ++argv;
    }
    rest = rb_ary_tmp_new(argc);
    for (i=0; i<argc; i++) {
        id = rb_to_id(argv[i]);
        RARRAY_ASET(rest, i, ID2SYM(id));
        rb_ary_set_len(rest, i+1);
    }
    if (NIL_P(name)) {
        st = anonymous_struct(klass);
    }
    else {
        st = new_struct(name, klass);
    }
    setup_struct(st, rest);
    if (rb_block_given_p()) {
        rb_mod_module_eval(0, 0, st);
    }

    return st;
}
Exemple #6
0
Var* ff_boxfilter(vfuncptr func, Var* arg)
{
	Var* v = NULL;
	Var *rcount, *rmean, *rs, *rn, *rsigma;
	Var* a;
	int x         = 0;
	int y         = 0;
	int z         = 0;
	int size      = 0;
	double ignore = FLT_MIN;
	int verbose   = 0;

	Alist alist[8];
	alist[0]      = make_alist("obj", ID_VAL, NULL, &v);
	alist[1]      = make_alist("x", DV_INT32, NULL, &x);
	alist[2]      = make_alist("y", DV_INT32, NULL, &y);
	alist[3]      = make_alist("z", DV_INT32, NULL, &z);
	alist[4]      = make_alist("size", DV_INT32, NULL, &size);
	alist[5]      = make_alist("ignore", DV_DOUBLE, NULL, &ignore);
	alist[6]      = make_alist("verbose", DV_INT32, NULL, &verbose);
	alist[7].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);
	if (v == NULL) {
		parse_error("%s(): No object specified\n", func->name);
		return (NULL);
	}
	if (x && y && size) {
		parse_error("%s(): Specify either size or (x, y, z), not both", func->name);
		return (NULL);
	}
	if (x == 0) x    = 1;
	if (y == 0) y    = 1;
	if (z == 0) z    = 1;
	if (size != 0) x = y = size;

	if (x == 0 || y == 0) {
		parse_error("%s(): No x or y specified", func->name);
		return (NULL);
	}

	init_sums(v, x, y, z, &rn, &rs, &rcount, &rmean, &rsigma, ignore);

	if (verbose) {
		a = new_struct(0);
		add_struct(a, "count", rcount);
		add_struct(a, "mean", rmean);
		add_struct(a, "sigma", rsigma);
		add_struct(a, "n", rn);
		add_struct(a, "s", rs);
		return (a);
	} else {
		mem_claim(rcount);
		free_var(rcount);
		mem_claim(rn);
		free_var(rn);
		mem_claim(rs);
		free_var(rs);
		return (rmean);
	}
}