php怎么实现hashmap
小编给大家分享一下php怎么实现hashmap,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

成都创新互联公司专注于叶集企业网站建设,自适应网站建设,成都商城网站开发。叶集网站建设公司,为叶集等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务
php实现hashmap的方法:使用【construct()】构造函数实现,代码为【Class HashMap{var $H_table;public function __construct(){$this->H_table = a}】。
php实现hashmap的方法:
主要方法参照JAVA的HASHMAP实现的
Class HashMap{
var $H_table;
public function __construct() {
$this->H_table = array ();
}
public function put($key, $value) {
if (!array_key_exists($key, $this->H_table)) {
$this->H_table[$key] = $value;
return null;
} else {
$tempValue = $this->H_table[$key];
$this->H_table[$key] = $value;
return $tempValue;
}
}
public function get($key) {
if (array_key_exists($key, $this->H_table))
return $this->H_table[$key];
else
return null;
}
public function remove($key) {
$temp_table = array ();
if (array_key_exists($key, $this->H_table)) {
$tempValue = $this->H_table[$key];
while ($curValue = current($this->H_table)) {
if (!(key($this->H_table) == $key))
$temp_table[key($this->H_table)] = $curValue;
next($this->H_table);
}
$this->H_table = null;
$this->H_table = $temp_table;
return $tempValue;
} else
return null;
}
public function keys(){
return array_keys($this->H_table);
}
public function values(){
return array_values($this->H_table);
}
public function putAll($map){
if(!$map->isEmpty()&& $map->size()>0){
$keys = $map->keys();
foreach($keys as $key){
$this->put($key,$map->get($key));
}
}
}
public function removeAll() {
$this->H_table = null;
$this->H_table = array ();
}
public function containsValue($value) {
while ($curValue = current($this->H_table)) {
if ($curValue == $value) {
return true;
}
next($this->H_table);
}
return false;
}
public function containsKey($key) {
if (array_key_exists($key, $this->H_table)) {
return true;
} else {
return false;
}
}
public function size() {
return count($this->H_table);
}
public function isEmpty() {
return (count($this->H_table) == 0);
}
public function toString() {
print_r($this->H_table);
}
}看完了这篇文章,相信你对php怎么实现hashmap有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
网页题目:php怎么实现hashmap
转载来于:http://www.jxjierui.cn/article/jedeje.html


咨询
建站咨询
