js 定义hash类
// JavaScript Document
function HashTable(){
this._hash={};
this._count=0;
/**
*添加或者更新key
*/
this.put=function(key,value){
if(this._hash.hasOwnProperty(key)){
this._hash[key]=value;
return true;
}else{
this._hash[key]=value;
this._count++;
return true;
}
}
/**
*获取key指定的值
*/
this.get=function(key){
if(this.containsKey(key))
return this._hash[key];
}
/**
*获取元素个数
*/
this.size=function(){
return this._count;
}
/**
*检查是否为空
*/
this.isEmpty=function(){
if(this._count<=0)
return true;
else return false;
}
/**
*检查是否包含指定的key
*/
this.containsKey=function(){
return this._hash.hasOwnPropetry(key);
}
/**
*检查是否包含指定的value
*/
this.containsValue=function(){
for(var strKey in this._hash)
if(this._hash[strKey]==value)
return true;
return false;
}
/**
*删除一个key
*/
this.remove=function(key){
delete this._hash[key];
this._count--;
}
/**
*删除所有的key
*/
this.clear=function(){
this._hash={};
this._count=0;
}
/**
*从HashTable中获取Key的集合,以数组的形式返回
*/
this.keySet=function(){
var arrKeySet= new Array();
var index=0;
for(var strKey in this._hash){
arrKeySet[index++]=strKey;
}
return (arrKeySet.length==0)?null:arrKeySet;
}
/**
*从HashTable中获取Key的集合,以数组的形式返回
*/
this.values=function(){
var arrValues= new Array();
var index=0;
for(var strKey in this._hash){
arrValues[index++]=this._hash[strKey];
}
return (arrValues.length==0)?null:arrValues;
}
}
最新文章
- AOJ 0033 Ball【DFS】
- (C++) Include 文件
- egrep 及扩展正则表达式
- WebResource.axd 404 错误
- codecademy-command line-inputoutput
- Linq to Entities
- View模版的设计
- J2SE7规范_2013.2_类
- ZOJ 3913 Bob wants to pour water
- Quartz2D 之 简单介绍
- JavaScript中国象棋程序(4) - 极大极小搜索算法
- laravel实现支付宝支付功能
- FIFO深度计算
- [转帖]pfSense软路由系统的使用
- 将图片嵌入到markdown文档中
- RabbmitMQ-组成及简单使用
- webpack的使用一
- HDU 1561 The more, The Better (有依赖背包 || 树形DP)
- HTML5开发——轻量级JSON存储解决方案Lawnchair.js
- CocoaPods 创建私有仓库
热门文章
- 【Mac + Pycharm】之实用东西以及配置东西
- 详解path和classpath的区别
- 登录shell与非登录shell读取文件过程
- Java对文件夹中的文件按修改时间排序
- cocos2d-x 3.0rc1 使用iconv库 解决UTF8乱码问题
- 去除app中的标题栏
- data standardization
- 【python】-- 进程与线程
- The given &#39;driver&#39; ] is unknown, Doctrine currently supports only the follo wing drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo
- 寻找第K大 网易2016实习研发工程师编程题