You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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))
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).]
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!).
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: