HashMap access to data in Java is very convenient, unfortunately there is no similar class in ASP. The author needs similar data types in the development program, and constructs a class that can basically resemble the HashMap function, can realize the key-value access operation and so on, and the data can be accessed by any basic type in ASP.
The following is the code of the program, posted to an empty ASP can run directly. There are questions you can communicate with me here:
<%
examples of the use of
' Miantuanmap
' Author: miantuan.net
' email:ray@miantuan.net
' qq:12694448
' ac area: http://www.miantuan.net
' Instantiates an object of a Mtmap class
Set miantuanmap = new Mtmap
' assigns a value to an MP object
Miantuanmap.putv "A", "Miantuan.net"
Miantuanmap.putv "B", "Www.miantuan.net"
Miantuanmap.putv "C", "Http://www.miantuan.net"
Response.Write "[Number of key values]:" &miantuanmap.count
Response.Write "<br>"
Response.Write "[A]:" &miantuanmap.getv ("a")
Response.Write "<br>"
Response.Write ":" &miantuanmap.getv ("B")
Response.Write "<br>"
Response.Write "[C]:" &miantuanmap.getv ("C")
Response.Write "
' deletes key to ' B '
Miantuanmap.delv "B"
Response.Write "[Number of key values]:" &miantuanmap.count
Response.Write "<br>"
Response.Write "[A]:" &miantuanmap.getv ("a")
Response.Write "<br>"
Response.Write ":" &miantuanmap.getv ("B")
Response.Write "<br>"
Response.Write "[C]:" &miantuanmap.getv ("C")
Response.Write "
' empties all values of Miantuanmap
miantuanmap.clear
' assigns value to key ' C '
Miantuanmap.putv "C", "Http://miantuan.net"
Response.Write "[Number of key values]:" &miantuanmap.count
Response.Write "<br>"
Response.Write "[A]:" &miantuanmap.getv ("a")
Response.Write "<br>"
Response.Write ":" &miantuanmap.getv ("B")
Response.Write "<br>"
Response.Write "[C]:" &miantuanmap.getv ("C")
Response.Write "
'-------------------------------------
' implements classes similar to HashMap functions
' Author: miantuan.net
' email:ray@miantuan.net
' qq:12694448
Class mtmap
Private arr ()
Private Arr_len
' constructor
Private Sub class_initialize
' where arr (0,n) is Key,arr (1,n) for value
arr_len = 0
ReDim arr (1,arr_len)
End Sub
' assignment, if present overwrite
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
' Gets the key value of ' 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
' deletes key value of ' 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
' Gets the number of key values in the Mtmap
Public Property Get count ()
count = Arr_len
End Property
' empties all the key values in the Mtmap
Public Sub Clear ()
arr_len = 0
ReDim arr (1,1)
End Sub
end class
%>