2011-02-27 38 views
2

imはvb.netで二重ハッシングハッシュテーブルを作成しようとしています。解決方法がわからないといういくつかのエラーが発生しています。あなた達が私を助けてくれることを願っています。私はdbnull.valueまたはmod =私はエディタでエラーを取得し、私は 'それらを修正する方法を知っていない。私が何を意味するかを見るためにこのコードをVBに入れてください。ここ は、コードは次のとおりです。vb.netの二重ハッシュテーブルまたは二重ハッシュハッシュテーブル

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 

エンドクラス

+0

あなたの質問は何ですか? – Gabe

+0

dbnull.valueの構文エラーが表示され、このような行があるhashVal mod = arraySizeと、mod = stuffのvb – bob

+0

nvmのnullの他の値はわかりません。 – bob

答えて

0

通常、第2のハッシュ関数は0

を返してはいけません、私はDBNull.ValueのはのDataItemから継承するとは思いません。また、配列は、Nothingへの参照を含むサイズの配列に初期化されます。

+0

私の質問にはお答えしません – bob

+0

あなたの質問に精緻化を試みるかもしれません。これは、これが動作しないようにするのには十分ですが、それ以上になる可能性があります。 – Joshua

+0

これをvbに入れ、エラーが発生していることを確認してください。 – bob