ASP实现类似hashMap功能的类(hashmap实现了哪些接口)这样也行?

随心笔谈2年前发布 编辑
161 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买


<%
set jb51=new Jb
‘给mp对象赋值
jb51.putv “a”,”jb51.net”
jb51.putv “b”,”www.jb51.net”
jb51.putv “c”,”https://www.jb51.net”
response.write “[键值数量]:”&jb51.count
response.write “<br>”
response.write “[a]:”&jb51.getv(“a”)
response.write “<br>”
response.write “:”&jb51.getv(“b”)
response.write “<br>”
response.write “[c]:”&jb51.getv(“c”)
response.write “<hr>”
‘删除key为”b”的键值
jb51.delv “b”
response.write “[键值数量]:”&jb51.count
response.write “<br>”
response.write “[a]:”&jb51.getv(“a”)
response.write “<br>”
response.write “:”&jb51.getv(“b”)
response.write “<br>”
response.write “[c]:”&jb51.getv(“c”)
response.write “<hr>”
‘清空jb51的所有值
jb51.clear
‘给key为”c”的键值重新赋值
jb51.putv “c”,”https://www.jb51.net”
response.write “[键值数量]:”&jb51.count
response.write “<br>”
response.write “[a]:”&jb51.getv(“a”)
response.write “<br>”
response.write “:”&jb51.getv(“b”)
response.write “<br>”
response.write “[c]:”&jb51.getv(“c”)
response.write “<hr>”
Class MtMap
private arr()
private arr_len
‘构造函数
private Sub Class_Initialize
‘其中 arr(0,n)为key,arr(1,n)为value
arr_len=0
redim arr(1,arr_len)
end sub

‘赋值,如果存在则覆盖
public sub putv(k,v)
dim is_update
is_update=false
arr_len=ubound(arr,2)
for i=0 to arr_len-1
if k=arr(0,i) then
arr(1,i)=v
is_update=true
exit for
end if
next
if not is_update then
arr_len=arr_len +1
redim preserve arr(1,arr_len)
arr(0,arr_len)=k
arr(1,arr_len)=v
end if
end sub
‘取得key为”k”的键值
public function getv(k)
dim v
v=””
for i=0 to arr_len
if k=arr(0,i) then
v=arr(1,i)
exit for
end if
next
getv=v
end function

‘删除key为”k”的键值
public sub delv(k)
arr_len=ubound(arr,2)
for i=0 to arr_len
if k=arr(0,i) then
v=arr(1,i)
for k=i to arr_len-1
arr(0,k)=arr(0,k+1)
arr(1,k)=arr(1,k+1)
next
arr_len=arr_len – 1
redim preserve arr(1,arr_len)
exit for
end if
next
end sub

‘获得jb51中键值的数量
public property get count()
count=arr_len
end property

‘清空jb51中所有的键值
public sub clear()
arr_len=0
redim arr(1,1)
end sub
end class
%>

© 版权声明

相关文章