fix
[libfirm] / ir / adt / set.c
index bb8cab4..f22c897 100644 (file)
@@ -59,7 +59,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "misc.h"
 #include "xmalloc.h"
 #ifdef PSET
 # include "pset.h"
@@ -86,13 +85,13 @@ typedef struct element {
 
 
 struct SET {
-  short        p;                      /* Next bucket to be split      */
-  short        maxp;                   /* upper bound on p during expansion    */
-  int nkey;                    /* current # keys       */
-  short        nseg;                   /* current # segments   */
+  unsigned p;                  /* Next bucket to be split      */
+  unsigned maxp;               /* upper bound on p during expansion    */
+  unsigned nkey;               /* current # keys       */
+  unsigned nseg;               /* current # segments   */
   Segment *dir[DIRECTORY_SIZE];
   MANGLEP(cmp_fun) cmp;                /* function comparing entries */
-  int iter_i, iter_j;
+  unsigned iter_i, iter_j;
   Element *iter_tail;          /* non-NULL while iterating over elts */
 #ifdef PSET
   Element *free_list;          /* list of free Elements */
@@ -145,14 +144,14 @@ stat_chain_len (SET *table, int chain_len)
 const char *MANGLEP(tag);
 
 
-static void
+void
 MANGLEP(describe) (SET *table)
 {
-  int i, j, collide;
+  unsigned i, j, collide;
   Element *ptr;
   Segment *seg;
 
-  printf ("p=%d maxp=%d nkey=%d nseg=%d\n",
+  printf ("p=%u maxp=%u nkey=%u nseg=%u\n",
          table->p, table->maxp, table->nkey, table->nseg);
   for (i = 0;  i < table->nseg;  i++) {
     seg = table->dir[i];
@@ -162,7 +161,7 @@ MANGLEP(describe) (SET *table)
       while (ptr) {
        if (collide) printf ("<%3d>", collide);
        else printf ("table");
-       printf ("[%d][%3d]: %u %p\n", i, j, ptr->entry.hash, ptr->entry.dptr);
+       printf ("[%d][%3d]: %u %p\n", i, j, ptr->entry.hash, (void *)ptr->entry.dptr);
        ptr = ptr->chain;
        collide++;
       }
@@ -179,10 +178,14 @@ SET *
   int i;
   SET *table = xmalloc (sizeof (SET));
 
-  /* Adjust nslots up to next power of 2, minimum SEGMENT_SIZE */
-  assert (nslots >= 0);
-  for (i = SEGMENT_SIZE;  i < nslots;  i <<= 1) assert (i < (i << 1));
-  nslots = i >> SEGMENT_SIZE_SHIFT;
+  if (nslots > SEGMENT_SIZE * DIRECTORY_SIZE)
+    n_slots = DIRECTORY_SIZE;
+  else {
+    assert (nslots >= 0);
+    /* Adjust nslots up to next power of 2, minimum SEGMENT_SIZE */
+    for (i = SEGMENT_SIZE;  i < nslots;  i <<= 1);
+    nslots = i >> SEGMENT_SIZE_SHIFT;
+  }
 
   table->nseg = table->p = table->nkey = 0;
   table->maxp = nslots << SEGMENT_SIZE_SHIFT;