public static void rehashStellaHashTable(StellaHashTable self, int newsize) {
    if (self.theTable == null) {
      StellaHashTable.initializeStellaHashTable(self);
      return;
    }
    { int size = self.size;
      KvCons[] table = self.theTable;
      KvCons[] newtable = new KvCons[newsize];
      int newbucketindex = 0;
      KvCons newbucket = null;
      KvCons cursor = null;
      KvCons current = null;
      boolean equaltestP = self.equalTestP;

      { int i = Stella.NULL_INTEGER;
        int iter000 = 0;
        int upperBound000 = newsize - 1;

        for (;iter000 <= upperBound000; iter000 = iter000 + 1) {
          i = iter000;
          newtable[i] = null;
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter001 = 0;
        int upperBound001 = size - 1;

        for (;iter001 <= upperBound001; iter001 = iter001 + 1) {
          i = iter001;
          cursor = table[i];
          while (cursor != null) {
            if (equaltestP) {
              newbucketindex = (((cursor.key.equalHashCode()) & 0x7FFFFFFF) % newsize);
            }
            else {
              newbucketindex = (((cursor.key.hashCode_()) & 0x7FFFFFFF) % newsize);
            }
            newbucket = newtable[newbucketindex];
            current = cursor;
            cursor = cursor.rest;
            if (newbucket != null) {
              current.rest = newbucket.rest;
              newbucket.rest = current;
            }
            else {
              newtable[newbucketindex] = current;
              current.rest = null;
            }
          }
        }
      }
      self.theTable = newtable;
      self.size = newsize;
      self.freeElements = Stella.integer_max(self.freeElements + Native.floor((newsize - size) * Stella.$STELLA_HASH_TABLE_AVG_BUCKET_LENGTH$), 0);
    }
  }