Exemple #1
0
                unset($this->HashTable[$bucket][$x]);
            }
        }
        /** everything is OK **/
        return 0;
    }
    public function search($string)
    {
        $resultArray = array();
        $bucket = $this->generate_bucket($string);
        if (is_null($this->HashTable[$bucket])) {
            return -1;
        } else {
            if (is_array($this->HashTable[$bucket])) {
                for ($x = 0; $x <= sizeof($this->HashTable[$bucket]); $x++) {
                    if (strcmp($this->HashTable[$bucket][$x]['string'], $string) == 0) {
                        array_push($resultArray, $this->HashTable[$bucket][$x]);
                    }
                }
            } else {
                array_push($resultArray, $this->HashTable[$bucket]);
            }
        }
        return $resultArray;
    }
}
$hash = new HashTable(16);
// $arr = array('nombre' => "jorge niedbalski");
$hash->add("astroza", $arr);
$hash->add("astrozas", $arr);
print_r($hash->search("astrozas"));