start search at 1 in HashFindFreeKeyBlock()
[mesa.git] / src / mesa / main / hash.c
index ce5fdee93163a694ee4cedb284c7ab83896b1e02..20f81962bf070908857ee7f9789493e44fbfa7ad 100644 (file)
@@ -1,8 +1,8 @@
-/* $Id: hash.c,v 1.2 1999/10/08 09:27:10 keithw Exp $ */
+/* $Id: hash.c,v 1.5 2000/01/04 08:14:36 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.1
+ * Version:  3.3
  * 
  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  * 
  */
 
 
-
-
-
 #ifdef PC_HEADER
 #include "all.h"
 #else
-#ifndef XFree86Server
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#else
-#include "GL/xf86glx.h"
-#endif
+#include "glheader.h"
 #include "hash.h"
+#include "mem.h"
 #endif
 
 
 /*
- * Generic hash table.  Only dependency is the GLuint datatype.
+ * Generic hash table.
  *
  * This is used to implement display list and texture object lookup.
  * NOTE: key=0 is illegal.
@@ -70,7 +62,7 @@ struct HashTable {
  */
 struct HashTable *NewHashTable(void)
 {
-   return (struct HashTable *) calloc(sizeof (struct HashTable), 1);
+   return CALLOC_STRUCT(HashTable);
 }
 
 
@@ -86,11 +78,11 @@ void DeleteHashTable(struct HashTable *table)
       struct HashEntry *entry = table->Table[i];
       while (entry) {
         struct HashEntry *next = entry->Next;
-        free(entry);
+        FREE(entry);
         entry = next;
       }
    }
-   free(table);
+   FREE(table);
 }
 
 
@@ -153,7 +145,7 @@ void HashInsert(struct HashTable *table, GLuint key, void *data)
    }
 
    /* alloc and insert new table entry */
-   entry = (struct HashEntry *) calloc(sizeof(struct HashEntry), 1);
+   entry = MALLOC_STRUCT(HashEntry);
    entry->Key = key;
    entry->Data = data;
    entry->Next = table->Table[pos];
@@ -187,7 +179,7 @@ void HashRemove(struct HashTable *table, GLuint key)
          else {
             table->Table[pos] = entry->Next;
          }
-         free(entry);
+         FREE(entry);
         return;
       }
       prev = entry;
@@ -237,7 +229,7 @@ void HashPrint(const struct HashTable *table)
  * Find a block of 'numKeys' adjacent unused hash keys.
  * Input:  table - the hash table
  *         numKeys - number of keys needed
- * Return:  startint key of free block or 0 if failure
+ * Return:  starting key of free block or 0 if failure
  */
 GLuint HashFindFreeKeyBlock(const struct HashTable *table, GLuint numKeys)
 {
@@ -249,9 +241,9 @@ GLuint HashFindFreeKeyBlock(const struct HashTable *table, GLuint numKeys)
    else {
       /* the slow solution */
       GLuint freeCount = 0;
-      GLuint freeStart = 0;
+      GLuint freeStart = 1;
       GLuint key;
-      for (key=0; key!=maxKey; key++) {
+      for (key=1; key!=maxKey; key++) {
         if (HashLookup(table, key)) {
            /* darn, this key is already in use */
            freeCount = 0;