<commit_before>/*
 * Copyright 2010      INRI<NAME>
 *
 * Use of this software is governed by the GNU LGPLv2.1 license
 *
 * Written by <NAME>, INRIA Saclay - Ile-de-France,
 * Parc Club Orsay Universite, ZAC des vignes, 4 rue <NAME>,
 * 91893 Orsay, France 
 */

#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)
#define xS(TYPE,NAME) struct TYPE ## _ ## NAME
#define S(TYPE,NAME) xS(TYPE,NAME)

struct UNION {
	int ref;
	isl_dim *dim;

	struct isl_hash_table	table;
};

__isl_give UNION *FN(UNION,cow)(__isl_take UNION *u);

isl_ctx *FN(UNION,get_ctx)(__isl_keep UNION *u)
{
	return u ? u->dim->ctx : NULL;
}

__isl_give isl_dim *FN(UNION,get_dim)(__isl_keep UNION *u)
{
	if (!u)
		return NULL;
	return isl_dim_copy(u->dim);
}

static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
{
	UNION *u;

	u = isl_calloc_type(ctx, UNION);
	if (!u)
		return NULL;

	u->ref = 1;
	u->dim = dim;
	if (isl_hash_table_init(dim->ctx, &u->table, size) < 0)
		goto error;

	return u;
error:
	isl_dim_free(dim);
	FN(UNION,free)(u);
	return NULL;
}

__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim)
{
	return FN(UNION,alloc)(dim, 16);
}

__isl_give UNION *FN(UNION,copy)(__isl_keep UNION *u)
{
	if (!u)
		return NULL;

	u->ref++;
	return u;
}

S(UNION,foreach_data)
{
	int (*fn)(__isl_take PART *part, void *user);
	void *user;
};

static int call_on_copy(void **entry, void *user)
{
	PART *part = *entry;
	S(UNION,foreach_data) *data = (S(UNION,foreach_data) *)user;

	return data->fn(FN(PART,copy)(part), data->user);
}

int FN(FN(UNION,foreach),PARTS)(__isl_keep UNION *u,
	int (*fn)(__isl_take PART *part, void *user), void *user)
{
	S(UNION,foreach_data) data = { fn, user };

	if (!u)
		return -1;

	return isl_hash_table_foreach(u->dim->ctx, &u->table,
				      &call_on_copy, &data);
}

static int has_dim(const void *entry, const void *val)
{
	PART *part = (PART *)entry;
	isl_dim *dim = (isl_dim *)val;

	return isl_dim_equal(part->dim, dim);
}

__isl_give UNION *FN(FN(UNION,add),PARTS)(__isl_take UNION *u,
	__isl_take PART *part)
{
	uint32_t hash;
	struct isl_hash_table_entry *entry;

	u = FN(UNION,cow)(u);

	if (!part || !u)
		goto error;

	isl_assert(u->dim->ctx, isl_dim_match(part->dim, isl_dim_param, u->dim,
					      isl_dim_param), goto error);
<commit_msg>isl_union_pw_qpolynomial_add_pw_qpolynomial: don't add empty parts<commit_after>/*
 * Copyright 2010      <NAME>
 *
 * Use of this software is governed by the GNU LGPLv2.1 license
 *
 * Written by <NAME>, <NAME> - Ile-de-France,
 * Parc Club Orsay Universite, ZAC des vignes, 4 rue <NAME>,
 * 91893 Orsay, France 
 */

#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)
#define xS(TYPE,NAME) struct TYPE ## _ ## NAME
#define S(TYPE,NAME) xS(TYPE,NAME)

struct UNION {
	int ref;
	isl_dim *dim;

	struct isl_hash_table	table;
};

__isl_give UNION *FN(UNION,cow)(__isl_take UNION *u);

isl_ctx *FN(UNION,get_ctx)(__isl_keep UNION *u)
{
	return u ? u->dim->ctx : NULL;
}

__isl_give isl_dim *FN(UNION,get_dim)(__isl_keep UNION *u)
{
	if (!u)
		return NULL;
	return isl_dim_copy(u->dim);
}

static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
{
	UNION *u;

	u = isl_calloc_type(ctx, UNION);
	if (!u)
		return NULL;

	u->ref = 1;
	u->dim = dim;
	if (isl_hash_table_init(dim->ctx, &u->table, size) < 0)
		goto error;

	return u;
error:
	isl_dim_free(dim);
	FN(UNION,free)(u);
	return NULL;
}

__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim)
{
	return FN(UNION,alloc)(dim, 16);
}

__isl_give UNION *FN(UNION,copy)(__isl_keep UNION *u)
{
	if (!u)
		return NULL;

	u->ref++;
	return u;
}

S(UNION,foreach_data)
{
	int (*fn)(__isl_take PART *part, void *user);
	void *user;
};

static int call_on_copy(void **entry, void *user)
{
	PART *part = *entry;
	S(UNION,foreach_data) *data = (S(UNION,foreach_data) *)user;

	return data->fn(FN(PART,copy)(part), data->user);
}

int FN(FN(UNION,foreach),PARTS)(__isl_keep UNION *u,
	int (*fn)(__isl_take PART *part, void *user), void *user)
{
	S(UNION,foreach_data) data = { fn, user };

	if (!u)
		return -1;

	return isl_hash_table_foreach(u->dim->ctx, &u->table,
				      &call_on_copy, &data);
}

static int has_dim(const void *entry, const void *val)
{
	PART *part = (PART *)entry;
	isl_dim *dim = (isl_dim *)val;

	return isl_dim_equal(part->dim, dim);
}

__isl_give UNION *FN(FN(UNION,add),PARTS)(__isl_take UNION *u,
	__isl_take PART *part)
{
	uint32_t hash;
	struct isl_hash_table_entry *entry;

	if (!part)
		goto error;

	if (FN(PART,is_zero)(part)) {
		FN(PART,free)(part);
		return u;
	}

	u = FN(UNION,cow)(u);

	if (!u)
		goto error;

	isl_assert(u->dim->ctx, isl_dim_match(part->dim, isl_dim_param, u->dim,
					      isl_dim_param), goto error);

{'fraction_non_alphanumeric': 0.1613983671760519, 'fraction_numerical': 0.007954783336822273, 'mean_word_length': 4.5429234338747095, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '461766', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2053, 'n_words': 477}