Most efficient way to check a range of character values
Moderators: chulett, rschirm, roy
Most efficient way to check a range of character values
I've seen plenty of inefficient methods but I'm looking for the most efficient way out there with the tools at hand. I've used match or alpha when I need to perform a simple alphabetic character check - but how about a range check? Something like when the field must be from 'A' to 'M' inclusive? Looking for the most efficient way to handle that when it needs to be done bazillions of times.
Thanks!
Thanks!
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
What other methods have you tried. If its a range, try changing it into ascii and checking that range.
For example, Alphabets are between 065 - 090 for Uppercase and 097 - 122 for lowercase. That would be much faster.
For example, Alphabets are between 065 - 090 for Uppercase and 097 - 122 for lowercase. That would be much faster.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
There's range checks like 1 to 10, which is really 1.00000000000000 to 10.000000000000, with an infinite number of values between because of decimals.
For this < and > are the best.
There's domain checks like 1 to 10, which is really 1,2,3,4,5,6,7,8,9,10.
For this, enforce no decimal and then the < and > are best.
There's string checks, which are more like domain checks.
For this, you have either the use of a dynamic array for a small number (< 10K) of values, sorted, using the LOCATE BY method for finding. For medium values ( <100K) probably an delimited string with INDEX is good, but after that it's the good old hashed file.
There's string checks, which are more like range checks (A..M).
I'd probably just do a < and > because DS BASIC automatically does lexicographic, which means left to right. No need to switch to CHAR values in an added step, as it's done under the covers anyway.
Of course, once Ray wakes up, he'll render our opinions moot.
For this < and > are the best.
There's domain checks like 1 to 10, which is really 1,2,3,4,5,6,7,8,9,10.
For this, enforce no decimal and then the < and > are best.
There's string checks, which are more like domain checks.
For this, you have either the use of a dynamic array for a small number (< 10K) of values, sorted, using the LOCATE BY method for finding. For medium values ( <100K) probably an delimited string with INDEX is good, but after that it's the good old hashed file.
There's string checks, which are more like range checks (A..M).
I'd probably just do a < and > because DS BASIC automatically does lexicographic, which means left to right. No need to switch to CHAR values in an added step, as it's done under the covers anyway.
Of course, once Ray wakes up, he'll render our opinions moot.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
O yes. Completely forgot that while using > and < operators on characters it implicitly changes them to its ascii. So there you go, my suggestion is already moot.
Craig, look at the R code (Range function). You can specify the range, the lower bounds and upper bounds and the number of ranges. That might help speed up the process.
Craig, look at the R code (Range function). You can specify the range, the lower bounds and upper bounds and the number of ranges. That might help speed up the process.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
-
ray.wurlod
- Participant
- Posts: 54595
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Particularly if the range is contiguous, the Index() function is likely to be fastest.
The comparison operators (> and <) are fine, and - given that the data are already non-numeric - will automatically do a left-justified comparison.
I suspect a "range conversion" would be fairly slick also.
Particularly if multiple ranges need to be tested.
Code: Select all
Index("ABCDEFGHIJKLM", InLink.TheColumn,1) > 0The comparison operators (> and <) are fine, and - given that the data are already non-numeric - will automatically do a left-justified comparison.
I suspect a "range conversion" would be fairly slick also.
Code: Select all
Oconv(InLink.TheColumn, "RA,M")Particularly if multiple ranges need to be tested.
Code: Select all
Oconv(InLink.TheColumn, "RA,M;V,W")IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod wrote:I suspect a "range conversion" would be fairly slick also.Code: Select all
Oconv(InLink.TheColumn, "RA,M")
Particularly if multiple ranges need to be tested.Code: Select all
Oconv(InLink.TheColumn, "RA,M;V,W")
I believe that the OCONV representation of the R code that i was talking about. Right Ray?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
The way to test this is to ... test it!
I usually use several million loop iterations and store the value of SYSTEM(9) before and subtract that from the value after the loop. This value is milliseconds of CPU so if you can make your baseline conversion run for about 5 or 10 minutes then the results should be quite comparable. I suspect that the c-coded ICONV/OCONV routines are going to be pretty efficient.
I usually use several million loop iterations and store the value of SYSTEM(9) before and subtract that from the value after the loop. This value is milliseconds of CPU so if you can make your baseline conversion run for about 5 or 10 minutes then the results should be quite comparable. I suspect that the c-coded ICONV/OCONV routines are going to be pretty efficient.

</a>