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;
}
}
js 定义hash类的更多相关文章
- js定义类和方法
js中定义一个类 //定义一个user类 var user = function(){ //类中的属性 var age; //设置age的值 var setAge = function(age){ t ...
- JS定义类的六种方式详解
转载自: http://www.jb51.net/article/84089.htm 在前端开发中,经常需要定义JS类.那么在JavaScript中,定义类的方式有几种,分别是什么呢?本文就JS定义类 ...
- js定义类的方法
ECMAScript6已经支持了class,但之前版本都不支持类,但是可以通过一些方法来模拟类. js中的类,既是重点,也是难点,很多时候都感觉模棱两可. 首先强调一下js中很重要的3个知识点:thi ...
- 通过寄生组合式继承创建js的异常类
最近项目中在做js的统一的异常处理,需要自定义异常类.理想的设计方案为:自定义一个异常错误类BaseError,继承自Error,然后再自定义若干个系统异常,例如用户取消异常.表单异常.网络异常,这些 ...
- NodeJs中类定义及类使用
1.首先定义类Point,文件名为point.class.js: // 定义类 class Point { //构造函数 constructor(x, y) { this.x = x;//类中变量 t ...
- js中的类
概述 经典的老书害人啊,全是讨论怎么解决javascript里面用函数形式定义类的坑.结果es2015直接用class关键字解决了所有问题.虽然class关键字没有什么新东西,只是js现有继承结构的语 ...
- 【JS】#001 JS定义对象写法(原型、JSON方式)
下面主要写两种 JS 定义对象的 常用写法 写法1:[很像面向对象语言中的写法] function zhongxia(age) { this.age = age; } zhongxia.name = ...
- js中有关类、对象的增强函数
javascript中继承的实现 基础实现 function Range(from,to){ this.from =from; this.to =to; } Range.prototype = { i ...
- js常用工具类.
一些js的工具类 复制代码 /** * Created by sevennight on 15-1-31. * js常用工具类 */ /** * 方法作用:[格式化时间] * 使用方法 * 示例: * ...
随机推荐
- centos7 安装postgresql10
https://blog.csdn.net/rudy5348/article/details/79299162
- .net 字符串驻留
.net中的string表达的是常量字符串. JIT编译器编译时判断遇到的常量字符串是否在内部散列表中,如果不在,添加进去.当第一次执行到含字符串的方法时,CLR会检查该字符串是否在内部的一个散列表中 ...
- XtraBackup备份mysql5.1.73
一.基础介绍 mysql5.1在源码中配备了两个版本的innodb存储引擎源码:innobase和innodb_plugin,编译安装的时候可以通过参数--with-plugins=innobase, ...
- Unity中surfaceShader的处理机制和finalColor
http://blog.csdn.net/swj524152416/article/details/52945375
- Java线程面试题:子线程先运行 2 次,然后主线程运行 4 次,如此反复运行 3 次
package thread; /** * 需求:线程编程:子线程先运行 2 次,然后主线程运行 4 次,如此反复运行 3 次. * @author zhongfg * @date 2015-06-1 ...
- lua注册函数
#include <stdio.h> #include <math.h> #define MAX_COLOR 255 extern "C" { #inclu ...
- Catalan数以及使用Raney引理证明
一.Catalan数性质 1.1 令h(0)=1,h(1)=1,catalan数满足递推式: h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) ...
- [原创]使用vscode+es6写nodejs服务端调试配置
前端的小伙伴们在babel等的加持下,已经可以愉快的使用es6来写代码了. 然后对于服务端的nodejs就有点坑爹了,虽然原生支持了es6,但是只是部分支持,一些不支持的特性(比如module)使用了 ...
- hive常规配置及常用命令使用
hive 常用的几种shell交互方式 查看hive命令帮助:bin/hive -help [hd@hadoop-senior hive]$ bin/hive -help usage: hive -d ...
- UITableView 右侧索引
1.设置右侧索引字体颜色 self.tabView.sectionIndexColor = [UIColor blackColor]; 2.设置右侧索引背景色 self.cityTabView.sec ...