mesa/st: avoid u_vbuf for GLES
[mesa.git] / src / gallium / auxiliary / cso_cache / cso_hash.h
index b86e11c5fd50b6d1ec6be6ffe086eb0ac12d5896..e984f117c95c437afd48cbcaf22693aea4b4ac80 100644 (file)
@@ -53,15 +53,8 @@ extern "C" {
 
 struct cso_node {
    struct cso_node *next;
-   unsigned key;
    void *value;
-};
-
-struct cso_hash {
-   union {
-      struct cso_hash_data *d;
-      struct cso_node      *e;
-   } data;
+   unsigned key;
 };
 
 struct cso_hash_iter {
@@ -69,21 +62,21 @@ struct cso_hash_iter {
    struct cso_node  *node;
 };
 
-struct cso_hash_data {
+struct cso_hash {
    struct cso_node *fakeNext;
    struct cso_node **buckets;
+   struct cso_node *end;
    int size;
-   int nodeSize;
    short userNumBits;
    short numBits;
    int numBuckets;
 };
 
-bool cso_hash_init(struct cso_hash *hash);
+void cso_hash_init(struct cso_hash *hash);
 void cso_hash_deinit(struct cso_hash *hash);
 
 
-int              cso_hash_size(struct cso_hash *hash);
+int cso_hash_size(struct cso_hash *hash);
 
 
 /**
@@ -103,7 +96,7 @@ struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, unsigned key,
  */
 struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter iter);
 
-void  *cso_hash_take(struct cso_hash *hash, unsigned key);
+void *cso_hash_take(struct cso_hash *hash, unsigned key);
 
 
 
@@ -112,10 +105,10 @@ struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash);
 /**
  * Returns true if a value with the given key exists in the hash
  */
-boolean   cso_hash_contains(struct cso_hash *hash, unsigned key);
+bool cso_hash_contains(struct cso_hash *hash, unsigned key);
 
 
-unsigned  cso_hash_iter_key(struct cso_hash_iter iter);
+unsigned cso_hash_iter_key(struct cso_hash_iter iter);
 
 
 struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter);
@@ -126,26 +119,24 @@ struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter);
  * comparison to see which entry in the list is a direct copy of our template
  * and returns that entry.
  */
-void *cso_hash_find_data_from_template( struct cso_hash *hash,
-                                       unsigned hash_key,
-                                       void *templ,
-                                       int size );
+void *cso_hash_find_data_from_template(struct cso_hash *hash,
+                                      unsigned hash_key,
+                                      void *templ,
+                                      int size);
 
 struct cso_node *cso_hash_data_next(struct cso_node *node);
 
-static inline int
+static inline bool
 cso_hash_iter_is_null(struct cso_hash_iter iter)
 {
-   if (!iter.node || iter.node == iter.hash->data.e)
-      return 1;
-   return 0;
+   return !iter.node || iter.node == iter.hash->end;
 }
 
 static inline void *
 cso_hash_iter_data(struct cso_hash_iter iter)
 {
-   if (!iter.node || iter.hash->data.e == iter.node)
-      return 0;
+   if (!iter.node || iter.hash->end == iter.node)
+      return NULL;
    return iter.node->value;
 }
 
@@ -154,13 +145,13 @@ 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)
+   if (hash->numBuckets) {
+      node = &hash->buckets[akey % hash->numBuckets];
+      assert(*node == hash->end || (*node)->next);
+      while (*node != hash->end && (*node)->key != akey)
          node = &(*node)->next;
    } else {
-      node = (struct cso_node **)((const struct cso_node * const *)(&hash->data.e));
+      node = &hash->end;
    }
    return node;
 }