Beispiel #1
0
void
sord_free(SordModel* sord)
{
	if (!sord)
		return;

	// Free nodes
	SordQuad tup;
	SordIter* i = sord_begin(sord);
	for (; !sord_iter_end(i); sord_iter_next(i)) {
		sord_iter_get(i, tup);
		for (int t = 0; t < TUP_LEN; ++t) {
			sord_drop_quad_ref(sord, tup[t], (SordQuadIndex)t);
		}
	}
	sord_iter_free(i);

	// Free quads
	ZixBTreeIter* t = zix_btree_begin(sord->indices[DEFAULT_ORDER]);
	for (; !zix_btree_iter_is_end(t); zix_btree_iter_increment(t)) {
		free(zix_btree_get(t));
	}
	zix_btree_iter_free(t);

	// Free indices
	for (unsigned o = 0; o < NUM_ORDERS; ++o)
		if (sord->indices[o])
			zix_btree_free(sord->indices[o]);

	free(sord);
}
Beispiel #2
0
void
sord_remove(SordModel* sord, const SordQuad tup)
{
	SORD_WRITE_LOG("Remove " TUP_FMT "\n", TUP_FMT_ARGS(tup));
	if (sord->n_iters > 0) {
		error(sord->world, SERD_ERR_BAD_ARG, "remove with iterator\n");
	}

	SordNode* quad = NULL;
	for (unsigned i = 0; i < NUM_ORDERS; ++i) {
		if (sord->indices[i]) {
			if (zix_btree_remove(sord->indices[i], tup, (void**)&quad, NULL)) {
				assert(i == 0);  // Assuming index coherency
				return;  // Quad not found, do nothing
			}
		}
	}

	free(quad);

	for (int i = 0; i < TUP_LEN; ++i)
		sord_drop_quad_ref(sord, tup[i], (SordQuadIndex)i);

	--sord->n_quads;
}
Beispiel #3
0
SerdStatus
sord_erase(SordModel* sord, SordIter* iter)
{
	if (sord->n_iters > 1) {
		error(sord->world, SERD_ERR_BAD_ARG, "erased with many iterators\n");
	}

	SordQuad tup;
	sord_iter_get(iter, tup);

	SORD_WRITE_LOG("Remove " TUP_FMT "\n", TUP_FMT_ARGS(tup));

	SordNode* quad = NULL;
	for (unsigned i = 0; i < NUM_ORDERS; ++i) {
		if (sord->indices[i]) {
			if (zix_btree_remove(sord->indices[i], tup, (void**)&quad,
			                     i == iter->order ? &iter->cur : NULL)) {
				return (i == 0) ? SERD_ERR_NOT_FOUND : SERD_ERR_INTERNAL;
			}
		}
	}
	iter->end = zix_btree_iter_is_end(iter->cur);

	free(quad);

	for (int i = 0; i < TUP_LEN; ++i)
		sord_drop_quad_ref(sord, tup[i], (SordQuadIndex)i);

	--sord->n_quads;
	return SERD_SUCCESS;
}
Beispiel #4
0
void
sord_remove(SordModel* sord, const SordQuad tup)
{
	SORD_WRITE_LOG("Remove " TUP_FMT "\n", TUP_FMT_ARGS(tup));

	SordNode** quad = NULL;
	for (unsigned i = 0; i < NUM_ORDERS; ++i) {
		if (sord->indices[i]) {
			ZixTreeIter* const cur = index_search(sord->indices[i], tup);
			if (!zix_tree_iter_is_end(cur)) {
				if (!quad) {
					quad = (SordNode**)zix_tree_get(cur);
				}
				zix_tree_remove(sord->indices[i], cur);
			} else {
				assert(i == 0);  // Assuming index coherency
				return;  // Quad not found, do nothing
			}
		}
	}

	free(quad);

	for (int i = 0; i < TUP_LEN; ++i)
		sord_drop_quad_ref(sord, tup[i], (SordQuadIndex)i);

	--sord->n_quads;
}