我想找到如何處理與HashTable
碰撞檢測。哈希表碰撞檢測解決方案
我的散列算法不好,導致許多碰撞,我在一個更好的算法工作:HashKey = (Mid(HashKey, 1, 3) * Mid(HashKey, 1, 3) Mod 11)
我救了我的結構Stock
:
<Serializable()>
Public Structure Stock
'Create a structure for the hash table stock file
<VBFixedString(10)> Public Barcode As String
<VBFixedString(20)> Public Category As String
<VBFixedString(20)> Public Title As String
<VBFixedString(20)> Public Description As String
<VBFixedString(4)> Public Quantity As Integer
<VBFixedString(8)> Public RRP As Double
<VBFixedString(8)> Public Cost As Double
End Structure
我目前用的手段檢測碰撞:
If HashTable(HashKey) = "" Then
...
SaveStock
End If
這是一種可靠的檢查方式嗎?如果檢測到碰撞,我如何解決VB.net。我是否必須實現自己的鏈表或者Hashtable類型是否具有處理它的屬性?
您應該使用泛型集合,而不是HashTable。 – SLaks
HashTable&Dictionary使用唯一鍵。代碼尖叫'使用類'的 – SLaks
。我敢打賭,如果你添加了一個產品代碼(也許是一個BarCode版本),那麼它可以作爲一個Dictionary鍵 – Plutonix