Macros for using the Powerbasic Data-Objects: Queue and Stack

Started by Theo Gottwald, April 24, 2024, 10:08:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

🚀 These powerful basic data objects are designed to be very versatile, which is why they use the slower variant data type.

This means they can be used for numbers as well as strings, but the downside is that they are relatively slow.

The object declaration also requires a lot of typing, but at least you can save some time with the macro below. Overall, I think this type of object data type is too slow for many things and therefore not universally applicable.
It also goes against the Power Basic principle of "smaller faster". 💡
#PowerBasic #DataTypes #Versatility #Efficiency


MACRO Make_Stack(P1) = LOCAL P1 AS ISTACKCOLLECTION:P1 = CLASS "StackCollection"  

' Usage:

LOCAL V01 AS VARIANT
LOCAL T01 AS LONG         

Make_Stack(stack)
stack.Push V01 
T01=stack.COUNT
V01=stack.Pop  


MACRO Make_Que(P1) = LOCAL P1 AS IQUEUECOLLECTION:P1 = CLASS "QueueCollection"  

' Usage:
LOCAL V01 AS VARIANT  
LOCAL T01 AS LONG         

Make_Que(queue)
queue.ENQUEUE V01
T01=queue.COUNT
V01=queue.DEQUEUE