Btw. that is not exactly heuristic approach (more like plain algorithmic),
because I don't know statistical properties of you array. IE what we can
assume. Now the index is always divided by two, but if you know how the
distribution of the data, you may make much more effective guesses
depending on what you will find with the current index.


Jussi

On Thu, May 11, 2017 at 12:09 AM, Jussi Lahtinen <jussi.lahti...@gmail.com>
wrote:

> This works only for sorted array. Example you could take the maximum index
> of your array, divide it by two and look which side of the array the
> searched string could be.
>
> Let's say you have array of 1000 elements and you are looking for "Chr".
> If sMyArray[500] begins with "M", then you should look only first half of
> the array. Or you could narrow the possibilities even more by dividing the
> 500 by two. Now if sMyArray[250] begins with "B", you know you just have to
> search between indexes 250 - 500, or narrow it even further.
>
> I hope you got the idea.
>
>
> Jussi
>
>
>
> On Wed, May 10, 2017 at 11:04 PM, Matti <matti.e...@vodafone.de> wrote:
>
>> Jussi, could you please explain?
>> Yes, I have to match the beginning of the string - but what means a
>> "heuristic guess for the index"?
>>
>> Am 10.05.2017 um 21:25 schrieb Jussi Lahtinen:
>> > If you need to match only the beginning of the string, you could sort
>> the
>> > array and then make heuristic guess for the index.
>> >
>> >
>> > Jussi
>> >
>> > On Wed, May 10, 2017 at 10:18 PM, Matti <matti.e...@vodafone.de> wrote:
>> >
>> >> Yes. But as I don't know [iIndex], I have to iterate through the (huge)
>> >> array with 'For...Next'.
>> >> I hoped to make it faster with 'Find'.
>> >>
>> >> Am 10.05.2017 um 20:59 schrieb Jussi Lahtinen:
>> >>> For that use; String.InStr(sYourArray[iIndex], "Chr")
>> >>>
>> >>>
>> >>> Jussi
>> >>>
>> >>>
>> >>> On Wed, May 10, 2017 at 9:24 PM, Matti <matti.e...@vodafone.de>
>> wrote:
>> >>>
>> >>>> Oh yes, oh yes!
>> >>>> Thank you, Jorge.
>> >>>> I always thought, Value could also be part of a string.
>> >>>>
>> >>>> Am 10.05.2017 um 19:08 schrieb Jorge Carrión:
>> >>>>> Wiki says: "Returns the position of the first occurrence of Value in
>> >> the
>> >>>>> array."
>> >>>>> You must search for a Value of the array.
>> >>>>>
>> >>>>> In your array there isn't a Value "Chr", that is what you search, so
>> >>>> always
>> >>>>> returns -1
>> >>>>>
>> >>>>>
>> >>>>> Best Regars
>> >>>>>
>> >>>>> 2017-05-10 18:57 GMT+02:00 Matti <matti.e...@vodafone.de>:
>> >>>>>
>> >>>>>> I tried to search an array with the 'Find' function instead of
>> >>>>>> 'For...Next' and 'InStr'.
>> >>>>>>
>> >>>>>> The wiki says:
>> >>>>>> "String[].Find (gb)
>> >>>>>> Function Find ( Value As String [ , Mode As Integer, Start As
>> Integer
>> >> ]
>> >>>> )
>> >>>>>> As Integer
>> >>>>>> Returns the position of the first occurrence of Value in the array.
>> >>>>>> If Value cannot be found, -1 is returned."
>> >>>>>>
>> >>>>>> But I can do what I want, I always get '-1'. No positive result
>> ever.
>> >>>>>>
>> >>>>>> Attached is a tiny project that should show this behaviour.
>> >>>>>> Where is my mistake?
>> >>>>>> Thanks in advance
>> >>>>>> Matti
>> >>>>>>
>> >>>>>> Gambas 3.9.2
>> >>>>>>
>> >>>>>> ------------------------------------------------------------
>> >>>>>> ------------------
>> >>>>>> Check out the vibrant tech community on one of the world's most
>> >>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> >>>>>> _______________________________________________
>> >>>>>> Gambas-user mailing list
>> >>>>>> Gambas-user@lists.sourceforge.net
>> >>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >>>>>>
>> >>>>>>
>> >>>>> ------------------------------------------------------------
>> >>>> ------------------
>> >>>>> Check out the vibrant tech community on one of the world's most
>> >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> >>>>> _______________________________________________
>> >>>>> Gambas-user mailing list
>> >>>>> Gambas-user@lists.sourceforge.net
>> >>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >>>>>
>> >>>> ------------------------------------------------------------
>> >>>> ------------------
>> >>>> Check out the vibrant tech community on one of the world's most
>> >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> >>>> _______________________________________________
>> >>>> Gambas-user mailing list
>> >>>> Gambas-user@lists.sourceforge.net
>> >>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >>>>
>> >>> ------------------------------------------------------------
>> >> ------------------
>> >>> Check out the vibrant tech community on one of the world's most
>> >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> >>> _______________________________________________
>> >>> Gambas-user mailing list
>> >>> Gambas-user@lists.sourceforge.net
>> >>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >> ------------------------------------------------------------
>> >> ------------------
>> >> Check out the vibrant tech community on one of the world's most
>> >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> >> _______________________________________________
>> >> Gambas-user mailing list
>> >> Gambas-user@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >>
>> > ------------------------------------------------------------
>> ------------------
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> > _______________________________________________
>> > Gambas-user mailing list
>> > Gambas-user@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to