Scrabble Dictionary
#12
From my opening post, it uses a binary search for our word array: 
Code: (Select All)
Function BinaryStringSearch (search$, Array() As String)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    BinaryStringSearch = BinaryStringSearchSome(search$, Array(), LBound(Array), UBound(Array))
End Function

Function BinaryStringSearchSome (search$, Array() As String, StartIndex As Long, EndIndex As Long)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    min = StartIndex
    max = EndIndex

    Do
        gap = (max + min) \ 2
        compare = _StrCmp(search$, Array(gap))
        If compare > 0 Then
            min = gap + 1
        ElseIf compare < 0 Then
            max = gap - 1
        Else
            BinaryStringSearchSome = gap
            Exit Function
        End If
        If max - min < 1 Then
            If search$ = Array(min) Then
                BinaryStringSearchSome = min
            Else
                BinaryStringSearchSome = LBound(Array) - 1
                If search$ < Array(min) Then
                    LastIndex = min - 1
                Else
                    LastIndex = min
                End If
            End If
            found = -1
        End If
    Loop Until found
End Function
Reply


Messages In This Thread
Scrabble Dictionary - by SMcNeill - 11-22-2022, 05:01 PM
RE: Scrabble Dictionary - by PhilOfPerth - 11-23-2022, 02:31 AM
RE: Scrabble Dictionary - by SMcNeill - 11-23-2022, 02:53 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-23-2022, 02:58 AM
RE: Scrabble Dictionary - by bplus - 11-23-2022, 04:08 PM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 12:00 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 12:23 AM
RE: Scrabble Dictionary - by SMcNeill - 11-24-2022, 01:58 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 02:58 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 04:12 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 04:29 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 08:01 AM
RE: Scrabble Dictionary - by SMcNeill - 11-24-2022, 04:34 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 04:40 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 12:50 PM



Users browsing this thread: 1 Guest(s)