【问题标题】:double hashtable or double hashing hashtable in vb.netvb.net 中的双哈希表或双哈希哈希表
【发布时间】:2011-02-27 03:03:34
【问题描述】:

我试图在 vb.net 中创建一个双散列哈希表,但我遇到了一些我不知道如何解决的错误。希望你们能帮助我。我遇到的问题是我有 dbnull.value 或 mod= 我在编辑器中遇到错误,我不知道如何修复它们。将此代码放入 vb 以了解我的意思。 这是代码:

Public Class DoubleHashing

Class DataItem
    Private data As Integer

    Public Sub New(ByVal i As Integer)
        data = i
    End Sub
    Public Function getKey() As Integer
        Return data
    End Function

End Class

Private hashArray() As DataItem
Private arraySize As Integer
Private bufItem As DataItem

Public Sub New(ByVal size As Integer)

    arraySize = size
    hashArray(arraySize) = New DataItem(arraySize)
    Dim bufItem(-1) As DataItem
End Sub

Public Function hashFunc1(ByVal key As Integer) As Integer
    Return key Mod arraySize
End Function

Public Function hashFunc2(ByVal key As Integer) As Integer
    Return 6 - key Mod 6
End Function


Public Sub insert(ByVal key As Integer, ByVal item As DataItem)
    Dim hashVal As Integer = hashFunc1(key) ' hash the key
    Dim stepSize As Integer = hashFunc2(key) ' get step size

    ' until empty cell or -1
    While hashArray(hashVal) <> DBNull.Value & hashArray(hashVal).getKey() <> -1
        hashVal += stepSize ' add the step
        hashVal mod= arraySize ' for wraparound
    End While
    hashArray(hashVal) = item ' insert item

End Sub

Public Function delete(ByVal key As Integer) As DataItem
    Dim hashVal As Integer = hashFunc1(key)
    Dim stepSize As Integer = hashFunc2(key) ' get step size

    While hashArray(hashVal) <> DBNull.Value
        If hashArray(hashVal).getKey() = key Then
            Dim temp As DataItem = hashArray(hashVal) ' save item
            hashArray(hashVal) = bufItem '  delete item
            Return temp '  return item
        End If

        hashVal += stepSize ' add the step
        hashVal mod= arraySize '  for wraparound
    End While

    Return DBNull.Value
End Function

Public Function find(ByVal key As Integer) As DataItem
    Dim hashVal As Integer = hashFunc1(key)
    Dim stepSize As Integer = hashFunc2(key)

    While hashArray(hashVal) <> DBNull.Value
        If hashArray(hashVal).getKey() = key Then
            Return hashArray(hashVal)
        End If

        hashVal += stepSize
        hashVal mod= arraySize
    End While

    Return DBNull.Value
End Function

结束类

【问题讨论】:

  • 那么你的问题是什么?
  • 我在 dbnull.value 和类似 hashVal mod= arraySize 的行中出现语法错误,我不知道 vb 中 null 的任何其他值

标签: vb.net hashtable double-hashing


【解决方案1】:

通常第二个散列函数不能返回 0。

我不认为 DBNull.Value 继承自 DataItem。此外,您的数组被初始化为包含对 Nothing 的引用的某个大小的数组。

【讨论】:

  • 那没有回答我的问题
  • 您可以尝试详细说明您的问题。这足以导致它不起作用,但很可能还有更多。
  • 把它放到 vb 中看看错误我很难解释
猜你喜欢
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
相关资源
最近更新 更多