예제 #1
0
파일: skiplist.c 프로젝트: SavOK/libdict
skiplist*
skiplist_clone(skiplist* list, dict_key_datum_clone_func clone_func)
{
    ASSERT(list != NULL);

    skiplist* clone = skiplist_new(list->cmp_func, list->del_func,
				   list->max_link);
    if (clone) {
	skip_node* node = list->head->link[0];
	while (node) {
	    bool inserted = false;
	    void** datum = skiplist_insert(clone, node->key, &inserted);
	    if (!datum || !inserted) {
		skiplist_free(clone);
		return NULL;
	    }
	    *datum = node->datum;
	    node = node->link[0];
	}
	if (clone_func) {
	    node = clone->head->link[0];
	    while (node) {
		clone_func(&node->key, &node->datum);
		node = node->link[0];
	    }
	}
    }
    return clone;
}
예제 #2
0
int CZhList::Clone(CZhList* dst,int *(*clone_func) (void *, void*))
{
	void* data;
	void* data2;
	int pos = 0;
	while (!IsListEof(pos))
	{
		data = GetAt(pos);
		if (clone_func(data, &data2) != 0)
			return -1;
		dst->Add(data2, -1);
		pos++;
	}
	return 0;
}
예제 #3
0
static tree_node_base*
node_clone(tree_node_base* node, tree_node_base* parent, size_t node_size,
	   dict_key_datum_clone_func clone_func)
{
    if (!node)
	return NULL;
    tree_node_base* clone = MALLOC(node_size);
    if (!clone)
	return NULL;
    memcpy(clone, node, node_size);
    if (clone_func)
	clone_func(&clone->key, &clone->datum);
    clone->parent = parent;
    clone->llink = node_clone(node->llink, clone, node_size, clone_func);
    clone->rlink = node_clone(node->rlink, clone, node_size, clone_func);
    return clone;
}
예제 #4
0
파일: osip_list.c 프로젝트: chcoffice/Bull
int osip_list_clone(const osip_list_t * src, osip_list_t * dst,
					int (*clone_func) (void *, void **))
{
	void *data;
	void *data2;
	int i;
	osip_list_iterator_t iterator;

	for (data = osip_list_get_first((osip_list_t *) src, &iterator);
		 osip_list_iterator_has_elem(iterator);
		 data = osip_list_get_next(&iterator)) {
		i = clone_func(data, &data2);
		if (i != 0)
			return i;
		osip_list_add(dst, data2, -1);
	}
	return OSIP_SUCCESS;
}
예제 #5
0
hashtable2*
hashtable2_clone(hashtable2* table, dict_key_datum_clone_func clone_func)
{
    ASSERT(table != NULL);

    hashtable2* clone = hashtable2_new(table->cmp_func, table->hash_func,
				       table->del_func, table->size);
    if (!clone) {
	return NULL;
    }
    memcpy(clone->table, table->table, sizeof(hash_node) * table->size);
    clone->count = table->count;
    if (clone_func) {
	for (hash_node *node = clone->table, *end = clone->table + table->size; node != end; ++node) {
	    if (node->hash) {
		clone_func(&node->key, &node->datum);
	    }
	}
    }
    return clone;
}
예제 #6
0
파일: hashtable.c 프로젝트: weixu8/libdict
hashtable*
hashtable_clone(hashtable* table, dict_key_datum_clone_func clone_func)
{
    ASSERT(table);

    hashtable* clone = hashtable_new(table->cmp_func, table->hash_func,
				     table->del_func, table->size);
    if (clone) {
	clone->count = table->count;
	for (unsigned slot = 0; slot < table->size; ++slot) {
	    hash_node* prev = NULL;
	    hash_node* node = table->table[slot];
	    for (; node; node = node->next) {
		hash_node* add = MALLOC(sizeof(*add));
		if (!add) {
		    hashtable_free(clone);
		    return NULL;
		}
		add->key = node->key;
		add->datum = node->datum;
		if (clone_func)
		    clone_func(&add->key, &add->datum);
		add->next = NULL;
		add->prev = prev;
		if (prev)
		    prev->next = add;
		else
		    clone->table[slot] = add;
		add->hash = node->hash;

		prev = add;
	    }
	}
    }
    return clone;
}