hello Fernando
Try the aSeek function below
The sintax is as follows
Regards
Leandro



ASORT(::aArrayResumo, {|a,b| str(a[1],11)+str(a[3],11)+dtoc(a[5])+a[7] > 
str(b[1],11)+str(b[3],11)+dtoc(b[5])+b[7] } )

nPosicaoArray := aSeek(    ::aArrayResumo, ;
                            STR( 
::oQueryRelatorioPrincipal:fieldGet('idgrupo_centro_custo'),11)+;
                            
STR(::oQueryRelatorioPrincipal:fieldGet('idcentro_custo'),11 )+;
                            DTOC(oDB:Mysql2Date 
(::oQueryRelatorioPrincipal:fieldGet('data_emissao') ) )+cSiglaMoeda,;
                                                        {|a| 
str(a[1],11)+str(a[3],11)+dtoc(a[5])+a[7]},;
                            .T.)
**********************************************

Function aSeek(aArray,xSearch,bSearch,lExact)

**********************************************

local xValue, vvv

local nPos := 1

local nFound := 0

local nLen := len(aArray)

local nJump := nLen-1 

local nBottom := nLen-1, nTop:=2

lExact:=valtype(lExact)=="L" .and. lExact

do while nPos>0 .and. nPos<=nLen .and. nJump>0

    if valtype(bSearch)=="B"

        xValue:=eval(bSearch,aArray[nPos])

    else

        xValue:=aArray[nPos]

    endif


    do case

        case xValue>xSearch

            nTop:=nPos

            nPos-=nJump

        case xValue<xSearch

            nBottom:=nPos

            nPos+=nJump

        other

            nFound:=nPos

            exit 

    endcase


        nJump:=int(nJump/2)

endd

do case

    case nFound==0

        if nPos>0

            for nFound=nBottom to nTop

                if valtype(bSearch)=="B"

                    xValue:=eval(bSearch,aArray[nFound])

                else

                    xValue:=aArray[nFound]

                endif

                if xValue==xSearch .or. (xValue=xSearch .and. !lExact)

                    Return nFound

                endif

            next

        endif

        Return 0

    case nFound==1

        if xValue==xSearch .or. (xValue=xSearch .and. !lExact)

            Return nFound

        else

            Return 0

        endif

    other

        nPos:=nFound-1

        do while nPos>nBottom

            if valtype(bSearch)=="B"

                vvv:=eval(bSearch,aArray[nPos])

            else

                vvv:=aArray[nPos]

            endif

            do case

                case vvv#xSearch

                    exit

                case vvv==xSearch .or. !lExact

                    xValue:=vvv

                    nFound:=nPos

            endcase

            nPos--

        endd

        if xValue==xSearch .or. !lExact

            Return nFound

        endif

endcase

Return 0




From: Fernando Athayde 
Sent: Saturday, November 07, 2009 8:01 AM
To: [email protected] 
Subject: [Harbour] ASCAN slow - proposal weighted search


ASORT(::aArrayResumo, {|a,b| str(a[1],11)+str(a[3],11)+dtoc(a[5])+a[7] > 
str(b[1],11)+str(b[3],11)+dtoc(b[5])+b[7] } )

//Normal way (Slow for more than 100 registers)
nPosicaoArray := ASCAN(::aArrayResumo, ;
                 {|a| str(a[1],11)+str(a[3],11)+dtoc(a[5])+a[7] ==;
                      STR( 
::oQueryRelatorioPrincipal:fieldGet('idgrupo_centro_custo'),11)+;
                      
STR(::oQueryRelatorioPrincipal:fieldGet('idcentro_custo'),11 )+;
                      DTOC(oDB:Mysql2Date 
(::oQueryRelatorioPrincipal:fieldGet('data_emissao') ) )+cSiglaMoeda} )

//Weighted search (Is very fast)
nPosicaoArray := 0
nArraySize := LEN( ::aArrayResumo )
nJump := nArraySize - 1
nPosition := 1
DO WHILE .T.
   nPosition += nJump
   IF nPosition > nArraySize
      nJump := 0
      nPosition := nArraySize
   ENDIF
   IF str(::aArrayResumo[nPosition,1],11)+str(::aArrayResumo[nPosition,3],11);
               +dtoc(::aArrayResumo[nPosition,5])+::aArrayResumo[nPosition,7] >;
      STR( ::oQueryRelatorioPrincipal:fieldGet('idgrupo_centro_custo'),11 );
                +STR( ::oQueryRelatorioPrincipal:fieldGet('idcentro_custo'),11 
);
                +DTOC(oDB:Mysql2Date 
(::oQueryRelatorioPrincipal:fieldGet('data_emissao') ) )+cSiglaMoeda

      nPosition -= nJump
      nJump := INT(nJump/2)
   ENDIF
   IF str(::aArrayResumo[nPosition,1],11)+str(::aArrayResumo[nPosition,3],11);
            +dtoc(::aArrayResumo[nPosition,5])+::aArrayResumo[nPosition,7] == 
      STR( ::oQueryRelatorioPrincipal:fieldGet('idgrupo_centro_custo'),11 );
            +STR( ::oQueryRelatorioPrincipal:fieldGet('idcentro_custo'),11 );
            +DTOC(oDB:Mysql2Date 
(::oQueryRelatorioPrincipal:fieldGet('data_emissao') ) )+cSiglaMoeda
      nPosicaoArray := nPosition
      EXIT
   ENDIF
   IF nJump<1
      EXIT
   ENDIF
ENDDO

my proposal is made a ASCANEX sending a block how parameter
but i don´t know how to use eval and blocks

Thanks,
Fernando Athayde


__________________________________________________
Fale com seus amigos de graça com o novo Yahoo! Messenger 
http://br.messenger.yahoo.com/ 


--------------------------------------------------------------------------------


_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to