The fastest to search: list or array ? [SOLVED]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
The fastest to search: list or array ? [SOLVED]
Hi to all,
As said in the title of this topic, I'm wondering what is the fastest to make a text search.
Consider these two hypotheses:
1- A list of 25000 lines, each line has 11 items
2- An array of 25000 rows and 11 colums
Problems:
1 - I want to search a word (as item 1), let say near the line or row 22000.
2 - From that word, I want to get the item or colum number 9.
I suppose the list will be slower in Problem 2, but faster in Problem 1, right ?
Kind regards.
As said in the title of this topic, I'm wondering what is the fastest to make a text search.
Consider these two hypotheses:
1- A list of 25000 lines, each line has 11 items
2- An array of 25000 rows and 11 colums
Problems:
1 - I want to search a word (as item 1), let say near the line or row 22000.
2 - From that word, I want to get the item or colum number 9.
I suppose the list will be slower in Problem 2, but faster in Problem 1, right ?
Kind regards.
Last edited by atout66 on Sat Apr 12, 2014 1:02 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.
Re: The fastest to search: list or array ?
Hmmm.
How does one search an array directly? I may be missing a big piece of my LC knowledge, but if I am right, you would have to change your array variable in the clear anyway, and then the question is moot.
Do I have a big hole or not? Anyone?
Craig
How does one search an array directly? I may be missing a big piece of my LC knowledge, but if I am right, you would have to change your array variable in the clear anyway, and then the question is moot.
Do I have a big hole or not? Anyone?
Craig
Re: The fastest to search: list or array ?
Bonjour atout66,
no idea what is faster, but you can do:
Best
Klaus
no idea what is faster, but you can do:
Code: Select all
...
put fld "the long list with many items" into tList
put "Whatever" into tSearchWord
put lineoffset(tSearchword,tList) into tLine
## Not found!
if tLine = 0 then
exit to top
end if
put item 9 of line tLine of tList int tFoundItem
...

Best
Klaus
Re: The fastest to search: list or array ?
Klaus' reply and mine crossed in the email.
He implies that the search is to be made on ordinary, not array, variables, and that the search is very fast. He is right about the speed. Still waiting to see if anyone has searched an array from within that array.
But does all this answer your question? I assume you can use the itemOffset within what Klaus gave you to get this going.
Craig
He implies that the search is to be made on ordinary, not array, variables, and that the search is very fast. He is right about the speed. Still waiting to see if anyone has searched an array from within that array.
But does all this answer your question? I assume you can use the itemOffset within what Klaus gave you to get this going.
Craig
Last edited by dunbarx on Fri Apr 04, 2014 5:50 pm, edited 1 time in total.
Re: The fastest to search: list or array ?
Thanks to all of you for your responses.
Does the lineOffset() in your code, Klaus, use a logarithm research, or does it scan every occurence, step by step (longer!) ?
The first items of each line are all alphabetiques and sorted by ascending order, that's why I care on a logarithm research (faster)...
Does the lineOffset() in your code, Klaus, use a logarithm research, or does it scan every occurence, step by step (longer!) ?
The first items of each line are all alphabetiques and sorted by ascending order, that's why I care on a logarithm research (faster)...
Discovering LiveCode Community 6.5.2.
Re: The fastest to search: list or array ?
Hi.
Do you mean a "binary" search?
Anyway, on a long list, the "lineOffset" is about three times faster than a repeat for each... loop. At least for a list of 25,000 lines with a dozen items in each line (7 mS vs. 20 mS). Both very fast, though. You would not see the difference
Craig
Do you mean a "binary" search?
Anyway, on a long list, the "lineOffset" is about three times faster than a repeat for each... loop. At least for a list of 25,000 lines with a dozen items in each line (7 mS vs. 20 mS). Both very fast, though. You would not see the difference
Craig
Re: The fastest to search: list or array ?
Craig, for sure, I will try the Klaus's proposal as I'm learning LC recently.
All your contributions are very usefull to me.
I could never progress so well without your help at all.
All your contributions are very usefull to me.
I could never progress so well without your help at all.

Discovering LiveCode Community 6.5.2.
Re: The fastest to search: list or array ?
Sorry, i have no idea what is going on in the engineatout66 wrote:Does the lineOffset() in your code, Klaus, use a logarithm research, or does it scan every occurence, step by step (longer!) ?
The first items of each line are all alphabetiques and sorted by ascending order, that's why I care on a logarithm research (faster)...

Re: The fastest to search: list or array ?
Here's a approach using an array, so you can compare timings for techniques.atout66 wrote: Problems:
1 - I want to search a word (as item 1), let say near the line or row 22000.
2 - From that word, I want to get the item or colum number 9.
Code: Select all
local sLineForWord
on setup
repeat for each line tLine in field "myField"
put tLine into sLineForWord[ word 1 of tLine ]
end repeat
end setup
function getItem9ForWord pWord
return item 9 of sLineForWord[ pWord ]
end getItem9ForWord
-- Dick
Re: The fastest to search: list or array ?
OK Dick, no problem.
I'll let you know my experiments when the matrix will be sufficiently large.
For now, I precisely try to develop a system clock that records the time but I'm not really cleaver at it and that's why I'm going to post an other topic right now
I'll let you know my experiments when the matrix will be sufficiently large.
For now, I precisely try to develop a system clock that records the time but I'm not really cleaver at it and that's why I'm going to post an other topic right now

Discovering LiveCode Community 6.5.2.
Re: The fastest to search: list or array ?
Hi atout66 ,
put the millisec into startTime
--do you lineOffset or repeat or ...
answer the millisec - startTime
Simon
put the millisec into startTime
--do you lineOffset or repeat or ...
answer the millisec - startTime
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: The fastest to search: list or array ?
Why don't you use the sqlite included in Livecode?
Database is good when you search data and you need to do it quickly.
Database is good when you search data and you need to do it quickly.

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: The fastest to search: list or array ?
You're right MaxV, I thought about sqlite, but I didn't spend time to learn about it for the moment.
It's an open option to me
It's an open option to me

Discovering LiveCode Community 6.5.2.
Re: The fastest to search: list or array ?
This page cover the essential: http://livecode.wikia.com/wiki/SQLiteatout66 wrote:You're right MaxV, I thought about sqlite, but I didn't spend time to learn about it for the moment.
It's an open option to me
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w