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中文网如有侵权请联系admin#tyuanma.cn删除
在php中in_array怎么用?(用法介绍)
声明: 本文章由【亿码酷站】整理自网络!如有侵权,请邮件联系 ymkuzhan@126.com 删除。本站发布的文章及附件仅限用于学习和研究目的;不得将上述内容用于商业或非法用途,否则后果请用户自负。
本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。
赞助本站仅为维持服务器日常运行并非购买程序及源码费用因此不提供任何技术支持,如需商用请购买正版!
本站资源如无特殊说明解压密码一律为www.ymkuzhan.com
本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。
赞助本站仅为维持服务器日常运行并非购买程序及源码费用因此不提供任何技术支持,如需商用请购买正版!
本站资源如无特殊说明解压密码一律为www.ymkuzhan.com