Not a bug, but lists are nearly useless because of speed

Just starting out? Need help? Post your questions and find answers here.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@Trond
why should i write a loop when i can use SelectElement(), which will do the same?! like fred said, its a convenience function. the only problem is, that it doesnt search position dependant, thats all.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

nco2k wrote:@Trond
why should i write a loop when i can use SelectElement(), which will do the same?! like fred said, its a convenience function. the only problem is, that it doesnt search position dependant, thats all.

c ya,
nco2k
I don't understand you. You're NOT SUPPOSED TO EVER index a list item by its position. That's the point of lists, they are position independent, so that items can be added and deleted in the middle of the list.
-> If you need to store a reference to a specific item it is nonsense to use the number, since it will change. Instead use the address of the element and ChangeCurrentElement().
-> If you don't need to store a reference to specific item you don't need SelectElement() at all.
Where's the problem? The problem is that a perfectly sensible and fast function exists and does what is needed, but people prefer to not use it and instead use a function that is totally unsuitable for the task. How that can be fixed I don't know.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

@nco2k

I discover your really good code.
But I don't understand what's happening when I replace 'DisableDebugger' with 'EnableDebugger'.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

nco2k: I agree that an optimised position dependant version would work best.

The current position would only be invalid if there has been a clear list, select element, or an insert item or delete item before the current position. Even then it could easily be updated to take this into account.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I implemented an improved version that takes the current position into account
Can you guys test it to see if it works as expected ? http://freak.purearea.net/v4/LinkedList

As Trond and others noted though, if speed is important then Lists + SelectElement() are the wrong solution.
The improvement increased the speed for random access by a constant factor only (about 3x faster on average),
it does in no way reduce the complexity of the underlying algorithmic problem.
So if you really want speed (especially for large numbers of elements), use an array.
quidquid Latine dictum sit altum videtur
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I've just tested it with ReportBuilder, seems to work without problems. :)

Is there a list of all the slight beta updates anywhere (rather than searching the forums)?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

freak wrote:I implemented an improved version that takes the current position into account
Can you guys test it to see if it works as expected ? http://freak.purearea.net/v4/LinkedList

As Trond and others noted though, if speed is important then Lists + SelectElement() are the wrong solution.
The improvement increased the speed for random access by a constant factor only (about 3x faster on average),
it does in no way reduce the complexity of the underlying algorithmic problem.
So if you really want speed (especially for large numbers of elements), use an array.
Is there an extension we can apply to that url? It just opens in my browser as text and gibberish. What kind of file is it?

cheers
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

rightclick the link and "save target as", you'll probably have to remove a .txt extension when it lands on your drive. Put it in the \PureBasic\Libraries folder and restart the compiler, should be good to go.
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Thanks, netmaestro.

I had already saved it (with a txt extension), so I'm halfway there :)

cheers

edit.
Haven't tested it for speed, but my linked list functions seem to work just fine.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

:idea: SQLite has an option to create an in-memory database which runs very fast (for a database). I wonder how it stacks up in this case. :?:

http://www.purebasic.fr/english/viewtop ... ght=sqlite

It may be a little slower to load but I suspect a lot faster to read from and as a big bonus, you get all the power and features of SQL commands so your sorting and searching of subsets would be great.

Not sure if it would help you with what you are doing but it might be worth a try

...just a thought
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@freak
thanks for adding this one. i did a short speed test and its extremly fast now! :shock:

no bugs found so far... great work! :wink:

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply