Map & Prioritary queue

BlitzMax Forums/BlitzMax Programming/Map & Prioritary queue

Paposo(Posted 2006) [#1]
Gello guys.
Sorry my bad english.
I offer free modules for your use.
This are implementations of Maps and prioritary queues baseds on a tree red-black. Same implementation used by java for the trees.

Base code for tree manegement



Code for Map



Code for Prioritary queue:



Please, if you enconter any bug comment this.

Bye,
Paposo


Dreamora(Posted 2006) [#2]
Isn't a priority queue basing on a self restructuring tree a little over the top? (thinking that heap delivers the same runtime without the need of averaging it and with far less overhead due to simple array implementation)

Oh and just to mention: brl.map is red-black based ... Where is the actual use of yours? (not that I have anything against new datastructures, they are always welcome :) )


Paposo(Posted 2006) [#3]
Hello Dremora.
The tree is used for for simple ordering the prioritys. In each node use a LinkedList. This is very eficient, the search for next priority is O(log(n) ) eficient and the extraction for linkedList is O(k) constant eficiency for use only the last and the first elements.
If you use a big number of elements the implementation look very eficient.
The method setPrioridad() not is O(log(n)) eficient. It search object in linked list.
I use the priority queue for painting the sprites in my prefered order. I not use desencolar. i use and enumerator and if ne sprite is moved to front i use setPrioridad() for repriorice it. This is very fast that sort entire queue.

Ahhh! brl.map is not balanced. not is one good implementation of red-black three. Test it! Use a set of preordered keys in brl.map. The eficiency is O(n). Very, very bad. Use the same set in TTreeMap. Get times and compare. 20000 elements need 200 millisec in Ttreemap and 40000 millisec in brl.map

The brl.map is only eficient with random ordered keys.

Bye,
paposo


Dreamora(Posted 2006) [#4]
Erm brl.map got an update a few days ago after the new implementation was posted on the Module Tweaks board 3 weeks ago by mark. So sadly, it is balanced now :-)

But you are right, the old implementation was quite critical, as ordered data ended with a linear linked list which made it pointless.


On PriorityQueue: With stack you could do everything on O(log(n)) base.
If you were a little freaky, even O(log(log(n))) is possible ... but I would never try to implement a Fibonacci Heap once again
And without a really large amount of objects, O(log(n)) isn't really slower than O(log(log(n))) as the whole relinking etc takes time as well that is not counted in O() time


Paposo(Posted 2006) [#5]
Thanks Dreamora.

I updated de brl mods and look at TMap. Very well. This is a good implementation.

I look for your technic in priorityQueue. Thanks

Bye,
Paposo