Exemplo n.º 1
0
/**
 * @short AA tree insert
 *
 * Returns the root node of the subtree
 */
static onion_dict_node  *onion_dict_node_add(onion_dict *d, onion_dict_node *node, onion_dict_node *nnode){
	if (node==NULL){
		//ONION_DEBUG("Add here %p",nnode);
		return nnode;
	}
	signed int cmp=d->cmp(nnode->data.key, node->data.key);
	//ONION_DEBUG0("cmp %d, %X, %X %X",cmp, nnode->data.flags,nnode->data.flags&OD_REPLACE, OD_REPLACE);
	if ((cmp==0) && (nnode->data.flags&OD_REPLACE)){
		//ONION_DEBUG("Replace %s with %s", node->data.key, nnode->data.key);
		onion_dict_node_data_free(&node->data);
		memcpy(&node->data, &nnode->data, sizeof(onion_dict_node_data));
		onion_low_free(nnode);
		return node;
	}
	else if (cmp<0){
		node->left=onion_dict_node_add(d, node->left, nnode);
		//ONION_DEBUG("%p[%s]->left=%p[%s]",node, node->data.key, node->left, node->left->data.key);
	}
	else{ // >=
		node->right=onion_dict_node_add(d, node->right, nnode);
		//ONION_DEBUG("%p[%s]->right=%p[%s]",node, node->data.key, node->right, node->right->data.key);
	}

	node=skew(node);
	node=split(node);

	return node;
}
Exemplo n.º 2
0
/**
 * @memberof onion_dict_t
 * @short Adds a value in the tree.
 *
 * Flags are or from onion_dict_flags_e, for example OD_DUP_ALL.
 *
 * @see onion_dict_flags_e
 */
void onion_dict_add(onion_dict *dict, const char *key, const void *value, int flags){
	if (!key){
		ONION_ERROR("Error, trying to add an empty key to a dictionary. There is a underliying bug here! Not adding anything.");
		return;
	}
	dict->root=onion_dict_node_add(dict, dict->root, onion_dict_node_new(key, value, flags));
}
Exemplo n.º 3
0
/**
 * @memberof onion_dict_t
 * Adds a value in the tree.
 */
void onion_dict_add(onion_dict *dict, const char *key, const void *value, int flags){
	dict->root=onion_dict_node_add(dict, dict->root, onion_dict_node_new(key, value, flags));
}