示例#1
0
  public static Stella_Object stellaHashTableLookup(StellaHashTable self, Stella_Object key) {
    {
      KvCons[] table = self.theTable;
      KvCons bucket = null;

      if (table == null) {
        return (null);
      }
      if (self.equalTestP) {
        bucket = table[(((key.equalHashCode()) & 0x7FFFFFFF) % (self.size))];
        while (bucket != null) {
          if (Stella_Object.equalP(bucket.key, key)) {
            return (bucket.value);
          } else {
            bucket = bucket.rest;
          }
        }
      } else {
        bucket = table[(((key.hashCode_()) & 0x7FFFFFFF) % (self.size))];
        while (bucket != null) {
          if (Stella_Object.eqlP(bucket.key, key)) {
            return (bucket.value);
          } else {
            bucket = bucket.rest;
          }
        }
      }
      return (null);
    }
  }
示例#2
0
  /**
   * Return an <code>equalP</code> hash code for <code>self</code>. Note that this is O(N) in the
   * number of entries of <code>self</code>.
   *
   * @return int
   */
  public int equalHashCode() {
    {
      StellaHashTable self = this;

      {
        int code = 36273463;

        {
          Stella_Object key = null;
          Stella_Object value = null;
          StellaHashTableIterator iter000 = ((StellaHashTableIterator) (self.allocateIterator()));

          while (iter000.nextP()) {
            key = iter000.key;
            value = iter000.value;
            code = (code ^ (key.equalHashCode()));
            code = (code ^ (value.equalHashCode()));
          }
        }
        return (code);
      }
    }
  }
示例#3
0
  public static void stellaHashTableRemoveAt(StellaHashTable self, Stella_Object key) {
    {
      KvCons[] table = self.theTable;
      int bucketindex = 0;
      KvCons bucket = null;
      boolean equaltestP = self.equalTestP;

      if (table == null) {
        return;
      }
      if (equaltestP) {
        bucketindex = (((key.equalHashCode()) & 0x7FFFFFFF) % (self.size));
      } else {
        bucketindex = (((key.hashCode_()) & 0x7FFFFFFF) % (self.size));
      }
      bucket = table[bucketindex];
      if (bucket == null) {
        return;
      } else if ((!equaltestP) && Stella_Object.eqlP(bucket.key, key)) {
        table[bucketindex] = bucket.rest;
        self.freeElements = self.freeElements + 1;
        return;
      } else if (equaltestP && Stella_Object.equalP(bucket.key, key)) {
        table[bucketindex] = bucket.rest;
        self.freeElements = self.freeElements + 1;
        return;
      } else {
        {
          KvCons trailer = bucket;

          bucket = bucket.rest;
          while (bucket != null) {
            if ((!equaltestP) && Stella_Object.eqlP(bucket.key, key)) {
              trailer.rest = bucket.rest;
              self.freeElements = self.freeElements + 1;
              return;
            } else if (equaltestP && Stella_Object.equalP(bucket.key, key)) {
              trailer.rest = bucket.rest;
              self.freeElements = self.freeElements + 1;
              return;
            } else {
              trailer = bucket;
              bucket = bucket.rest;
            }
          }
        }
      }
    }
  }
示例#4
0
  public static void stellaHashTableInsertAt(
      StellaHashTable self, Stella_Object key, Stella_Object value) {
    {
      KvCons[] table = self.theTable;
      int free = self.freeElements;
      int bucketindex = 0;
      KvCons bucket = null;
      boolean equaltestP = self.equalTestP;

      if (table == null) {
        StellaHashTable.initializeStellaHashTable(self);
        table = self.theTable;
        free = self.freeElements;
      }
      if (free == 0) {
        StellaHashTable.rehashStellaHashTable(self, Stella.pickHashTableSizePrime(self.size + 1));
        table = self.theTable;
        free = self.freeElements;
      }
      if (equaltestP) {
        bucketindex = (((key.equalHashCode()) & 0x7FFFFFFF) % (self.size));
      } else {
        bucketindex = (((key.hashCode_()) & 0x7FFFFFFF) % (self.size));
      }
      bucket = table[bucketindex];
      if (bucket == null) {
        {
          KvCons self000 = KvCons.newKvCons();

          self000.key = key;
          self000.value = value;
          table[bucketindex] = self000;
        }
        self.freeElements = free - 1;
      } else {
        {
          KvCons cursor = bucket;

          if (equaltestP) {
            while ((cursor != null) && (!Stella_Object.equalP(cursor.key, key))) {
              cursor = cursor.rest;
            }
          } else {
            while ((cursor != null) && (!Stella_Object.eqlP(cursor.key, key))) {
              cursor = cursor.rest;
            }
          }
          if (cursor != null) {
            cursor.value = value;
          } else {
            {
              KvCons self001 = KvCons.newKvCons();

              self001.key = key;
              self001.value = value;
              self001.rest = bucket.rest;
              bucket.rest = self001;
            }
            self.freeElements = free - 1;
          }
        }
      }
    }
  }