/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on succes; non-zero on failure. */ public static function main($args) { printf("Demonstration program number 4.\n"); $status = 0; ChainedHashTable::main($args); ChainedScatterTable::main($args); OpenScatterTable::main($args); OpenScatterTableV2::main($args); return $status; }
return new ChainedHashTable_Iterator($this); } /** * Compares this chained hash table with the specified comparable object. * This method is not implemented. * * @param object IComparable $arg * The comparable object to which this chained hash table is compared. */ protected function compareTo(IComparable $arg) { throw new MethodNotImplementedException(); } /** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("ChainedHashTable main program.\n"); $status = 0; $hashTable = new ChainedHashTable(57); AbstractHashTable::test($hashTable); return $status; } } if (realpath($argv[0]) == realpath(__FILE__)) { exit(ChainedHashTable::main(array_slice($argv, 1))); }
/** * Counts the number of distinct words in the input stream and then * prints a table of the words and the number of occurrences * on the output stream. * Uses a hash table. * * @param resource $in The input stream. * @param resource $out The output stream. */ public static function wordCounter($in, $out) { $table = new ChainedHashTable(1031); while (($line = fgets($in)) != false) { $words = preg_split('/[ \\t\\n]+/', $line, -1, PREG_SPLIT_NO_EMPTY); foreach ($words as $word) { $assoc = $table->find(new Association(box($word))); if ($assoc === NULL) { $table->insert(new Association(box($word), box(1))); } else { $count = unbox($assoc->getValue()); $assoc->setValue(box($count + 1)); } } } fprintf($out, "%s\n", str($table)); }