zoukankan
html css js c++ java
javascript实现的Hashtable
<
SCRIPT LANGUAGE
=
"
JavaScript
"
>
<!--
function
HashTable()
{
this
.Items
=
[];
this
.Count
=
function
()
{
return
this
.Items.length;}
;
//
长度
this
.DictionaryEntry
=
function
(key,value)
{
this
.Key
=
key
||
null
;
this
.Value
=
value
||
null
;
}
this
.Add
=
function
(key,value)
{
this
.Items.push(
new
this
.DictionaryEntry(key,value));}
this
.Clear
=
function
()
{
this
.Items.length
=
0
;}
this
.Remove
=
function
(key)
{
var
index
=
this
.GetIndexWithKey(key);
if
(index
>-
1
)
this
.Items.splice(index,
1
);
}
this
.GetValue
=
function
(key)
{
var
index
=
this
.GetIndexWithKey(key);
if
(index
>-
1
)
return
this
.Items[index].Value;
}
this
.ContainsKey
=
function
(key)
{
if
(
this
.GetIndexWithKey(key)
>-
1
)
return
true
;
return
false
;
}
this
.ContainsValue
=
function
(value)
{
if
(
this
.GetIndexWithValue(value)
>-
1
)
return
true
;
return
false
;
}
this
.Keys
=
function
()
{
var
iLen
=
this
.Count();
var
resultArr
=
[];
for
(
var
i
=
0
;i
<
iLen;i
++
)
resultArr.push(
this
.Items[i].Key);
return
resultArr;
}
this
.Values
=
function
()
{
var
iLen
=
this
.Count();
var
resultArr
=
[];
for
(
var
i
=
0
;i
<
iLen;i
++
)
resultArr.push(
this
.Items[i].Value);
return
resultArr;
}
this
.IsEmpty
=
function
()
{
return
this
.Count()
==
0
;}
this
.GetIndexWithKey
=
function
(key)
{
var
iLen
=
this
.Count();
for
(
var
i
=
0
;i
<
iLen;i
++
)
if
(
this
.Items[i].Key
===
key)
return
i;
return
-
1
;
}
this
.GetIndexWithValue
=
function
(value)
{
var
iLen
=
this
.Count();
for
(
var
i
=
0
;i
<
iLen;i
++
)
if
(
this
.Items[i].Value
===
value)
return
i;
return
-
1
;
}
}
var
my
=
new
HashTable();
my.Add(
"
name
"
,
"
blueKnight
"
);
my.Add(
"
age
"
,
'
24
'
);
my.Add(
"
sex
"
,
"
boy
"
);
alert(my.Count());
alert(my.ContainsValue(
"
boy
"
));
alert(my.GetValue(
"
name
"
))
for
(
var
i
in
my.Items)
{
alert(
"
Key:
"
+
my.Items[i].Key
+
"
--Value:
"
+
my.Items[i].Value);
}
my.Remove(
"
age
"
);
alert(my.Keys()
+
'
-
'
+
my.Values()
+
'
\n\r
'
);
//
-->
<
/
SCRIPT>
原主体部分摘自于网络。
本人对原js中存在的部分bug进行了修正。
查看全文
相关阅读:
眼底血管分割测试部分
眼底血管分割训练函数(SVM,Adaboost)
将眼底图片生成的txt文件进行格式化处理
图像特征的提取(gaussian,gabor,frangi,hessian,Morphology...)及将图片保存为txt文件
读书计划(2020年秋)
假期周进度报告3
信息化领域热词分类分析及解释
个人课程总结
第二阶段团队冲刺3
第二阶段团队冲刺2
原文地址:https://www.cnblogs.com/ding0910/p/1106599.html
最新文章
[CF453B] Little Pony and Harmony Chest
[ZJOI2009]假期的宿舍
[Luogu2879][USACO07JAN]区间统计Tallest Cow
[BZOJ1206][HNOI2005]虚拟内存
[BZOJ1009][HNOI2008]GT考试
[BZOJ2662][BeiJing wc2012]冻结
[BZOJ2440][中山市选2011]完全平方数
django 外键的增删改查,一对多和多对多
django 如何创建表关系
django 模型开发迭代新增字段,修改字段,删除字段,针对旧的数据库表
热门文章
mysql sql修改表必会
数据库外键关系分类一对多,一对一,多对多
django restframework 序列化 serializer
django 请求解析器-前端请求参数解析
版本器
数据结构C++实现代码-顺序表
将labelme 生成的.json文件进行可视化的代码+label.png 对比度处理的matlab代码
论文阅读笔记二-ImageNet Classification with Deep Convolutional Neural Networks
论文阅读笔记一:Tutorial on Gabor Filters
眼底血管图片数据的采样函数(每隔20行进行采样操作)
Copyright © 2011-2022 走看看