isl_convex_hull.c: remove unused set_project_out
[platform/upstream/isl.git] / isl_hash.c
index 38c9e25..365082c 100644 (file)
@@ -8,8 +8,8 @@
  */
 
 #include <stdlib.h>
-#include "isl_hash.h"
-#include "isl_ctx.h"
+#include <isl/hash.h>
+#include <isl/ctx.h>
 
 uint32_t isl_hash_string(uint32_t hash, const char *s)
 {
@@ -18,6 +18,15 @@ uint32_t isl_hash_string(uint32_t hash, const char *s)
        return hash;
 }
 
+uint32_t isl_hash_mem(uint32_t hash, const void *p, size_t len)
+{
+       int i;
+       const char *s = p;
+       for (i = 0; i < len; ++i)
+               isl_hash_byte(hash, s[i]);
+       return hash;
+}
+
 static unsigned int round_up(unsigned int v)
 {
        int old_v = v;
@@ -42,7 +51,7 @@ int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
        table->bits = ffs(round_up(4 * (min_size + 1) / 3 - 1)) - 1;
        table->n = 0;
 
-       size = 2 << table->bits;
+       size = 1 << table->bits;
        table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
                                          size);
        if (!table->entries)
@@ -59,7 +68,7 @@ static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table,
        uint32_t h;
 
        entries = table->entries;
-       old_size = 2 << table->bits;
+       old_size = 1 << table->bits;
        size = 2 * old_size;
        table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
                                          size);
@@ -131,7 +140,7 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
        uint32_t h, key_bits;
 
        key_bits = isl_hash_bits(key_hash, table->bits);
-       size = 2 << table->bits;
+       size = 1 << table->bits;
        for (h = key_bits; table->entries[h].data; h = (h+1) % size)
                if (table->entries[h].hash == key_hash &&
                    eq(table->entries[h].data, val))
@@ -152,6 +161,22 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
        return &table->entries[h];
 }
 
+int isl_hash_table_foreach(struct isl_ctx *ctx,
+                               struct isl_hash_table *table,
+                               int (*fn)(void **entry, void *user), void *user)
+{
+       size_t size;
+       uint32_t h;
+
+       size = 1 << table->bits;
+       for (h = 0; h < size; ++ h)
+               if (table->entries[h].data &&
+                   fn(&table->entries[h].data, user) < 0)
+                       return -1;
+       
+       return 0;
+}
+
 void isl_hash_table_remove(struct isl_ctx *ctx,
                                struct isl_hash_table *table,
                                struct isl_hash_table_entry *entry)
@@ -162,7 +187,7 @@ void isl_hash_table_remove(struct isl_ctx *ctx,
        if (!table || !entry)
                return;
 
-       size = 2 << table->bits;
+       size = 1 << table->bits;
        h = entry - table->entries;
        isl_assert(ctx, h >= 0 && h < size, return);