Announcement

Collapse
No announcement yet.

Array scan ... Or ...

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

  • Michael Mattias
    replied
    Instead of multiple tag arrays, go the whole mile:

    Specify the data type in a FROM..TO sort of a UDT array to handle the bit-packing:
    Code:
    TYPE  FooType
      A AS STRING * 6
      B AS LONG
      C AS SINGLE
      D AS LONG
    END TYPE
    
    DIM Foo (lots) AS FooType
    ...
    
    ARRAY SORT Foo(), FROM 5 to 8 AS LONG
    AND, add multiple keys with direction for each

    Code:
    ARRAY SORT Foo(), FROM 1 TO 6 AS STRING ASCEND, FROM 5 TO 8 AS LONG DESCEND...

    This *is* a "wish" list, right?

    MCM

    Leave a comment:


  • Peter Manders
    replied
    Edwin,

    I'm not sure if I understand your problem correctly, but if you want to find the next empty item in an array, you just have to start your scan at the index where you put your last new item.
    If you reach the end of the array you can start at the first index again, if you then reach your first starting index, no empty array items were found. All you need is a variable pointing to the last added index.

    This is much faster than always starting at the first index.


    Peter


    ------------------
    [email protected]

    Leave a comment:


  • Edwin Knoppert
    replied
    We are making use of several arrays with the same index, tagarray could help but the problem is that allmost any code was time consuming in this case.

    Sort is not really an option.
    Prefilling in't either, i increase the array with 1000 empty items, this makes it faster, search for an empty element the next time.
    Much faster.

    Adding 5000 items in several arrays is done in < .5 seconds, wich was good but the faster the better.

    Indeed, adding more states would help me..

    ---

    I already HAD a do-loop, it's not as fast as one array scan.
    (I tried a lot and took a few weeks and using some small asm code to increase speed(happy))

    Thanks,


    ------------------
    [email protected]

    Leave a comment:


  • Phil Tippit
    replied
    Edwin,

    You may have already done this, but if you haven't!!!

    The Do Loop in this sample is a work around on your problem,
    it will return all values that are not null and are <> than
    the value you are scanning against.

    It may be just as fast to use a FOR NEXT and compare
    <> on each string array.

    Code:
    FUNCTION PBMAIN() AS LONG
    DIM a$(1 TO 100)
     RANDOMIZE TIMER
     FOR i& = 1 TO 100
      b&=RND(48,53)  '0000' TO '0005'
     a$(i&)="000"+CHR$(b&)  ' create 100 strings 4 chars long (could be anything)
     NEXT
     FOR i& = 2 TO 9:a$(i&)="0001":NEXT  ' force some of them
         a$(10)="0003"
     FOR i& = 1 TO 100 STEP 12
         a$(i&)=""                  ' make some of them null
     NEXT
     FOR b& = 1 TO 20:PRINT I&,a$(b&):NEXT
         WAITKEY$
     b&=0:j$="0001"
     DO
     recheck:
       INCR b&
       ARRAY SCAN a$(b&),FROM 1 TO 4, <> j$, TO i&
       IF i& = 0 THEN EXIT DO
       i&=(i&+b&)-1
     LOOP WHILE a$(i&)=""
     IF i& THEN
        PRINT i&,a$(i&)
        WAITKEY$
        b&=i&
        IF b& < UBOUND(a$) THEN GOTO recheck
     END IF
    END FUNCTION
    ------------------




    [This message has been edited by Phil Tippit (edited January 11, 2001).]

    Leave a comment:


  • Lance Edmonds
    replied
    Huh? How can "" = "0000"...? PowerBASIC will not make this distinction, but your program may?

    Of course, if you are scanning for '<> "0001"' then a nul string will fulfil that expression. However, in your example, ARRAY SCAN will return 1, since it is the 2nd subscript that satisfies the condition ("0002")... the null string appears later in the array and is not located on that pass.

    So, you may need to re-evaluate your approach here, since you imply that your program treats "" identically to "0000"... Why not sort the array first (in descending order), and then use ARRAY SCAN? This way the empty entries will appear at the end of the list (assuming the real string data starts with ASCII code 33 or higher).

    Alternatively, prefill your array with "0000" if that is practical.

    Adding more "states" to ARRAY SCAN is certainly an idea though, and I'll pass this along to R&D.

    I personally would like to see ARRAY SORT being able to use multiple TAGARRAYs... that would be much more useful (to me!).



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

    Leave a comment:


  • Edwin Knoppert
    started a topic Array scan ... Or ...

    Array scan ... Or ...

    I want more selections in array scan

    I have an dynamic string array

    T()

    T( 0 ) = "0001"
    T( 1 ) = "0002"
    T( 2 ) = ""
    T( 4 ) = "0003"

    I want:
    Code:
    Array Scan T(), Form 1 to 4 <> "0001" And Not ""
    How
    The problem is "" is equal to "0000" in array scan i believe.



    ------------------
    [email protected]
Working...
X