This article mainly introduces ASP implements classes similar to hashMap functions
HashMap in java is very convenient to access data, but unfortunately there is no similar class in ASP. The author needs similar data types in the development program, so he constructed a class that can basically be similar to the hashMap function, which can implement key-value access operations, etc. The accessed data can be any basic type in the ASP.
Below is the code of the program, which can be directly run in an empty ASP.
- <%
- setvevb=newJb
- 'Assign value to mp object
- vevb.putva,vevb.com
- vevb.putvb,www.vevb.net
- vevb.putvc,http://www.vevb.net
- response.write[number of key value]:&vevb.count
- response.write<br>
- response.write[a]:&vevb.getv(a)
- response.write<br>
- response.write:&vevb.getv(b)
- response.write<br>
- response.write[c]:&vevb.getv(c)
- response.write<hr>
- 'Delete the key value with key b
- vevb.delvb
- response.write[number of key value]:&vevb.count
- response.write<br>
- response.write[a]:&vevb.getv(a)
- response.write<br>
- response.write:&vevb.getv(b)
- response.write<br>
- response.write[c]:&vevb.getv(c)
- response.write<hr>
- 'Clear all values of vevb
- vevb.clear
- 'Reassign the key value of the key to c
- vevb.putvc,http://www.vevb.net
- response.write[number of key value]:&vevb.count
- response.write<br>
- response.write[a]:&vevb.getv(a)
- response.write<br>
- response.write:&vevb.getv(b)
- response.write<br>
- response.write[c]:&vevb.getv(c)
- response.write<hr>
- ClassMtMap
- privatearr()
- privatearr_len
- 'Constructor
- privateSubClass_Initialize
- 'Where arr(0,n) is key, arr(1,n) is value
- arr_len=0
- redimarr(1,arr_len)
- endsub
- 'Assignment, if present, overwrite
- publicsubputv(k,v)
- dimis_update
- is_update=false
- arr_len=ubund(arr,2)
- fori=0toarr_len-1
- ifk=arr(0,i)then
- arr(1,i)=v
- is_update=true
- exitfor
- endif
- next
- ifnotis_updatethen
- arr_len=arr_len+1
- redempreservearr(1,arr_len)
- arr(0,arr_len)=k
- arr(1,arr_len)=v
- endif
- endsub
- 'Get key value with key k
- publicfunctiongetv(k)
- dimv
- v=
- fori=0toarr_len
- ifk=arr(0,i)then
- v=arr(1,i)
- exitfor
- endif
- next
- getv=v
- endfunction
- 'Delete the key value with key k
- publicsubdelv(k)
- arr_len=ubund(arr,2)
- fori=0toarr_len
- ifk=arr(0,i)then
- v=arr(1,i)
- fork=itoarr_len-1
- arr(0,k)=arr(0,k+1)
- arr(1,k)=arr(1,k+1)
- next
- arr_len=arr_len-1
- redempreservearr(1,arr_len)
- exitfor
- endif
- next
- endsub
- 'Get the number of key values in vevb
- publicpropertygetcount()
- count=arr_len
- endproperty
- 'Clear all key values in vevb
- publicsubclear()
- arr_len=0
- redimarr(1,1)
- endsub
- endclass
- %>
The above is how ASP can implement classes similar to hashMap functions. I hope it will inspire everyone's learning.