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; } } } } } }
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); } }
/** * Return TRUE if <code>x</code> and <code>y</code> represent the same set of key/value pairs. * * @param y * @return boolean */ public boolean objectEqualP(Stella_Object y) { { StellaHashTable x = this; if (Surrogate.subtypeOfP( Stella_Object.safePrimaryType(y), Stella.SGT_STELLA_STELLA_HASH_TABLE)) { { StellaHashTable y000 = ((StellaHashTable) (y)); if (x.length() == y000.length()) { { Stella_Object key = null; Stella_Object value = null; StellaHashTableIterator iter000 = ((StellaHashTableIterator) (x.allocateIterator())); while (iter000.nextP()) { key = iter000.key; value = iter000.value; if (!Stella_Object.equalP(value, y000.lookup(key))) { return (false); } } } return (true); } } } else { } return (false); } }
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; } } } } }