php中自定义hashmap类
来源:互联网 发布:中国大萧条 知乎 编辑:程序博客网 时间:2024/05/02 04:31
<?php
/**
* @(#)hashable.php
* PHP version 5.2.3
*
*
* Copyright 2007 SoftRoad. All Rights Reserved.
*
*====================================================================
* 変更履歴
*
* 新規作成 2007 年5月17日 蒋彪
*/
class HashTable {
var $H_table;
/*
* コンストラクタ
*/
function __construct() {
$this->H_table = array ();
}
/*
Object put(key,value)
*/
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;
}
}
/*
void clear()
*/
function clear() {
$this->H_table = null;
$this->H_table = array ();
}
/*
boolean containsValue(value)
*/
function containsValue($value) {
while ($curValue = current($this->H_table)) {
if ($curValue == $value) {
return true;
}
next($this->H_table);
}
return false;
}
/*
boolean containsKey(key)
*/
function containsKey($key) {
if (array_key_exists($key, $this->H_table)) {
return true;
} else {
return false;
}
}
/*
object get(key)
*/
function get($key) {
if (array_key_exists($key, $this->H_table))
return $this->H_table[$key];
else
return null;
}
/*
boolean isEmpty()
*/
function isEmpty() {
return (count($this->H_table) == 0);
}
/*
*int size()
*/
function size() {
return count($this->H_table);
}
/*
*対象を削除します
*/
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;
}
function toString() {
print_r($this->H_table);
}
}
?>
- php中自定义hashmap类
- php中自定义分页处理类
- php中自定义数据库处理类
- php中自定义分页处理类
- HashMap中如果key是自定义的类,为什么重写hashcode()和equals()
- java HashMap用自定义类作为key
- mybatis返回HashMap<Long,List<自定义类>>
- java HashMap用自定义类作为key
- Java 自定义类作为HashMap的key
- flex 自定义HashMap类(转)
- java中HashMap类用法
- php自定义异常类
- javesript 中的自定义hashmap
- 自定义HashMap中的key
- 工具 - js自定义HashMap
- 模仿源码自定义HashMap
- js 自定义hashmap
- hashMap转自定义实体
- postgre数据库备份shell
- 深入正则表达式
- postgre数据库备份恢复shell
- C++字符串完全指引之二 —— 字符串封装类
- 脚本是个好东西,要搞出一个类似CodeSmith的代码生成器真的很EASY
- php中自定义hashmap类
- C# 代码文件头部注释批量写入, 函数注释批量删除的工具
- IIS6.0日志文件分析代码_2生成访问记录到文本文件
- Grep学习笔记
- 我的创业想法
- analysis
- tomcat 5.5配连接池
- dynamips 安装手册
- 编辑一个小程序,让人开机进不了电脑,这个方法能行吗?大家说说,我认为是骗人的吧