Questions for all. 'Robert'
Robert. does compare do short-circuiting?
IE: compare("alpha", "beta")-- exit as soon as it realized 'a'
is less than 'b'
This message contains the following.
[Code to be optimized]
[Questions about structure]
[Code to be optimized]
1) I submit the function that I created below.
2) I request ANY ideas to make it run faster. IE: Optimize it.
3) I request ideas as to how a HASH formula might help.
4)a) I intend this function for a certain project.
4)b) I request optimizations ideas design for that particular project.
4)c) The project is my structure routines.
I created the function below and it works as follows.
include sort.e
sequence unsorted_list, sorted_list
-- the lists can be MUCH longer
-- and bfind() is only faster if the list is text and 250 elements or more.
-- bfind() is faster on atoms only if the list is 1,000's of elements.
unsorted_list = {"name", "age", "year", "birthdate", "wage"}
sorted_list = sort(unsorted_list)
--Now I can use bfind() just as I would use find() except
--bfind() requires a sorted list. It may not find() the first
--instance of a value in the list IE:
--{1, 1, 2} find() would return 1 bfind() would return 2
--therefore bfind() only returns indentical values as find()
--if the list is sorted and there are NO Duplicate values.
? find("birthdate", sorted_list)-- prints 2
? bfind("birthdate', sorted_list)-- prints 2
----bfind.e
global function bfind(object this_in, sequence that)
integer min, max, gtlt, here
min = 0
max = length(that)
here = floor((max / 2) + .5)
while min != max do
gtlt = compare(this_in, that[here])
if gtlt = 0 then
return here
elsif gtlt = 1 then
min = here
here = floor(((min + max) / 2) + .5)
else
max = here
here = floor(((min + max) / 2) + .5)
end if
end while
return 0
end function
[Questions about structure]
I have found that find() is the bottleneck in my structure routines.
The function above is my attempt to remedy the bottleneck. However,
It fails to do so. The above routine will actually be much slower
when there are few structures. I can easily build into the structure
routines to circumvent that problem. IE: Autodetect for more than
250 structures and use bfind() only when that requirement is met but
That will mean that most of the time, probably all of the time,
bfind() would not be used and would actually just be BLOAT code.
Or better yet, I could build the Autodetect directly into the bfind()
routine.
Just wondering,
Lucius L. Hilley III
|
Not Categorized, Please Help
|
|