Alaska Software Inc. - Ascan Softseek
Username: Password:
AuthorTopic: Ascan Softseek
Salar MadadiAscan Softseek
on Tue, 07 Mar 2006 11:07:56 -0500
Hi,

Does anyone have a custom ASCAN that will work similar to a SOFT SEEK where
if it doesn't find an exact match, will find the next closest element?

Regards,

Salar Madadi
- Latest Developments Inc.
James Loughner Re: Ascan Softseek
on Tue, 07 Mar 2006 11:30:53 -0500
Is the array sorted?

Jim

Salar Madadi wrote:
> Hi,
> 
> Does anyone have a custom ASCAN that will work similar to a SOFT SEEK where
> if it doesn't find an exact match, will find the next closest element?
>
Salar MadadiRe: Ascan Softseek
on Tue, 07 Mar 2006 12:52:59 -0500
Jim,

Yes, the array is sorted on the element that we want to "SOFT SEEK" to.

Salar

"James Loughner" <jwrl@charter.net> wrote in message
news:16581752$2c71ff3$15fdb1@news.alaska-software.com...
> Is the array sorted?
>
> Jim
>
> Salar Madadi wrote:
> > Hi,
> >
> > Does anyone have a custom ASCAN that will work similar to a SOFT SEEK
where
> > if it doesn't find an exact match, will find the next closest element?
> >
James Loughner Re: Ascan Softseek
on Tue, 07 Mar 2006 13:01:48 -0500
ASCAN(aArray,{|a| a[element]>= xSought })

Jim

Salar Madadi wrote:

> Jim,
> 
> Yes, the array is sorted on the element that we want to "SOFT SEEK" to.
> 
> Salar
> 
> "James Loughner" <jwrl@charter.net> wrote in message
> news:16581752$2c71ff3$15fdb1@news.alaska-software.com...
> 
>>Is the array sorted?
>>
>>Jim
>>
>>Salar Madadi wrote:
>>
>>>Hi,
>>>
>>>Does anyone have a custom ASCAN that will work similar to a SOFT SEEK
> 
> where
> 
>>>if it doesn't find an exact match, will find the next closest element?
>>>
> 
> 
>
Thomas Braun
Re: Ascan Softseek
on Wed, 08 Mar 2006 08:55:17 +0100
Salar Madadi wrote:

> Does anyone have a custom ASCAN that will work similar to a SOFT SEEK where
> if it doesn't find an exact match, will find the next closest element?

First of all, if the array is already sorted, a binary search (see below)
is much faster - based on the following code it should be easy to achieve
what you need:

FUNCTION BinarySearch(aArray,xSearch,bSearch)
LOCAL nHigh  := len(aArray)+1
LOCAL nLow   := 0
LOCAL nProbe := 0

   DEFAULT bSearch TO {|nI| aArray[nI] }

   DO WHILE nHigh-nLow > 1
      nProbe    := int((nHigh+nLow)/2)
      IF EVAL(bSearch, nProbe) <= xSearch
         nlow   := nProbe
      ELSE
         nHigh  := nProbe
      ENDIF
   ENDDO
RETURN iif(nLow=0 .or. .NOT. EVAL(bSearch, nLow) == xSearch,0,nLow)

HTH
Thomas