📄 hash.asp
字号:
<%
Class ImplMocomUtilHash
Private keyHash
Private valHash
Private Sub Class_Initialize()
keyHash = Array()
valHash = Array()
End Sub
Private Sub Class_Terminate()
Erase keyHash
Erase valHash
End Sub
Public Default Property Get Item(ByVal strKey)
Dim i
For i = 0 To Me.Count
If strKey = keyHash(i) Then
If IsObject(valHash(i)) Then
Set Item = valHash(i)
Else
Item = valHash(i)
End If
Exit Property
End If
Next
End Property
Public Property Let Item(ByVal strKey, vtIn)
Dim i
For i = 0 To Me.Count
If strKey = keyHash(i) Then
If IsObject(vtIn) Then
Set valHash(i) = vtIn
Else
valHash(i) = vtIn
End If
Exit Property
End If
Next
i = Me.Count + 1
ReDim Preserve keyHash(i)
ReDim Preserve valHash(i)
keyHash(i) = strKey
If IsObject(vtIn) Then
Set valHash(i) = vtIn
Else
valHash(i) = vtIn
End If
End Property
Public Property Get Keys()
Keys = keyHash
End Property
Public Property Get Items()
Items = valHash
End Property
Public Property Get Count()
Count = UBound(valHash)
End Property
Public Function Exists(ByVal strKey)
Dim i
For i = 0 To Me.Count
If strKey = keyHash(i) Then
Exists = True
Exit Function
End If
Next
Exists = False
End Function
Public Sub Remove(ByVal strKey)
If Exists(strKey) = False Then Exit Sub
If Me.Count = 0 Then
Call RemoveAll
Else
Dim newKey, newVal
ReDim newKey(Me.Count - 1)
ReDim newVal(Me.Count - 1)
Dim i, k
k = 0
For i = 0 To Me.Count
If strKey <> keyHash(i) Then
newKey(k) = keyHash(i)
If IsObject(valHash(i)) Then
Set newVal(k) = valHash(i)
Else
newVal(k) = valHash(i)
End If
k = k + 1
End If
Next
Erase keyHash
Erase valHash
keyHash = newKey
valHash = newVal
End If
End Sub
Public Sub Rename(ByVal strKey, ByVal newKey)
If strKey = newKey Then Exit Sub
If Exists(newKey) Then
Err.Raise vbObjectError + 1, "Hash.Rename", "同名索引已存在"
End If
Dim i
For i = 0 To Me.Count
If strKey = keyHash(i) Then
keyHash(i) = newKey
Exit For
End If
Next
End Sub
Public Sub RemoveAll()
Erase keyHash
Erase valHash
keyHash = Array()
valHash = Array()
End Sub
Public Function toString()
If Me.Count = -1 Then Exit Function
Dim i
Dim ret
ReDim ret(Me.Count)
For i = 0 To Me.Count
ret(i) = keyHash(i) & "=" & CEncode(valHash(i))
Next
toString = Join(ret, "|")
End Function
Public Function newInstance()
Set newInstance = New ImplMocomUtilHash
End Function
End Class
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -