uint32_t isl_gmp_hash(mpz_t v, uint32_t hash);
#define isl_int_hash(v,h) isl_gmp_hash(v,h)
+#define isl_hash_init(h) (h = 2166136261u)
+#define isl_hash_byte(h,b) do { \
+ h *= 16777619; \
+ h ^= b; \
+ } while(0)
+#define isl_hash_hash(h,h2) \
+ do { \
+ isl_hash_byte(h, (h2) & 0xFF); \
+ isl_hash_byte(h, ((h2) >> 8) & 0xFF); \
+ isl_hash_byte(h, ((h2) >> 16) & 0xFF); \
+ isl_hash_byte(h, ((h2) >> 24) & 0xFF); \
+ } while(0)
+#define isl_hash_bits(h,bits) \
+ ((bits) == 32) ? (h) : \
+ ((bits) >= 16) ? \
+ ((h) >> (bits)) ^ ((h) & (((uint32_t)1 << (bits)) - 1)) : \
+ (((h) >> (bits)) ^ (h)) & (((uint32_t)1 << (bits)) - 1)
+
#if defined(__cplusplus)
}
#endif
{
int h;
unsigned total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div;
- uint32_t hash = isl_seq_hash(bmap->ineq[k]+1, total, bits);
+ uint32_t hash = isl_seq_get_hash_bits(bmap->ineq[k]+1, total, bits);
for (h = hash; index[h]; h = (h+1) % size)
if (&bmap->ineq[k] != index[h] &&
isl_seq_eq(bmap->ineq[k]+1, index[h][0]+1, total))
if (!index)
return bmap;
- index[isl_seq_hash(bmap->ineq[0]+1, total, bits)] = &bmap->ineq[0];
+ index[isl_seq_get_hash_bits(bmap->ineq[0]+1, total, bits)] = &bmap->ineq[0];
for (k = 1; k < bmap->n_ineq; ++k) {
h = hash_index(index, size, bits, bmap, k);
if (!index[h]) {
goto out;
isl_seq_clr(eq.data, 1+total);
- index[isl_seq_hash(bmap->div[k], 2+total, bits)] = k + 1;
+ index[isl_seq_get_hash_bits(bmap->div[k], 2+total, bits)] = k + 1;
for (--k; k >= 0; --k) {
uint32_t hash;
if (isl_int_is_zero(bmap->div[k][0]))
continue;
- hash = isl_seq_hash(bmap->div[k], 2+total, bits);
+ hash = isl_seq_get_hash_bits(bmap->div[k], 2+total, bits);
for (h = hash; index[h]; h = (h+1) % size)
if (isl_seq_eq(bmap->div[k],
bmap->div[index[h]-1], 2+total))
return bmap;
}
+struct isl_basic_set *isl_basic_set_normalize(struct isl_basic_set *bset)
+{
+ return (struct isl_basic_set *)isl_basic_map_normalize(
+ (struct isl_basic_map *)bset);
+}
+
static int isl_basic_map_fast_cmp(const struct isl_basic_map *bmap1,
const struct isl_basic_map *bmap2)
{
isl_basic_set_list_free(list);
return NULL;
}
+
+uint32_t isl_basic_set_get_hash(struct isl_basic_set *bset)
+{
+ int i;
+ uint32_t hash;
+ unsigned total;
+
+ if (!bset)
+ return 0;
+ bset = isl_basic_set_copy(bset);
+ bset = isl_basic_set_normalize(bset);
+ if (!bset)
+ return 0;
+ total = bset->nparam + bset->dim + bset->n_div;
+ isl_hash_byte(hash, bset->n_eq & 0xFF);
+ for (i = 0; i < bset->n_eq; ++i) {
+ uint32_t c_hash;
+ c_hash = isl_seq_get_hash(bset->eq[i], 1 + total);
+ isl_hash_hash(hash, c_hash);
+ }
+ isl_hash_byte(hash, bset->n_ineq & 0xFF);
+ for (i = 0; i < bset->n_ineq; ++i) {
+ uint32_t c_hash;
+ c_hash = isl_seq_get_hash(bset->ineq[i], 1 + total);
+ isl_hash_hash(hash, c_hash);
+ }
+ isl_hash_byte(hash, bset->n_div & 0xFF);
+ for (i = 0; i < bset->n_div; ++i) {
+ uint32_t c_hash;
+ if (isl_int_is_zero(bset->div[i][0]))
+ continue;
+ isl_hash_byte(hash, i & 0xFF);
+ c_hash = isl_seq_get_hash(bset->div[i], 1 + 1 + total);
+ isl_hash_hash(hash, c_hash);
+ }
+ isl_basic_set_free(bset);
+ return hash;
+}
+
+uint32_t isl_set_get_hash(struct isl_set *set)
+{
+ int i;
+ uint32_t hash;
+
+ if (!set)
+ return 0;
+ set = isl_set_copy(set);
+ set = isl_set_normalize(set);
+ if (!set)
+ return 0;
+
+ isl_hash_init(hash);
+ for (i = 0; i < set->n; ++i) {
+ uint32_t bset_hash;
+ bset_hash = isl_basic_set_get_hash(set->p[i]);
+ isl_hash_hash(hash, bset_hash);
+ }
+
+ isl_set_free(set);
+
+ return hash;
+}
isl_int_addmul(*prod, p1[i], p2[i]);
}
-uint32_t isl_seq_hash(isl_int *p, unsigned len, unsigned bits)
+uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash)
{
int i;
- uint32_t hash = 2166136261u;
-
for (i = 0; i < len; ++i) {
if (isl_int_is_zero(p[i]))
continue;
hash ^= (i & 0xFF);
hash = isl_int_hash(p[i], hash);
}
- if (bits == 32)
- return hash;
- if (bits >= 16)
- return (hash >> bits) ^ (hash & (((uint32_t)1 << bits) - 1));
- return ((hash >> bits) ^ hash) & (((uint32_t)1 << bits) - 1);
+ return hash;
+}
+
+uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
+{
+ uint32_t hash;
+ isl_hash_init(hash);
+
+ return isl_seq_hash(p, len, hash);
+}
+
+uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits)
+{
+ uint32_t hash;
+
+ hash = isl_seq_get_hash(p, len);
+ return isl_hash_bits(hash, bits);
}