示例#1
0
void node_destroy(struct ast_node *node) {
    if (node == NULL) {
        return;
    }

    switch (node->type) {
        case NODE_STR:
            free(node->sValue);
            break;

        default:
            break;
    }

    if (node_uses_body(node)) {
        for (unsigned int i = 0; i < AST_NODE_BODY_MAX_SIZE; i++) {
            node_destroy(node->body[i]);
        }
    }

    if (node->next != NULL) {
        node_destroy(node->next);
    }

    /* this node */
    free(node);
}
示例#2
0
文件: aatree.c 项目: shonma29/eotan
static node_t *node_remove(tree_t *tree, node_t *p, const int key)
{
	if (!IS_NIL(p)) {
		int d = tree->compare(key, p->key);

		if (d == 0) {
			if (IS_NIL(p->left)) {
				node_t *q = p->right;

				node_destroy(tree, p);
				return q;
			} else if (IS_NIL(p->right)) {
				node_t *q = p->left;

				node_destroy(tree, p);
				return q;
			} else {
				node_t *q = p;
				node_t *r = node_remove_swap(tree, p->right,
						&q);

				p = q;
				p->right = r;
			}
		} else if (d < 0)
			p->left = node_remove(tree, p->left, key);
		else
			p->right = node_remove(tree, p->right, key);

		p = node_rebalance(p);
	}

	return p;
}
示例#3
0
void expr_ifthen_destruct(SyntaxNode* expr)
{
	ifthen_t* ifthen = (ifthen_t*) expr;

	node_destroy(PTR_SUPER(ifthen->cond));
	node_destroy(PTR_SUPER(ifthen->then));
	node_destroy(PTR_SUPER(ifthen->els));
}
示例#4
0
void node_destroy(node_t *node)
{
    if (node != NULL) {
        node_destroy(node->l);
        node_destroy(node->r);
        node->data = NULL;
        free(node);
    }
}
示例#5
0
void node_destroy(struct enode *n) {
  if (n && n->left) {
    node_destroy(n->left);
  }
  if (n && n->right) {
    node_destroy(n->right);
  }
  free(n);
}
示例#6
0
static void node_destroy (Tree *tree, TreeNode *node)
{
	if (node->link[0] != tree->nil) {
		node_destroy (tree, node->link[0]);
	}
	if (node->link[1] != tree->nil) {
		node_destroy (tree, node->link[1]);
	}
	memory_destroy (node);
}
示例#7
0
/* 节点递归销毁 */
static void node_destroy(h_rbtree_st *tree, rbtree_node_st *node)
{
    if (node->left)
        node_destroy(tree, node->left);
    if (node->right)
        node_destroy(tree, node->right);

    if ((void *)tree->data_free)
        tree->data_free(node->cs.data);

    h_free(node);
}
示例#8
0
void pf_list_destroy(PF_List *lst) {
    int i = 0;
    int size = lst->size;
    for(i=0; i<size; i++) {
        Node *curr = pf_list_pop(lst, 0);
        node_destroy(curr);
    }
    if(lst->head != NULL) {
        node_destroy(lst->head);
    }
    if(lst->tail != NULL) {
        node_destroy(lst->tail);
    }
}
示例#9
0
void regression_free_inputs(
    int in1_type,
    struct node *in1,
    int in2_type,
    struct node *in2
)
{
    if (in1_type == EVAL) {
        node_destroy(in1);
    }
    if (in2_type == EVAL) {
        node_destroy(in2);
    }
}
示例#10
0
void pf_list_move_list(PF_List *lst1, PF_List *lst2) {
    Node *curr = lst1->tail->next;
    while(curr != lst1->head) {
        pf_list_remove(lst1, curr);
        //printf("current list\n");
        //pf_list_print(lst1);
        
        //clone node
        //move next pointer
        //add clone to lst2
        //destroy node in memory
        Node* copy = node_clone(curr);
        node_destroy(curr);
        curr = NULL;
        curr = copy->next;
        //check to see if there is a duplicate
        //if there is a duplicate then choose the node with the lowest fscore
        Node *existing = pf_list_remove(lst2, copy);
        if(existing != NULL) {
            if(copy->F < existing->F) {
                pf_list_add(lst2, copy);
            } else {
                pf_list_add(lst2, existing);
            }
        } else {
            pf_list_add(lst2, copy);
        }
        
        //printf("open list\n");
        //pf_list_print(lst2);

        //TODO reference to tail points to lst2 after added 
    }
}
示例#11
0
文件: node.c 项目: dreamer-dead/myxml
void node_destroy( mxml_node * n )
{
	if ( n != NULL )
	{
		mxml_node * temp = NULL;
		mxml_node * child = n->first_child;

		while ( child )
		{
			temp = child->next;
			node_destroy( child );
			child = temp;
		}

		if ( n->extend != NULL && n->type != type_node )
		{
			switch( n->type )
			{
			case type_element		: destroy_element	 ( (mxml_element *)n->extend ); break;
			case type_attribute		: destroy_attribute	 ( (mxml_attribute *)n->extend ); break;
			case type_declaration	: destroy_declaration( (mxml_declaration *)n->extend ); break;
			case type_document		: destroy_document	 ( (mxml_document *)n->extend ); break;
			}
		}
		free_str( &n->value );
		free( n );
	}
}
示例#12
0
文件: node.c 项目: Mephostopilis/lua
node_t* node_create(node_t* parent, void* data) {
	int error = 0;

	node_t* node = (node_t*) malloc(sizeof(node_t));
	if(node == NULL) {
		return NULL;
	}
	memset(node, '\0', sizeof(node_t));

	node->data = data;
	node->depth = 0;
	node->next = NULL;
	node->prev = NULL;
	node->count = 0;
	node->isLeaf = TRUE;
	node->isRoot = TRUE;
	node->parent = NULL;
	node->children = node_list_create();

	// Pass NULL to create a root node
	if(parent != NULL) {
		// This is a child node so attach it to it's parent
		error = node_attach(parent, node);
		if(error < 0) {
			// Unable to attach nodes
			printf("ERROR: %d \"Unable to attach nodes\"\n", error);
			node_destroy(node);
			return NULL;
		}
	}

	return node;
}
示例#13
0
文件: node.c 项目: marcielmj/esd-list
void node_destroy_cascaded(Node* n) {
    if (n->next != NULL) {
        node_destroy_cascaded(n->next);
    }

    node_destroy(n);
}
int main (int argc, char* argv[]){
    int nodecount, *num_in_links, *num_out_links;

    int err = get_node_stat(&nodecount, &num_in_links, &num_out_links);
    if (err != 0) {
        return err;
    }

    node_t *nodehead;
    err = node_init(&nodehead, num_in_links, num_out_links, 0, nodecount);
    if (err != 0) {
        return err;
    }

    double start, end;

    GET_TIME(start);
    double damp_const = (1.0 - DAMPING_FACTOR) / nodecount;
    double *r = init_result_vector(nodecount, false);
    double *r_pre = init_result_vector(nodecount, true);
    page_rank(r, r_pre, num_out_links, num_in_links, nodecount, nodehead, damp_const);
    free(r_pre);
    GET_TIME(end);

    double delay = end - start;
    Lab4_saveoutput(r, nodecount, delay);

    node_destroy(nodehead, nodecount);
    free(num_in_links);
    free(num_out_links);
    free(r);
}
示例#15
0
void free_chromosome(struct node **chromosome, int length)
{
    int i;
    for (i = 0; i < length; i++) {
        node_destroy(chromosome[i]);
    }
}
示例#16
0
void test_array()
{
    START_CODE(node)
	IF
	    IN
                RAW_PARAM(3)
		ARRAY_CONSTANT(array_create(3, 1,2,3));
	    END;
	THEN
	    CATEGORY_CONSTANT(1)
	ELSE
	    CATEGORY_CONSTANT(2)
	END;
    END_CODE;

    node_print(node);

    node = test_serialization(node);

    environment_t env = test_environment();

    constant_t v = node_eval(node, &env);
    assert(v.c == 2);
    assert(v.type == CONSTANT_CATEGORY);

    env.row->inputs[3].category = 3;
    v = node_eval(node, &env);
    assert(v.c == 1);
    assert(v.type == CONSTANT_CATEGORY);

    row_destroy(env.row);
    node_destroy(node);
}
示例#17
0
/* 销毁 */
void h_rbtree_destroy(h_rbtree_st *tree)
{
    if (tree->root)
        node_destroy(tree, tree->root);

    h_free(tree);
}
示例#18
0
//
// AUTOTEST: ann node
//
void xautotest_ann_node()
{
    float w[4] = {1,2,3,4}; // weights vector
    float x[3] = {5,1,3};   // input vector
    float y[1];             // output vector

    // create node
    node q = node_create(w,     // weights
                         x,     // input
                         y,     // output
                         3,     // num_inputs
                         0,     // activation function ID
                         1.0f   // activation function gain
                        );

    // evaluate node
    node_evaluate(q);

    if (liquid_autotest_verbose) {
        node_print(q);
        printf("y = %12.8f\n", y[0]);
    }

    // contend equality of output
    CONTEND_EQUALITY(y[0], 20.0f);

    // destroy node
    node_destroy(q);
}
示例#19
0
void osm_node_delete(IN OUT osm_node_t ** p_node)
{
	CL_ASSERT(p_node && *p_node);
	node_destroy(*p_node);
	free(*p_node);
	*p_node = NULL;
}
示例#20
0
node *
list_remove_node(list *l, node *n)
{
	void *data = n->data;
	node *p = l->h;

	if (p != n)
		while (p && p->next != n)
			p = p->next;
	if (p == n) {
		l->h = n->next;
		p = NULL;
	} else if ( p != NULL)  {
		p->next = n->next;
	}
	if (n == l->t)
		l->t = p;
	node_destroy(l, n);
	l->cnt--;
	MT_lock_set(&l->ht_lock, "list_remove_node");
	if (l->ht && data)
		hash_delete(l->ht, data);
	MT_lock_unset(&l->ht_lock, "list_remove_node");
	return p;
}
示例#21
0
static void cleanup(void)
{
    ir_destroy();
    node_destroy(root);
    stack_destroy(&stack);
    yylex_destroy();
}
示例#22
0
void S_queue_destroy(pTHX_ message_queue* queue) {
	MUTEX_LOCK(&queue->mutex);
	node_destroy(&queue->front);
	COND_DESTROY(&queue->condvar);
	MUTEX_UNLOCK(&queue->mutex);
	MUTEX_DESTROY(&queue->mutex);
}
示例#23
0
void expr_lambda_destruct(SyntaxNode* expr)
{
	lambda_t* lambda = (lambda_t*) expr;

	node_destroy(lambda->body);
	param_list_destroy(lambda->params);
}
示例#24
0
/**
 * Recursively deallocates a node and all the nodes in its merged array.
 */
void node_recursive_destroy(node *n) {
    int i;
    for (i = 0; n->merged && i < n->merged->nnodes; i++) {
	node_recursive_destroy(n->merged->node[i]);
    }
    node_destroy(n);
}
示例#25
0
static void node_destroy(Node n) {
	if(n == NULL) {
		return;
	} else {
		node_destroy(n->next);
		free(n);
	}
}
示例#26
0
文件: list.c 项目: sfrias/orvibo
void
node_destroy_all(struct node *node, const NODE_DATA_DESTROY destroy) {
	struct node *temp = NULL;
	while (node != NULL) {
		temp = node->next;
		node_destroy(node, destroy);
		node = temp;
	}
}
示例#27
0
static void tree_destroy(RBTree *tree, RBNode *x)
{
    if (x != tree->nil)
    {
        tree_destroy(tree, x->left);
        tree_destroy(tree, x->right);
        node_destroy(tree, x);
    }
}
示例#28
0
void function_node_free(FUNCTION_NODE* fnode)
{
	assert( fnode != NULL );
	fnode->node.refcount--;
	if( fnode->node.refcount <= 0 )
	{
		node_destroy((NODE*)fnode);
		GC_FREE(fnode);
	}
}
示例#29
0
static void table_clear(HashtableNode **table, int real_capacity, void(*free_value)(void *))
{
	int i;
	HashtableNode *node;
	for(i = 0; i < real_capacity; i++) {
		node = table[i];
		node_destroy(node, free_value);
		table[i] = NULL;
	}
}
示例#30
0
node_t*test_serialization(node_t*node)
{
    writer_t *w = growingmemwriter_new();
    node_write(node, w, 0);
    node_destroy(node);
    reader_t*r = growingmemwriter_getreader(w);
    w->finish(w);
    node = node_read(r);
    r->dealloc(r);
    return node;
}