小編給大家分享一下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://m.kartarina.com/article24/jedeje.html
成都網站建設公司_創新互聯,為您提供網站收錄、電子商務、外貿網站建設、服務器托管、App設計、外貿建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯