Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
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;
            }
          }
        }
      }
    }
  }
Ejemplo n.º 3
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;
          }
        }
      }
    }
  }