Example #1
0
typename tree< T , A >::iterator
tree< T , A >::
insert( iterator it , const value_type & copy /*= value_type()*/ )
{
    NodePtr_t node_ptr;
    if ( get_node_ptr( it ) != root_) {
        NodePtr_t _S = get_node_ptr( it );
        node_ptr = alloc_node( _S->left , _S , 0 );
        allocator_.construct( & node_ptr->value , copy );
        if ( _S == _S->left->child )
            node_ptr->left->child = node_ptr;
        else if ( _S == _S->left->right )
            node_ptr->left->right = node_ptr;
        _S->left = node_ptr;
    } else if ( root_->child != root_ ) {
        NodePtr_t _S = root_->child;
        while ( _S->right != 0 )
            _S = _S->right;
        node_ptr = alloc_node( _S , _S->right , 0 );
        allocator_.construct( & node_ptr->value , copy );
        _S->right = node_ptr;
        if ( node_ptr->right != 0 )
            node_ptr->right->left = node_ptr;
    } else {
        node_ptr = alloc_node( root_ );
        allocator_.construct( & node_ptr->value , copy );
        root_->child = node_ptr;
    } // if
    ++size_;
    return iterator( node_ptr );
} // insert
Example #2
0
static void
pet_test(void)
{
#define NODES	1000000
    node_t *pool, *root;
    struct timeval tv, tv2;
    time_t sec;
    suseconds_t msec;
    int i, j;

    pool = pool_new(NODES);
    j = NODES / 2;
    gettimeofday(&tv, NULL);
    root = alloc_node(pool);
    root = make_node(root, 0);
    for (i = 1; i < NODES; i++, j = (j + 17) % NODES)
        root = insert(root, alloc_node(pool), j);
    while (root)
        root = delete_min(root);
    gettimeofday(&tv2, NULL);
    sec = tv2.tv_sec - tv.tv_sec;
    msec = tv2.tv_usec - tv.tv_usec;
    msec += sec * 1000000;
    printf("%d nodes add/remove: %lu msec\n", NODES, msec);

    pool_release(pool);
}
Example #3
0
void
parse_item(void)
{
    if (!gInItems) {
        fprintf(stderr, "\\item found outside an items environment\n");
        print_page_and_filename();
        print_next_ten_tokens();
        jump();
    }
    curr_node->type = Item;
    get_token();
    if (token.type == Lsquarebrace) {
        /* I should parse the optional argument */
        curr_node->next = alloc_node();
        curr_node = curr_node->next;
        curr_node->type = Description;
        curr_node->next = alloc_node();
        curr_node = curr_node->next;
        gInOptional++;
        parse_HyperDoc();
        gInOptional--;
        curr_node->type = Enddescription;
        if (token.type != Rsquarebrace) {
            fprintf(stderr, "(HyperDoc) Optional arguments must end with ].\n");
            print_next_ten_tokens();
            print_page_and_filename();
            jump();
        }
    }
    else {
        unget_token();
    }
}
Example #4
0
struct node *parse_equality(struct compiler *compiler)
{
    struct node *result = parse_boolean_unary(compiler);

    while(is_equality_op(compiler))
    {
        struct node *node;

        if(lexer_current(compiler) == T_NO_EQUALITY)
            node = alloc_node(compiler,  N_NO_EQUALITY);
        else
        {
            node = alloc_node(compiler,  N_BINARY_OP);
            node->op = lexer_current(compiler);
        }

        node->left = result;

        lexer_next(compiler);

        node->right = parse_boolean_unary(compiler);
        result = node;
    }

    return result;
}
Example #5
0
void
quadtree_build(quadtree_t *curr) {
        short x1 = curr->x1;
        short y1 = curr->y1;
        short x2 = curr->x2;
        short y2 = curr->y2;
        short midx = 0;
        short midy = 0;

        if (x1 == x2 && y1 == y2) {
                return;
        }

        midx = (x1 + x2) >> 1;
        midy = (y1 + y2) >> 1;

        curr->nw = alloc_node(x1, y1, midx, midy);
        quadtree_build(curr->nw);

        if (x1 != x2) {
                curr->sw = alloc_node(midx + 1, y1, x2, midy);
                quadtree_build(curr->sw);
        }
        if (y1 != y2) {
                curr->ne = alloc_node(x1, midy + 1, midx, y2);
                quadtree_build(curr->ne);
        }
        if (x1 != x2 && y1 != y2) {
                curr->se = alloc_node(midx + 1, midy + 1, x2, y2);
                quadtree_build(curr->se);
        }
}
Example #6
0
int 
main()//int argc, char ** argv) CHECK_TYPE
{
  int sz = 5;
  if (sz <= 0)
    return 0;

  list *root, *cur;
  int i = 1;

  root = alloc_node(0);
  for(cur = root; i < sz; i++)
  {
    cur->next = alloc_node(i);
    cur = cur->next;
  }
  
  for(cur = root; cur->next != NULL; cur = cur->next);
  {
    if(cur)
      validptr(cur->next);
  }
  /*   //cur :: { v: ptr(l1,.) | v.id = i} */
  /*   //l1 -> (4: {v: ptr(l2,.) | v = NULL || v.id = i + 1 ^ v != vvaddr - 4}) */
  
}
Example #7
0
File: node.c Project: yipf/C-lisp
node_t quote_node(node_t node,int quote){
	value_t value;
	while(quote--){
		value=alloc_value(SYMBOL,0);
		value->string=unique_string("quote");
		node=alloc_node(value,node);
		node=alloc_node(alloc_value(LIST,node),0);
 	}
	return node;
}
int main ()
{
    int i = 0;
    node *head = NULL;
    srand(10);

    if (!head) {
        head = alloc_node('M');
    }
        push(&head, alloc_node('a'));
        push(&head, alloc_node('l'));
        push(&head, alloc_node('a'));
        push(&head, alloc_node('y'));
        push(&head, alloc_node('a'));
        push(&head, alloc_node('l'));
        push(&head, alloc_node('a'));
        push(&head, alloc_node('M'));
    
  
    printf("\nBefore\n");  
    disp(head);
//    printf("\nAfter\n");  
//    reverse(head);
    reverse_llist(&head);
    printf("\nAfter reversing\n");  
    disp(head);
    printf("\nAfter\n");  
    reverse(head);
}
Example #9
0
void add_conf(char *identifier)
{
    if (search_conf(identifier) != NULL)
        return;
    if (conf_list == NULL) {
        next_conf_iterator = conf_list = last_conf = alloc_node(identifier); 
        return;
    }
    last_conf->next = alloc_node(identifier);
    last_conf = last_conf->next;
}
Example #10
0
void insert_CLRS(NODE * t, int v)
{
	if (dbg_level == 0) {
		fprintf(stderr, "%s%d%s, ", GREEN, v, NOCOLOR);
		rb_insert(t, alloc_node(v, R));
		verify_rbtree(t->L, 0);
	} else {
		printf("%sinsert %d%s\n", GREEN, v, NOCOLOR);
		rb_insert(t, alloc_node(v, R));
		______________________________("./fig/", t, t, "inserted %d", v);
	}
}
Example #11
0
static ucl_node_t
fill (int number_of_elements, int first)
{
  ucl_node_t	R, N, M;
  int		i;
  R = alloc_node(first);
  for (i=1, N = R; i<number_of_elements; ++i) {
    M = alloc_node(i + first);
    ucl_list_set_cdr(N, M);
    N = M;
  }
  return R;
}
Example #12
0
File: node.c Project: yipf/C-lisp
node_t hash_push_value(char* key,node_t value){
	node_t head,target,nvalue;
	head=HASH+key2hash(key,NUM);
	target=get_node(head->cdr,key);
	if(!target){
		target=alloc_node(key);
		target->cdr=head->cdr;
		head->cdr=target;
	}
	nvalue=alloc_node(key);
	nvalue->child=value;
	node->child=push_value(node->child,nvalue);
	return value;
}
Example #13
0
NODE * str2tree(const char ** pstr)
{
	/* examples:
	 *   ()
	 *   (2), (2+)
	 *   (2(1)(3)), (2+(1)(3)), (2(1+)(3+))
	 *   (2(1+)()), (2()(3+))
	 */
	int k;
	const char * p = *pstr;
	NODE * x = 0;

	assert(*p == '(');
	p++;
	assert(isdigit(*p) || *p == ')');
	if (isdigit(*p)) {
		k = 0;
		while (isdigit(*p))
			k = k * 10 + (*p++ - '0');
		if (*p == '+') {
			x = alloc_node(k, R);
			p++;
		} else {
			assert(*p == '(' || *p == ')');
			x = alloc_node(k, B);
		}

		if (*p == '(') {
			x->L = str2tree(&p);
			if (x->L != nil)
				x->L->P = x;

			x->R = str2tree(&p);
			if (x->R !=nil)
				x->R->P = x;
		}
	} else {
		x = nil;
	}
	assert(*p == ')');
	p++;

	printf("processed ");
	for (const char * q = *pstr; q < p; q++)
		printf("%s%c%s",  GREEN, *q, NOCOLOR);
	printf("\n");
	*pstr = p;

	return x;
}
void check_interrupt(void)
{
   struct node* event;

   if (g_dev.r4300.mi.regs[MI_INTR_REG] & g_dev.r4300.mi.regs[MI_INTR_MASK_REG])
      g_cp0_regs[CP0_CAUSE_REG] = (g_cp0_regs[CP0_CAUSE_REG] | CP0_CAUSE_IP2) & ~CP0_CAUSE_EXCCODE_MASK;
   else
      g_cp0_regs[CP0_CAUSE_REG] &= ~CP0_CAUSE_IP2;
   if ((g_cp0_regs[CP0_STATUS_REG] & (CP0_STATUS_IE | CP0_STATUS_EXL | CP0_STATUS_ERL)) != CP0_STATUS_IE) return;
   if (g_cp0_regs[CP0_STATUS_REG] & g_cp0_regs[CP0_CAUSE_REG] & UINT32_C(0xFF00))
   {
      event = alloc_node(&q.pool);

      if (event == NULL)
      {
         DebugMessage(M64MSG_ERROR, "Failed to allocate node for new interrupt event");
         return;
      }

      event->data.count = next_interrupt = g_cp0_regs[CP0_COUNT_REG];
      event->data.type = CHECK_INT;

      if (q.first == NULL)
      {
         q.first = event;
         event->next = NULL;
      }
      else
      {
         event->next = q.first;
         q.first = event;

      }
   }
}
Example #15
0
void check_interupt(void)
{
   struct node *event;

   if ((g_r4300.mi.regs[MI_INTR_REG] & g_r4300.mi.regs[MI_INTR_REG]))
      g_cp0_regs[CP0_CAUSE_REG] = (g_cp0_regs[CP0_CAUSE_REG] | UINT32_C(0x400)) & UINT32_C(0xFFFFFF83);
   else
      g_cp0_regs[CP0_CAUSE_REG] &= ~UINT32_C(0x400);
   if ((g_cp0_regs[CP0_STATUS_REG] & UINT32_C(7)) != 1)
      return;
   if (g_cp0_regs[CP0_STATUS_REG] & g_cp0_regs[CP0_CAUSE_REG] & UINT32_C(0xFF00))
   {
      event = alloc_node(&q.pool);

      if (!event)
      {
         DebugMessage(M64MSG_ERROR, "Failed to allocate node for new interrupt event");
         return;
      }

      event->data.count = next_interupt = g_cp0_regs[CP0_COUNT_REG];
      event->data.type = CHECK_INT;

      if (!q.first)
      {
         q.first = event;
         event->next = NULL;
      }
      else
      {
         event->next = q.first;
         q.first = event;
      }
   }
}
Example #16
0
node_t* make_string_node(char *literal)
{
	node_t *node = alloc_node();
	node->type = STRING;
	node->value.string_literal = literal;
	return node;
}
Example #17
0
node_t* make_field_node(char *fieldname)
{
	node_t *node = alloc_node();
	node->type = FIELD;
	node->value.field.fieldname = fieldname;
	return node;
}
Example #18
0
/*
 * get_node()
 *	Return node, either from hash or created from scratch
 */
struct openfile *
get_node(daddr_t d)
{
	struct openfile *o;

	/*
	 * From hash?
	 */
	o = hash_lookup(node_hash, d);
	if (o) {
		/*
		 * Yes--add a reference, and return
		 */
		ref_node(o);
		return(o);
	}

	/*
	 * Get a new one, and return it
	 */
	o = alloc_node(d);
	if (hash_insert(node_hash, d, o)) {
		deref_node(o);
		o = 0;
	}
	return(o);
}
dmp_pos dmp_range_init(
	dmp_pool *pool, dmp_range *run,
	int op, const char *data, uint32_t offset, uint32_t len)
{
	run->start = run->end = alloc_node(pool, op, data, offset, len);
	return run->start;
}
Example #20
0
NODE * init_rbtree(const char * tstr)
{
	nil = alloc_node(-1, B); /* the sentinel */
	nil->P = nil;
	nil->L = nil;
	nil->R = nil;

	NODE * head= alloc_node(INT_MAX, B);
	head->P = nil;
	head->L = str2tree(&tstr);
	head->R = nil;

	assert(*tstr == '\0');

	return head;
}
Example #21
0
int
main()
{
	node_t *temp;
	node_t *root = alloc_node(1);
	root->next = alloc_node(2);
	root->next->next = alloc_node(3);
	root->next->next->next = alloc_node(4);	
	root->next->next->next->next = alloc_node(5);	

	root = remove_elem(&root, 1);

	for (temp = root; temp != NULL; temp = temp->next) {
		printf("%d \n", temp->val);
	}
}
struct Node* insert_node(struct Node* list, int val1, int val2) {
	struct Node* node = alloc_node();
	node->val1 = val1;
	node->val2 = val2;
	node->next = list;
	return node;
}
Example #23
0
    bool enqueue(T const & t)
    {
        node * n = alloc_node(t);

        if (n == NULL)
            return false;

        for (;;)
        {
            atomic_node_ptr tail (tail_);
            read_memory_barrier();
            atomic_node_ptr next (tail->next);

            if (likely(tail == tail_))
            {
                if (next.get_ptr() == 0)
                {
                    if ( tail->next.cas(next, n) )
                    {
                        tail_.cas(tail, n);
                        return true;
                    }
                }
                else
                    tail_.cas(tail, next.get_ptr());
            }
        }
    }
Example #24
0
void
parse_begin_items(void)
{
    TextNode *bi = curr_node;

    /*
     * This procedure parses a begin item. It sets the current
     * node and sees if there is an optional argument for the itemspace
     */

    bi->type = token.type;
    get_token();
    if (token.type == Lsquarebrace) {
        bi->data.node = alloc_node();
        curr_node = bi->data.node;
        gInOptional++;
        parse_HyperDoc();
        gInOptional--;
        curr_node->type = Enddescription;
        if (token.type != Rsquarebrace) {
            fprintf(stderr, "(HyperDoc) Optional arguments must end with ].\n");
            print_next_ten_tokens();
            print_page_and_filename();
            jump();
        }
        curr_node = bi;
    }
    else
        unget_token();
    gInItems++;
}
dmp_pos dmp_range_insert(
	dmp_pool *pool, dmp_range *run, dmp_pos pos,
	int op, const char *data, uint32_t offset, uint32_t len)
{
	dmp_node *node;
	dmp_pos added_at = alloc_node(pool, op, data, offset, len);
	if (added_at < 0)
		return pos;

	node = dmp_node_at(pool, added_at);

	if (pos == -1) {
		dmp_node *end = dmp_node_at(pool, run->end);
		node->next = end->next;
		end->next  = added_at;
		run->end   = added_at;
	}
	else if (pos == 0) {
		node->next = run->start;
		run->start = added_at;
	}
	else {
		dmp_node *after = dmp_node_at(pool, pos);
		node->next  = after->next;
		after->next = added_at;
	}

	return added_at;
}
Example #26
0
node_t* make_int_node(int literal)
{
	node_t *node = alloc_node();
	node->type = INT;
	node->value.int_literal = literal;
	return node;
}
Example #27
0
static struct name_id* parse_line(char *line)
{
	char *p;
	int i;
	char id_buf[MAX_ID_LEN+1];
	struct name_id *node;
	node = alloc_node();
	p = line;
	i = 0;
	// Get name field
	while (*p != ':') {
		if (i > MAX_NAME_LEN)
			error_msg_and_die("Name field too long");
		node->name[i++] = *p++;
	}
	node->name[i] = '\0';
	p++;
	// Skip the second field
	while (*p != ':')
		p++;
	p++;
	// Get id field
	i = 0;
	while (*p != ':') {
		if (i > MAX_ID_LEN)
			error_msg_and_die("ID filed too long");
		id_buf[i++] = *p++;
	}
	id_buf[i] = '\0';
	node->id = atol(id_buf);
	return node;
}
Example #28
0
node_t* make_op_node(enum operation op)
{
	node_t* node = alloc_node();
	node->type = OP;
	node->value.op = op;
	return node;
}
Example #29
0
EC_API ec_list ec_list_copy( ec_list list )
{
	ec_list          newlist;
	ec_list_iterator iter;
	ec_list_node     node, newnode, last;

	check_list(list);

	newlist = ec_list_create();
	if (! newlist) return NULL;

	last = NULL;
	iter = ec_list_iterator_create( list );
	while ((node = ec_list_iterator_next( iter )))
	{
		check_node(node);
		newnode = alloc_node( KEY(node), DATA(node) );
		ASSERT( newnode );
		if (! newnode) return NULL;								/* argh ! */
		if (last)
			NEXT(last) = newnode;
		else
		{
			HEAD(newlist) = newnode;
			last          = newnode;
		}
	}
	ec_list_iterator_destroy( iter );

	check_list(newlist);
	return newlist;
}
Example #30
0
File: node.c Project: yipf/C-lisp
node_t clone_node(node_t src,node_t dst){
	if
	dst=dst?alloc_node(src->key);
	
	node_t dst=calloc(1,sizeof(node_));
	return HEAD=dst;
}