gallium/cso_hash: remove always constant variable nodeSize
[mesa.git] / src / gallium / auxiliary / cso_cache / cso_hash.c
index 4d3e261a741f24a96d295d881383923018becb3c..e3495d5165a67c293e00ace96b33d5ce854ed9b0 100644 (file)
@@ -73,19 +73,9 @@ static int countBits(int hint)
    return numBits;
 }
 
-struct cso_hash_data {
-   struct cso_node *fakeNext;
-   struct cso_node **buckets;
-   int size;
-   int nodeSize;
-   short userNumBits;
-   short numBits;
-   int numBuckets;
-};
-
 static void *cso_data_allocate_node(struct cso_hash_data *hash)
 {
-   return MALLOC(hash->nodeSize);
+   return MALLOC(sizeof(struct cso_node));
 }
 
 static void cso_free_node(struct cso_node *node)
@@ -189,21 +179,6 @@ static struct cso_node *cso_data_first_node(struct cso_hash_data *hash)
    return e;
 }
 
-static struct cso_node **cso_hash_find_node(struct cso_hash *hash, unsigned akey)
-{
-   struct cso_node **node;
-
-   if (hash->data.d->numBuckets) {
-      node = (struct cso_node **)(&hash->data.d->buckets[akey % hash->data.d->numBuckets]);
-      assert(*node == hash->data.e || (*node)->next);
-      while (*node != hash->data.e && (*node)->key != akey)
-         node = &(*node)->next;
-   } else {
-      node = (struct cso_node **)((const struct cso_node * const *)(&hash->data.e));
-   }
-   return node;
-}
-
 struct cso_hash_iter cso_hash_insert(struct cso_hash *hash,
                                        unsigned key, void *data)
 {
@@ -224,30 +199,22 @@ struct cso_hash_iter cso_hash_insert(struct cso_hash *hash,
    }
 }
 
-struct cso_hash * cso_hash_create(void)
+bool cso_hash_init(struct cso_hash *hash)
 {
-   struct cso_hash *hash = MALLOC_STRUCT(cso_hash);
-   if (!hash)
-      return NULL;
-
    hash->data.d = MALLOC_STRUCT(cso_hash_data);
-   if (!hash->data.d) {
-      FREE(hash);
-      return NULL;
-   }
+   if (!hash->data.d)
+      return false;
 
    hash->data.d->fakeNext = 0;
    hash->data.d->buckets = 0;
    hash->data.d->size = 0;
-   hash->data.d->nodeSize = sizeof(struct cso_node);
    hash->data.d->userNumBits = (short)MinNumBits;
    hash->data.d->numBits = 0;
    hash->data.d->numBuckets = 0;
-
-   return hash;
+   return true;
 }
 
-void cso_hash_delete(struct cso_hash *hash)
+void cso_hash_deinit(struct cso_hash *hash)
 {
    struct cso_node *e_for_x = (struct cso_node *)(hash->data.d);
    struct cso_node **bucket = (struct cso_node **)(hash->data.d->buckets);
@@ -262,15 +229,7 @@ void cso_hash_delete(struct cso_hash *hash)
    }
    FREE(hash->data.d->buckets);
    FREE(hash->data.d);
-   FREE(hash);
-}
-
-struct cso_hash_iter cso_hash_find(struct cso_hash *hash,
-                                     unsigned key)
-{
-   struct cso_node **nextNode = cso_hash_find_node(hash, key);
-   struct cso_hash_iter iter = {hash, *nextNode};
-   return iter;
+   hash->data.d = NULL;
 }
 
 unsigned cso_hash_iter_key(struct cso_hash_iter iter)
@@ -280,7 +239,7 @@ unsigned cso_hash_iter_key(struct cso_hash_iter iter)
    return iter.node->key;
 }
 
-static struct cso_node *cso_hash_data_next(struct cso_node *node)
+struct cso_node *cso_hash_data_next(struct cso_node *node)
 {
    union {
       struct cso_node *next;
@@ -348,12 +307,6 @@ static struct cso_node *cso_hash_data_prev(struct cso_node *node)
    return a.e;
 }
 
-struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter)
-{
-   struct cso_hash_iter next = {iter.hash, cso_hash_data_next(iter.node)};
-   return next;
-}
-
 void * cso_hash_take(struct cso_hash *hash,
                       unsigned akey)
 {