Announcement

Collapse
No announcement yet.

Request for new function "Array Scan"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    Ron, I am scanning for the last inserted item matching the search-criteria,
    not the last inserted item...
    A couple of things...

    A. If you are looking for the last inserted item meeting a criteria, why bother sorting the array at all?
    B. Doing a REDIM PRESERVE for *every* insert takes time; better perhaps to allocate new "block" of elements (maybe 100 at a time, using something like REDIM PRESERVE FooArray (1: UBOUND(FooArray) + 100) and keep trak of the number of valid elements.)
    C. If "entry sequence" is important to you, it should be part your sort key.
    D. If none of these methods floats your boat, I published a linked-list method of keeping a list of UDTs in sorted order by three keys at once. This code is public domain, available at the IMS web site. The December, 1998 issue of "BASICally Speaking" included MS-DOS code along with a detailed explanation of what I was doing in an article entitled, "Make Haste,Not Waste." The April, 1999 issue contained the migration of that code to PB/Win32 in an article entitled, "Dynamic Allocation and Linked Lists: Porting from PB/DOS to PB/CC"
    Since the code is public domain it may be posted in the source code forum by anyone. The article texts are copyright; reprints are available from IMS at http://www.infoms.com, follow the links to Basically Speaking.

    Bottom line: ARRAY SCAN BACKWARDS may be a neat feature, but just looking at you application I think you have a number of things to try to speed it up without waiting for a new feature.




    ------------------
    Michael Mattias
    Racine WI USA
    [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Great idea guys... I've passed it on to R&D.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Fred Oxenby
    replied
    Florent, My need is unsorted array of UDT's with >100,000 elements
    I have tried your way, but you have to create (or maintain) the
    array of element-numbers and make two Array Sort on this, one before and one
    after the Array Scan. Just one word -ItIsNotFastEnogh
    ----
    There is a way to 'sort'. If you have a Udt like this:
    Code:
    Type MyUdt
     ElementNr    as long
     OtherElement as string 
     Date         as Double
     etc
    End Type
    
    When you add new elements you do it this way
    -----
    Dim Udt as MyUdt
      .... 
      NewRec& = Ubound(Array)+1
      Redim Preserve Array(NewRec&)
      ceRweN$ = Peek$(VarPtr(NewRec&),4)
      ceRweN$ = StrReverse$(ceRweN$)
      Poke$ VarPtr(Udt.ElementNr),ceRweN$
      Array(NewRec&) = Udt
         
      Array Sort Array(),From 1 To 3,DESCEND
      ....
      Now the Array element is in 'reverse' order
    Just a thought
    ---------
    Ron, I am scanning for the last inserted item matching the search-criteria,
    not the last inserted item...


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited January 08, 2001).]

    Leave a comment:


  • Guest
    Guest replied
    If you are trying to determine if "my first hit is the 'latest insert' in the array"
    why not examine the last subscript and not do an array scan?

    I know it must not be this simple but it appears to be.


    ------------------
    Ron

    Leave a comment:


  • Borje Hagsten
    replied
    Yes, if the array can be manipulated, but we usually want to
    keep it intact, plus, in time critical code, it makes things a
    lot slower, especially with large arrays. Backwards SCAN would
    enable us to speed up many things quite a bit.

    For purpose of quickly finding latest inserted item, one could use
    a tagged array of Longs though, where you set UBOUND(tArray) to
    matching array item each time one is inserted and then use,
    ARRAY SCAN tArray(), = UBOUND(tArray) - 1

    But if items only are added to an array, Array(UBOUND(Array) - 1)
    will of course do the same thing much faster..


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

    Leave a comment:


  • Florent Heyworth
    replied
    Hi guys

    You could SORT DESCENDING on a TAGARRAY and then do the ARRAY
    SCAN...

    As in:
    Code:
    #COMPILE EXE
    
    FUNCTION PBMAIN() AS LONG
        DIM i AS LONG
        DIM a(0:26) AS STRING
        DIM b(0:26) AS LONG
        
        FOR i = 1 TO 27
            a(i-1) = CHR$(i+47) + "Hello there" + CHR$(i+47)
            b(i-1) = i
        NEXT
        
        ARRAY SORT a(0), TAGARRAY b(), DESCEND
    
        ARRAY SCAN a(), = "JHello thereJ", TO i
        PRINT a(i-1)
        
        WAITKEY$
    END FUNCTION

    But I agree it would be a useful short cut...

    Cheers

    Florent

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

    Leave a comment:


  • Borje Hagsten
    replied
    Fred, are you a mind reader? Thought about the exact same thing
    only a couple of days ago. I fully support this wish..

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

    Leave a comment:


  • Fred Oxenby
    started a topic Request for new function "Array Scan"

    Request for new function "Array Scan"

    I have not seen request for this.
    If it is already on the wish-list, please tick it once more.

    I frequently need to scan arrays in 'reverse' direction to ensure that
    my first hit is the 'latest insert' in the array

    ARRAY SCAN REVERSE A()....
    or
    ARRAY SCAN A(Ubound(A)),FOR -200,......


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

Working...
X