Beispiel #1
0
void handle_remap(PARSER_STATE *ps) {
   NODE *tok;
   int remap_values;
   
   ps->ignore_semicolon=0;

   tok=get_token(ps);
   if (tok->type!=nt_keyword)
     parse_error(ps,"remap direction must be a keyword");
   else if (strcmp(tok->cp,"values")==0)
     remap_values=1;
   else if (strcmp(tok->cp,"vals")==0)
     remap_values=1;
   else if (strcmp(tok->cp,"keys")==0)
     remap_values=0;
   else
     parse_error(ps,"unknown remap direction %s",tok->cp);
   node_delete(tok);
   
   tok=get_token(ps);   
   if ((tok->type!=nt_keyword) || (strcmp(tok->cp,"{")!=0))
     parse_error(ps,"remap must be given a context");
   node_delete(tok);
   
   handle_opening_brace(ps);
   context_stack->generator=remap_values?gen_value_remap:gen_key_remap;
   arrow_map_delete(&(context_stack->am));
   arrow_map_new(&(context_stack->am));
}
Beispiel #2
0
void handle_default(PARSER_STATE *ps) {
   NODE *tok;

   if (context_stack->default_value!=NULL) {
      node_delete(context_stack->default_value);
      context_stack->default_value=NULL;
   }
   
   ps->ignore_semicolon=0;
   tok=get_token(ps);

   if (tok->type!=nt_keyword) {
      context_stack->default_policy=dp_value;
      context_stack->default_value=tok;
      tok->refs++;
   } else if (strcmp(tok->cp,"any")==0)
	context_stack->default_policy=dp_any;
   else if (strcmp(tok->cp,"fail")==0)
     context_stack->default_policy=dp_fail;
   else if (strcmp(tok->cp,"null")==0)
     context_stack->default_policy=dp_null;
   else
     parse_error(ps,"unknown default policy keyword %s",tok->cp);
   
   node_delete(tok);
   ps->ignore_semicolon=1;
}
Beispiel #3
0
void node_delete(node_t *n)
{
	if (!is_nil(n->left))
		node_delete(n->left);
	if (!is_nil(n->right))
		node_delete(n->right);

	free(n);
}
Beispiel #4
0
sval_t
seq_delete(intset_t* set, skey_t key)
{
  node_t* curr = set->head;
  node_t* ppred = NULL;
  node_t* pred = NULL;

  while (likely(curr != NULL && !curr->leaf))
    {
      ppred = pred;
      pred = curr;
      skey_t curr_key = curr->key;
      if (key < curr_key)
	{
	  curr = (node_t*) curr->left;
	}
      else
	{
	  curr = (node_t*) curr->right;
	}
    }

  node_t* other;
  if (curr && curr->key == key)
    {
      if (pred->left == curr)
	{
	  pred->left = NULL;
	  other = (node_t*) pred->right;
	}
      else
	{
	  pred->right = NULL;
	  other = (node_t*) pred->left;
	}

      if (ppred != NULL && other == NULL)
	{
	  if (ppred->left == pred)
	    {
	      ppred->left = NULL;
	    }
	  else
	    {
	      ppred->right = NULL;
	    }
	  node_delete(pred);
	}

      node_delete(curr);
      return curr->val;
    }

  return 0;
}
Beispiel #5
0
void node_delete(NODE* node)
{
	if (!node)
		return;

	symbol_delete(node->symbol);

	if (node->left)
		node_delete(node->left);

	if (node->right)
		node_delete(node->right);

	free(node);
}
Beispiel #6
0
void tree_delete(tree_t *tree)
{
	if (!is_nil(tree->root))
		node_delete(tree->root);

	free(tree);
}
Beispiel #7
0
gboolean
node_try_delete(node_t* node)
{
    g_assert (node);

    FN_W ("%s 0x%p %s\n", __func__, node, NODE_NAME(node));

    /* Try clean children */
    if (node_children_num (node) > 0) {
        g_hash_table_foreach_remove(node->children, children_remove_cb, NULL);
    }
    if (!NODE_NEED_MONITOR(node)) {
        /* Clean some flags. */
        /* NODE_CLE_FLAG(node, NODE_FLAG_HAS_SNAPSHOT | NODE_FLAG_STAT_DONE); */
        node->flag = 0;

        /* Now we handle the state. */
        if (NODE_HAS_STATE(node, NODE_STATE_ASSOCIATED)) {
            port_remove(node);
        }
        /* Actually ignore the ROOT node. */
        if (node->state == 0 && NODE_PARENT(node)) {
            children_remove(NODE_PARENT(node), node);
            /* Do clean instead of returning TRUE. */
            node_delete (node);
        }
        /* else, we have events, clean event queue? */
    }
    return FALSE;
}
Beispiel #8
0
bool
rbtree_delete(struct rbtree *tree, ipaddr_t IP)
{
  struct rbtree_elem *parent, *succ, *pred, *node;

  if (!rbtree_search(tree, IP, &node)) {
    return false;
  }

  if (node->low == IP) {
    if (node->high == IP) {
      node_delete(&tree->root, node) ;
    } else {
      node->low++ ;
    }
  } else if (node->high == IP) {
    node->high--;
  } else {
    rbnode_t new_node;
    new_node = malloc(sizeof(struct rbtree_elem)) ;
    ASSERT(new_node);
    ASSERT(node->low < IP && node->high > IP) ;
    new_node->low=IP+1 ; new_node->high=node->high ;
    new_node->left=new_node->right=new_node->parent=nil ;
    new_node->color = _RED_ ;
    node->high = IP - 1;
    node_insert_at(&tree->root, node, new_node);
  }
  return true;
}
static u8 ml_wc_nodes_create(c8 *parent_topSUB, u16 toplen, u8 qid, void *usr_cl)
{
    struct topic_node *parent_leaf = NULL;

    if('\0' != parent_topSUB[0]) {
        parent_leaf = SUB_node_create(parent_topSUB, qid, usr_cl);
        if(NULL == parent_leaf)
            return QFL_VALUE;
    }

    /* Get the topic SUB to it's original state */
    if(toplen > 1) parent_topSUB[toplen - 2] = '/';
    parent_topSUB[toplen - 1] = '#';

    if(NULL == SUB_node_create(parent_topSUB, qid, usr_cl)) {
        /* Failed to create WC topic, so delete parent as well.
           In this revision, 'parent_leaf' will not be a 'NULL'
           at this juncture, nevertheless a check (for tools) */
        if(parent_leaf)
            node_delete(parent_leaf);

        return QFL_VALUE;
    }

    return qid;
}
END_TEST

START_TEST(test_node_delete)
{
    node *root = node_new("d", "definition");
    node *l = node_new("b", "b");
    node *ll = node_new("a", "a");
    node *lr = node_new("c", "c");

    node_insert(root, l);
    node_insert(root, ll);
    node_insert(root, lr);

    // ensure correct insertions
    ck_assert_ptr_eq(l, root->left);
    ck_assert_ptr_eq(ll, root->left->left);
    ck_assert_ptr_eq(lr, root->left->right);

    ck_assert_int_eq(4, node_size(root));

    ck_assert_ptr_eq(l, node_delete(root, "b"));

    // ensure correct reinsertion
    ck_assert_ptr_eq(ll, root->left);
    ck_assert_ptr_eq(NULL, root->right);
    ck_assert_ptr_eq(NULL, root->left->left);
    ck_assert_ptr_eq(lr, root->left->right);

    // node is not found in the tree anymore
    ck_assert_ptr_eq(NULL, node_search(root, "b"));

    ck_assert_int_eq(3, node_size(root));

    node_free(root);
}
Beispiel #11
0
void trie_delete(trie_tree *tree, const wchar_t *word)
{
	assert(tree != NULL);
	if(tree->root == NULL)
		return;
	tree->root = node_delete(tree->root, word);
}
Beispiel #12
0
int
main(void)
{
    //int         i;
    RB_TREE     *T;

    T = tree_init();

    node_insert(T, 23);
    node_insert(T, 94);
    node_insert(T, 32);
    node_insert(T, 84);
    node_insert(T, 12);
    node_insert(T, 8);
    node_insert(T, 82);
    node_insert(T, 31);
    node_insert(T, 59);
    node_insert(T, 41);
    node_insert(T, 73);

    //for ( i = 0 ; i < 1000 ; i++ ) {
    //    key = rand() % 1000;
    //    node_insert(T, key);
    //}


    inorder_tree_walk(T, T->root);
    printf("\n");

    node_delete(T, 32);
    node_delete(T, 8);
    node_delete(T, 4);

    printf("after delete 32, 8, 4:\n");
    inorder_tree_walk(T, T->root);
    printf("\n");

    printf("sucessor of 23 is %d\n", rbtree_successor(T, rbtree_search(T, T->root, 23))->key);
    printf("predecessor of 84 is %d\n", rbtree_predecessor(T, rbtree_search(T, T->root, 84))->key);
    printf("the maximun is %d\n", rbtree_maximum(T, T->root)->key);
    printf("the minimum is %d\n", rbtree_minimum(T, T->root)->key);

    node_destory(T, T->root);
    tree_destory(T);

    exit(0);
}
u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    struct dsp_uuid node_uuid;
    u32 cb_data_size = 0;
    u32 __user *psize = (u32 __user *) args->args_node_allocate.args;
    u8 *pargs = NULL;
    struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
    struct node_res_object *node_res;
    int nodeid;
    void *hprocessor = ((struct process_context *)pr_ctxt)->processor;


    if (psize) {
        if (get_user(cb_data_size, psize))
            status = -EPERM;

        cb_data_size += sizeof(u32);
        if (!status) {
            pargs = kmalloc(cb_data_size, GFP_KERNEL);
            if (pargs == NULL)
                status = -ENOMEM;

        }
        CP_FM_USR(pargs, args->args_node_allocate.args, status,
                  cb_data_size);
    }
    CP_FM_USR(&node_uuid, args->args_node_allocate.node_id_ptr, status, 1);
    if (status)
        goto func_cont;

    if (args->args_node_allocate.attr_in) {
        CP_FM_USR(&proc_attr_in, args->args_node_allocate.attr_in,
                  status, 1);
        if (!status)
            attr_in = &proc_attr_in;
        else
            status = -ENOMEM;

    }
    if (!status) {
        status = node_allocate(hprocessor,
                               &node_uuid, (struct dsp_cbdata *)pargs,
                               attr_in, &node_res, pr_ctxt);
    }
    if (!status) {
        nodeid = node_res->id + 1;
        CP_TO_USR(args->args_node_allocate.node, &nodeid,
                  status, 1);
        if (status) {
            status = -EFAULT;
            node_delete(node_res, pr_ctxt);
        }
    }
func_cont:
    kfree(pargs);

    return status;
}
Beispiel #14
0
Datei: list.c Projekt: karoon/431
void node_delete(node n) {
   if (n) {
      if (n->next)
         node_delete(n->next);
      free(n);
      n = 0;
   }
}
Beispiel #15
0
void scope_delete(SCOPE* scope)
{
	int i;
	for (i = 0; i < MAX_SYMBOL_TYPES; i++)
		node_delete(scope->node[i]);

	free(scope);
}
/* Modify is slightly trickier. The basic idea is we simply delete the
 * object and create it with the new parameters. Then we need to mark the
 * objects that depend on this one */
int output_pgsql_t::node_modify(osmium::Node const &node)
{
    if (!m_options.slim) {
        fprintf(stderr, "Cannot apply diffs unless in slim mode\n");
        util::exit_nicely();
    }
    node_delete(node.id());
    node_add(node);
    return 0;
}
Beispiel #17
0
/* Delete Node */
ptr_t DeleteSuccessor(data_t *myHeap, data_t *Master2SysAlloc, int *fixedStack, int stackPtr_avl, ptr_t rootPtr, int key){
	int flag_stop = 0;
	ptr_t nowPtr = rootPtr;
	struct stack_t stackOutput;
	int flag_stackIsUsed = 0;
	while(flag_stop == 0){
		struct sub_t subResult = DeleteSuccessorSub(myHeap, nowPtr, key);
		if(subResult.feedback == FB_DONE){
			flag_stop = 1;
			// --------- Deletion ---------
			node_delete(Master2SysAlloc, nowPtr);
			nowPtr = NULL_PTR;		
			// --------- Balancing ---------
			if(flag_stackIsUsed == 0){
				rootPtr = NULL_PTR;
				
			}else{
				stackOutput = AVL_STACK_READ(fixedStack, stackPtr_avl);	
				stackPtr_avl = stackOutput.hdPtr_avl;		
				if(stackOutput.operation == GOING_LEFT){
					node_set_left(myHeap, stackOutput.pointer, nowPtr);
				}else{
					node_set_right(myHeap, stackOutput.pointer, nowPtr);
				}
				while(stackPtr_avl > 0){
					nowPtr = stackOutput.pointer;
					ptr_t nowPtr_new = ProcessNodeDeletion(myHeap, nowPtr);		
					stackOutput = AVL_STACK_READ(fixedStack, stackPtr_avl);
					stackPtr_avl = stackOutput.hdPtr_avl;				
					if(nowPtr_new != nowPtr){
						if(stackOutput.operation == GOING_LEFT){
							node_set_left(myHeap, stackOutput.pointer, nowPtr_new);
						}else{
							node_set_right(myHeap, stackOutput.pointer, nowPtr_new);
						}					
					}
				}			
				rootPtr = ProcessNodeDeletion(myHeap, stackOutput.pointer);			
			}
		}else{
			flag_stackIsUsed = 1;
			if(subResult.feedback == FB_LEFT){
				stackOutput = AVL_STACK_WRITE(fixedStack, stackPtr_avl, nowPtr, GOING_LEFT);
				stackPtr_avl = stackOutput.hdPtr_avl;
				nowPtr = node_get_left_pointer(myHeap, nowPtr);
			}else{
				stackOutput = AVL_STACK_WRITE(fixedStack, stackPtr_avl, nowPtr, GOING_RIGHT);
				stackPtr_avl = stackOutput.hdPtr_avl;
				nowPtr = node_get_right_pointer(myHeap, nowPtr);
			}
		}		
	}
	return rootPtr;
}
Beispiel #18
0
/* Modify is slightly trickier. The basic idea is we simply delete the
 * object and create it with the new parameters. Then we need to mark the
 * objects that depend on this one */
int output_pgsql_t::node_modify(osmid_t osm_id, double lat, double lon, const taglist_t &tags)
{
    if( !m_options.slim )
    {
        fprintf( stderr, "Cannot apply diffs unless in slim mode\n" );
        util::exit_nicely();
    }
    node_delete(osm_id);
    node_add(osm_id, lat, lon, tags);
    return 0;
}
Beispiel #19
0
bool map_remove(Map *map, const void *key) {
	bool ret = false;
	map->root = node_delete(map->root, key, &ret);
	map->root->color = BLACK;

	if (ret) {
		--(map->size);
    }

	return ret;
}
Beispiel #20
0
static void node_delete(struct btree_node *node, struct btree *btree)
{
	unsigned int i, count = node->count;

	if (!node->depth) {
		if (btree->destroy) {
			for (i=0; i<count; i++)
				btree->destroy((void*)node->item[i], btree->destroy_ctx);
		}
	} else {
		for (i=0; i<count; i++) {
			node_delete(node->branch[i], btree);
			if (btree->destroy)
				btree->destroy((void*)node->item[i], btree->destroy_ctx);
		}
		node_delete(node->branch[count], btree);
	}

	free(node);
}
Beispiel #21
0
void queue_delete(Queue *queue) {
    if (queue != 0) {
        Node *ptr = queue->top;
        Node *last;
        while (ptr != 0) {
            last = ptr;
            ptr = node_get_next(ptr);
            node_delete(last);
        }
        free(queue);
    }
}
Beispiel #22
0
inline void page_pickSchedule() {
  static byte prev_index = 0;
  if(pre_page != PICK_SCHEDULE) {
    PTLS(" Page Pick Schedule");
    lcd.cursor();
    pre_page = PICK_SCHEDULE; 
    node_index = node_index % (node_size()-1);
    prev_index = node_index + 1;
  }
  
  if (prev_index != node_index) {
    prev_index == node_index;
    schedule s = node_get(node_index);
    String t = getTimeString(s);
    if (mod) lcd.print(F("Mod:"));
    else lcd.print(F("Del: "));
    lcd.print(t);
    lcd.setCursor(0,1);
    lcd.print("Targ Temp: " + (String)s.temperature);
  }
  
  if (button_input == PLUS_UP || button_input == PLUS_HOLD)
  {
    node_index += 1;
    if (node_index >= node_size())
      node_index = 0;
  }
  else if (button_input == MINUS_UP || button_input == MINUS_HOLD)
  {
    node_index -= 1;
    if(node_index < 0) {
      node_index = (node_size()-1);
    }
  }
  else if (button_input == SET_UP)
  {
    if(mod) {
      switchPage(MODIFY_SCHEDULE);
    } else {
      PTLS("Node deleted");
      node_delete(node_index);
      node_index = (node_size()-1);
      prev_index = node_index + 1;
    }
  }
  else if (button_input == MODE_UP)
  {
    switchPage(LIST_MODE);
  }
}
Beispiel #23
0
//~~~~~~~~~~~~~~~~~MAIN~~~~~~~~~~~~~~~~~~~~~~~
int main(int argc, char* argv[]){
  int debug = 0, flag = 1, arg, numRead = 0;
  char command, *stream;
  Line line = line_init( stdin);
  gen_parse_args( argc, argv, &debug);
  Htable htable = ht_init( ht_mod_hash);

  while(flag){
    arg = -1;
    fprintf( stdout, "\ncommand: ");
    line_read_line( line);
    stream = get_line( line);
    sscanf( stream, " %c%n", &command, &numRead);
    switch( command){
      case 'q': flag = 0; break;
      case 'i': sscanf( stream+numRead, "%d", &arg);
                if( arg < 0) fprintf( stderr, "MUST BE >= 0\n");
                else ht_add( htable, arg, arg, debug);
                break;
      case 'd': sscanf( stream+numRead, "%d", &arg);
                if( arg < 0) fprintf( stderr, "MUST BE >= 0\n");
                else{
                  int pos = ht_mod_hash( htable, arg);
                  node_delete( &((htable->table)[pos]), arg, arg, debug); 
                }
                break;
      case 'c': sscanf( stream+numRead, "%d", &arg);
                if( arg < 0) fprintf( stderr, "MUST BE >= 0\n");
                else{
                  if( ht_exists( htable, arg, debug) )
                    fprintf( stdout, "The value, %d, exists!\n", arg);
                  else
                    fprintf( stdout, "The value, %d, does NOT exist\n", arg);
                }
                break;
      case 'e': ht_erase( htable); break;
      case 'r': sscanf( stream+numRead, "%d", &arg);
                if( arg >= 1) ht_resize( htable, arg, debug);
                else fprintf( stderr, "Error, size must be >= 1\n");
                break;
      case 'l': ht_list( htable); break;
      case '\n': break;
      default: fprintf( stdout, "Sorry, Invalid command\n"); break;
    }
    free(stream);
  }
  line_free( line);
  ht_free( htable);
  return 0;
}
u32 nodewrap_delete(union trapped_args *args, void *pr_ctxt)
{
    u32 ret;
    struct node_res_object *node_res;

    find_node_handle(&node_res, pr_ctxt, args->args_node_delete.node);

    if (!node_res)
        return -EFAULT;

    ret = node_delete(node_res, pr_ctxt);

    return ret;
}
Beispiel #25
0
/**
 * Deletes the node which points to the requested data.
 *
 * Should be safe when called in parallel with other threads that
 * might call the same functions. Uses fine grained locking.
 *
 * @param root       root of the tree
 * @param comparator function used to compare nodes
 * @param data       pointer to the data to be deleted
 * @return           1 if data is not found, 0 otherwise
 */
int
node_delete_ts_fg(struct bst_node** root, comparator compare, void* data)
{
    /* TODO: Fill-in the body of this function */
    
    //struct bst_node** node = search(root, compare, data);
    struct bst_node** node = root;
    if (node == NULL)
        return -1;
    else 
    {   
        node_delete(node, compare, data);
        return 0;
    }
}
static void try_node_delete(struct topic_node *node)
{
    while(node) {

        if(is_node_retain(node) ||
                is_node_willed(node) ||
                enrolls_plugin(node) ||
                node->cl_map[0]      ||
                node->cl_map[1]      ||
                node->cl_map[2])
            break;

        node = node_delete(node);
    }
}
Beispiel #27
0
void
rbtree_delete(struct rbtree *tree, struct rbtree_elem *elem)
{
#if 0
  struct rbtree_elem *parent, *succ, *pred, *node;

  //rbtree_inorder_check(tree) ;
  if (!(node = rbtree_find(tree, elem))) {
    //rbtree_inorder_check(tree) ;
    return false;
  }
#endif

  node_delete(tree, elem) ;
  //rbtree_inorder_check(tree) ;
}
Beispiel #28
0
bool
rbtree_insert(struct rbtree *tree, ipaddr_t IP)
{
  rbnode_t root, node, parent, succ, pred;

  root = tree->root;
  if (search_pred_succ(root, IP, &succ, &pred)) {
    return false;
  }

  if (pred != nil && pred->high == IP - 1) {
    if (succ != nil && succ->low == IP+1) {
      //log_printf("succ!=nil & pred!=nil.\n") ;

      ipaddr_t high = succ->high ;
      //inorder_check(*tree) ;
      node_delete(&tree->root, succ) ;
      //inorder_check(*tree);
      node = pred;
      pred->high = high;
      //if (pred->parent!=nil && pred->parent->left==pred) ASSERT(pred->high<pred->parent->low) ;
      //if (pred->right!=nil) ASSERT(pred->high<pred->right->low) ;
    } else {
      node = pred;
      pred->high = IP;
    }
  } else if (succ!=nil && succ->low==IP+1) {
    node = succ;
    succ->low=IP;
  } else {
    rbnode_t new_node;
    new_node = malloc(sizeof(struct rbtree_elem));
    ASSERT(new_node);
    new_node->low = new_node->high = IP;
    new_node->left = new_node->right = new_node->parent = nil;
    new_node->color = _RED_;

    node = new_node;
    node_insert(&tree->root, new_node);
  }
  //if (node->parent!=nil && node->parent->left==node) ASSERT(node->high<node->parent->low) ;
  //if (node->parent!=nil && node->parent->right==node) ASSERT(node->low>node->parent->high) ;
  //if (node->right!=nil) ASSERT(node->high<node->right->low) ;
  //if (node->left!=nil) ASSERT(node->low>node->left->high) ;
  //inorder_check(*tree) ;
  return true;
}
Beispiel #29
0
void handle_return(PARSER_STATE *ps) {
   NODE *tok;
   
   ps->ignore_semicolon=0;
   tok=get_token(ps);

   if (tok->type!=nt_keyword)
     parse_error(ps,"return policy must be a keyword");
   else if (strcmp(tok->cp,"pointer")==0)
     context_stack->return_pointer=1;
   else if (strcmp(tok->cp,"value")==0)
     context_stack->return_pointer=0;
   else
     parse_error(ps,"unknown return policy keyword %s",tok->cp);
   
   node_delete(tok);
   ps->ignore_semicolon=1;
}
int main (void){

	LNode my_List;
	LNode temp;
	void *ptr;
	ptr	=NULL;
	arr_init(ptr);
	my_List=llist_new(ptr);

	temp=my_List;

	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	node_insert(my_List,888,21);

	temp=my_List;

	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	node_delete(my_List,21);
	temp=my_List;
	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}









	return 0;
}