Results 1 to 40 of 87

Thread: Simple and fast, lightweight HashList-Class (no APIs)

Threaded View

  1. #11
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

    Re: Simple and fast, lightweight HashList-Class (no APIs)

    BTW, The Microsoft Dictionary from the scrrun.dll uses next hashing algorithm for strings:
    Code:
    INT CalcHashFromStringItem (BSTR bstrKey) {
        INT iResult = 0;
        
        for (INT i = 0; i < SysStringLen(bstrKey); i++)
            iResult = iResult * 17 + bstrKey[i];
        
        iResult %= 1201;
        
        return iResult;
        
    }
    I make an analog for testing it in VB6:
    Code:
    Option Explicit
    
    Private Declare Function GetMem4 Lib "msvbvm60" ( _
                             ByRef src As Any, _
                             ByRef Dst As Any) As Long
    
    Private Sub Form_Load()
        Dim sKey    As String
        Dim pDic    As Dictionary
        Dim index   As Long
        
        Set pDic = New Dictionary
        
        For index = 0 To 10
            sKey = MakeRandomString()
            Debug.Print pDic.HashVal(sKey), Dictionaty_HashVal(sKey)
        Next
        
    End Sub
    
    Private Function MakeRandomString() As String
        Dim l As Long:  Dim i As Long
        
        l = Int(Rnd * 10) + 5
        
        Do While l
            
            i = Int(Rnd * 62)
            
            Select Case i
            Case Is < 10
                i = i + 48
            Case Is < 36
                i = i - 10 + 65
            Case Else
                i = i - 36 + 97
            End Select
            
            MakeRandomString = MakeRandomString & Chr$(i)
            
            l = l - 1
            
        Loop
        
    End Function
    
    Private Function Dictionaty_HashVal( _
                     ByRef sValue As String) As Long
        Dim index   As Long
        Dim result  As Long
        
    #If COMPILED Then
        
        ' // We can't use unsigned arithmetic without overflow in IDE
        For index = 0 To Len(sValue) - 1
            result = result * 17 + AscW(Mid$(sValue, index + 1, 1))
        Next
        
        result = result Mod 1201
        
    #Else
        
        ' // In order to bypass overflow error, we use currency 64-bit numbers
        Dim cResult As Currency
        
        For index = 0 To Len(sValue) - 1
        
            cResult = cResult * 17 + AscW(Mid$(sValue, index + 1, 1)) / 10000@
            
            ' // Zero high dword
            If cResult > 429496.7295@ Then
                GetMem4 0&, ByVal VarPtr(cResult) + 4
            End If
            
        Next
        
        cResult = cResult * 10000@
        result = cResult - Int(cResult / 1201@) * 1201@
        
    #End If
        
        Dictionaty_HashVal = result
        
    End Function
    Also i attached the project that allows make some tricks with MS Dictionary (sorting/get key/etc.). This knowledge had been obtained during reversing scrrun.dll code on Windows 7 x64 therefore it can distinct on the different platforms.
    Name:  DicViever.png
Views: 4615
Size:  14.7 KB
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width