Use a binaryincluded text file

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Use a binaryincluded text file

Post by netmaestro »

Hehe, if I were still trying to solve this one after 8 years I'd seriously consider hanging up my lily pad! FindString was available at the time too but was rejected for speed reasons. If I were doing this today I'd spend 3 minutes making a map and then go watch some funny cats on YouTube. Interestingly enough though, even today I'm having to do something similar. I'm working with LZW compression and I have to look at a lot of strings, do one thing if I've seen a string before and another if I haven't. I'm using a map of course.
BERESHEIT
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Use a binaryincluded text file

Post by davido »

Hi netmaestro,

Are you suggesting that a map is faster than you very neat 'binary chop' or is it just a whole lot more convenient?
DE AA EB
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Use a binaryincluded text file

Post by netmaestro »

Both actually. The binary search I'm using for the dictionary might take an average of 7-10 tests before it finds the searched string, and maybe up to 17. While that's quite fast it can't compete with a map. The map generates a hash for the string and the result is the address of an array element - it just goes right to it with no searching (provided the hash isn't a collision, which will slow it down slightly) Also, the binary search requires that all elements be sorted prior to searching, which makes adding new words slow and tedious as they have to be inserted just where they belong. Not so with a map.

One other consideration is the size of the list. The larger the dataset the greater the speed gain with a map.
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Use a binaryincluded text file

Post by PB »

> Once again, PB has to be correct

I only replied since NM replied the other day. Didn't
mean to annoy or piss you off. And since you said
"once again", I assume I've done it to you in the
past, rsts. If so, I apologize.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Use a binaryincluded text file

Post by davido »

Hi netmaestro,

Thank you, very much, for taking the trouble to explain the difference between the two. :D
DE AA EB
Post Reply