]> andersk Git - splint.git/blobdiff - src/cstringTable.c
Added va_copy to standard.h.
[splint.git] / src / cstringTable.c
index 9be49ed895f16c7e39ebbdef2d1d641555031a93..c6cacbecda052652e9b97381cf36d1f98b0fa0bd 100644 (file)
@@ -55,8 +55,7 @@ static hentry hentry_create (/*@only@*/ cstring key, int val)
 
   h->key = key;
   h->val = val;
-  llassert (val != HBUCKET_DNE); /*@i523 way bogus! */
-
+  llassert (val != HBUCKET_DNE); 
   return (h);
 }
 
@@ -83,7 +82,7 @@ hbucket_unparse (hbucket h)
       
       for (i = 0; i < h->size; i++)
        {
-       /*drl bee: si*/  s = message ("%q %s:%d", s, h->entries[i]->key, h->entries[i]->val);
+        s = message ("%q %s:%d", s, h->entries[i]->key, h->entries[i]->val);
        }
     }
 
@@ -98,7 +97,7 @@ hbucket_single (/*@only@*/ hentry e)
   h->size = 1;
   h->nspace = HBUCKET_BASESIZE - 1;
   h->entries = (hentry *) dmalloc (HBUCKET_BASESIZE * sizeof (*h->entries));
/*drl bee: dm*/ h->entries[0] = e;
+ h->entries[0] = e;
   
   return (h);
 }
@@ -116,13 +115,13 @@ hbucket_grow (/*@notnull@*/ hbucket h)
   
   for (i = 0; i < h->size; i++) 
     {
-   /*drl bee: dm*/
-      /*drl bee: si*/  newentries[i] = h->entries[i]; 
+      newentries[i] = h->entries[i]; 
     }
  
-  /*@i32@*/ sfree (h->entries);
+  sfree (h->entries);
   h->entries = newentries; 
-/*@i23@*/ }
+  /*@-compmempass@*/
+} /*@=compmempass@*/ /* Spurious warnings reported - shouldn't need this */
 
 static int hbucket_lookup (hbucket p_h, cstring p_key);
 
@@ -148,7 +147,7 @@ hbucket_add (/*@notnull@*/ hbucket h, /*@only@*/ hentry e)
     }
   
   llassert (e->val != HBUCKET_DNE);
-  /*drl bee: si*/ h->entries[h->size] = e;
+  h->entries[h->size] = e;
   h->size++;
   h->nspace--;
 }
@@ -171,7 +170,7 @@ hbucket_lookup (hbucket h, cstring key)
       
       for (i = 0; i < h->size; i++)
        {
-       /*drl bee: si*/  if (cstring_equal (h->entries[i]->key, key))
+        if (cstring_equal (h->entries[i]->key, key))
            {
              return h->entries[i]->val;
            }
@@ -201,13 +200,13 @@ void hbucket_free (/*@only@*/ hbucket h)
 void 
 cstringTable_free (/*@only@*/ cstringTable h)
 {
-  int i;
+  unsigned int i;
 
   llassert (cstringTable_isDefined (h)); 
 
   for (i = 0; i < h->size; i++)
     {
-      /*drl bee: si*/ hbucket_free (h->buckets[i]);
+      hbucket_free (h->buckets[i]);
     }
 
   sfree (h->buckets);
@@ -218,13 +217,13 @@ static int
 cstringTable_countCollisions (cstringTable h)
 {
   int nc = 0;
-  int i;
+  unsigned long i;
 
   llassert (cstringTable_isDefined (h)); 
 
   for (i = 0; i < h->size; i++)
     {
-  /*drl bee: si*/    nc += hbucket_ncollisions (h->buckets[i]);
+     nc += hbucket_ncollisions (h->buckets[i]);
     }
 
   return (nc);
@@ -235,13 +234,13 @@ static int
 cstringTable_countEmpty (cstringTable h)
 {
   int nc = 0;
-  int i;
+  unsigned long i;
 
   llassert (cstringTable_isDefined (h)); 
 
   for (i = 0; i < h->size; i++)
     {
-    /*drl bee: si*/    if (hbucket_isEmpty (h->buckets[i]))
+       if (hbucket_isEmpty (h->buckets[i]))
        {
          nc++;
        }
@@ -263,7 +262,7 @@ cstringTable_hashValue (/*@notnull@*/ cstringTable h, cstring key)
 
   for (p = cstring_toCharsSafe (key); *p != '\0'; p++)
     {
-      /*drl bee: nm*/ hash_value = (hash_value << 1) ^ g_randomNumbers[*p % 256];
+      hash_value = (hash_value << 1) ^ g_randomNumbers[*p % 256];
     }
 
   return (hash_value % h->size);
@@ -277,9 +276,9 @@ cstringTable_hash (/*@notnull@*/ cstringTable h, cstring key)
 
 
 /*@only@*/ cstringTable
-cstringTable_create (int size)
+cstringTable_create (unsigned long size)
 {
-  int i;
+  unsigned long i;
   cstringTable h = (cstringTable) dmalloc (sizeof (*h));
   
   h->size = size;
@@ -289,7 +288,7 @@ cstringTable_create (int size)
   /*@+loopexec@*/
   for (i = 0; i < size; i++)
     {
-     /*drl bee: dm*/   h->buckets[i] = hbucket_undefined;
+       h->buckets[i] = hbucket_undefined;
     }
   /*@-loopexec@*/
   return h;
@@ -298,21 +297,21 @@ cstringTable_create (int size)
 cstring cstringTable_unparse (cstringTable h)
 {
   cstring res = cstring_newEmpty ();
-  int i;
+  unsigned long i;
 
   if (cstringTable_isDefined (h)) 
     {
       for (i = 0; i < h->size; i++)
        {
-         /*drl bee: si*/  hbucket hb = h->buckets[i];
+          hbucket hb = h->buckets[i];
          
          if (hb != NULL)
            {
-             res = message ("%q%d. %q\n", res, i, hbucket_unparse (hb));
+             res = message ("%q%ul. %q\n", res, i, hbucket_unparse (hb));
            }
        }
       
-      res = message ("%qsize: %d, collisions: %d, empty: %d", 
+      res = message ("%qsize: %ul, collisions: %d, empty: %d", 
                     res,
                     h->size, 
                     cstringTable_countCollisions (h),
@@ -332,7 +331,7 @@ cstring cstringTable_unparse (cstringTable h)
 cstringTable_stats (cstringTable h)
 {
   llassert (cstringTable_isDefined (h)); 
-  return (message ("size: %d, collisions: %d, empty: %d\n", 
+  return (message ("size: %ul, collisions: %d, empty: %d\n", 
                   h->size, cstringTable_countCollisions (h),
                   cstringTable_countEmpty (h)));
 }
@@ -344,9 +343,10 @@ cstringTable_rehash (/*@notnull@*/ cstringTable h)
   ** rehashing based (loosely) on code by Steve Harrison
   */
 
-  int i;
-  int oldsize = h->size;
-  int newsize = 1 + ((oldsize * 26244) / 10000); /* 26244 = 162^2 */
+  unsigned long i;
+  /* Fix provided by Thomas Mertz (int -> unsigned long), 21 Apr 2004 */
+  unsigned long oldsize = h->size;
+  unsigned long newsize = 1 + ((oldsize * 26244) / 10000); /* 26244 = 162^2 */
   hbucket *oldbuckets = h->buckets;
   
   h->size = newsize;  
@@ -356,15 +356,15 @@ cstringTable_rehash (/*@notnull@*/ cstringTable h)
   /*@+loopexec@*/
   for (i = 0; i < newsize; i++)
     {
-     /*drl bee: dm*/   h->buckets[i] = hbucket_undefined;
+       h->buckets[i] = hbucket_undefined;
     }
   /*@=loopexec@*/
   
   for (i = 0; i < oldsize; i++)
     {
-     /*drl bee: dm*/   hbucket bucket = oldbuckets[i];
+       hbucket bucket = oldbuckets[i];
 
-    /*drl bee: dm*/    oldbuckets[i] = NULL;
+       oldbuckets[i] = NULL;
 
       if (!hbucket_isNull (bucket))
        {
@@ -372,7 +372,7 @@ cstringTable_rehash (/*@notnull@*/ cstringTable h)
          
          for (j = 0; j < bucket->size; j++)
            {
-         /*drl bee: si*/      cstringTable_addEntry (h, bucket->entries[j]);
+              cstringTable_addEntry (h, bucket->entries[j]);
            }
          
          /* 
@@ -399,9 +399,9 @@ cstringTable_addEntry (/*@notnull@*/ cstringTable h, /*@only@*/ hentry e)
   ** instead reveals a bug I don't want to deal with right now!
   */
 
-   /*drl bee: si*/ if (hbucket_isNull (h->buckets[hindex]))
+   if (hbucket_isNull (h->buckets[hindex]))
     {
-      /*drl bee: si*/  h->buckets[hindex] = hbucket_single (e); 
+       h->buckets[hindex] = hbucket_single (e); 
       h->nentries++;
     }
   else
@@ -424,7 +424,7 @@ cstringTable_addEntry (/*@notnull@*/ cstringTable h, /*@only@*/ hentry e)
 void
 cstringTable_insert (cstringTable h, cstring key, int value)
 {
-  unsigned int hindex;
+  unsigned long hindex;
   hbucket hb;
   hentry e;  
 
@@ -440,11 +440,11 @@ cstringTable_insert (cstringTable h, cstring key, int value)
   hindex = cstringTable_hashValue (h, key);
   e = hentry_create (key, value);
 
-  /*drl bee: si*/  hb = h->buckets[hindex];
+   hb = h->buckets[hindex];
   
   if (hbucket_isNull (hb))
     {
-       /*drl bee: si*/ h->buckets[hindex] = hbucket_single (e);
+       h->buckets[hindex] = hbucket_single (e);
     }
   else
     {
@@ -478,9 +478,9 @@ cstringTable_update (cstringTable h, cstring key, int newval)
       
       for (i = 0; i < hb->size; i++)
        {
-         /*drl bee: si*/  if (cstring_equal (hb->entries[i]->key, key))
+          if (cstring_equal (hb->entries[i]->key, key))
            {
-             /*drl bee: si*/      hb->entries[i]->val = newval;
+                  hb->entries[i]->val = newval;
              return;
            }
        }
@@ -508,9 +508,9 @@ cstringTable_replaceKey (cstringTable h, cstring oldkey, /*@only@*/ cstring newk
       
       for (i = 0; i < hb->size; i++)
        {
-         /*drl bee: si*/  if (cstring_equal (hb->entries[i]->key, oldkey))
+          if (cstring_equal (hb->entries[i]->key, oldkey))
            {
-             /*drl bee: si*/ hb->entries[i]->key = newkey;
+             hb->entries[i]->key = newkey;
              return;
            }
        }
@@ -533,12 +533,11 @@ cstringTable_remove (cstringTable h, cstring key)
       
       for (i = 0; i < hb->size; i++)
        {
-         /*drl bee: si*/  if (cstring_equal (hb->entries[i]->key, key))
+          if (cstring_equal (hb->entries[i]->key, key))
            {
              if (i < hb->size - 1)
                {
-                 /*drl bee: si*/
-                 hb->entries[i] = hb->entries[hb->size - 1];
+                                 hb->entries[i] = hb->entries[hb->size - 1];
                }
              
              hb->size--;
This page took 0.039421 seconds and 4 git commands to generate.