Queue 1.1 - library
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
Queue 1.1 - library
[edit]
I updated to version 1.1:
+ fixed a string-memory-hole during clean-up and dequeue/delete (strings are set to "" now)
+ added Queue_DequeueToString() - I just forgot it before. Similar to Queue_GetValToString()
(Returns a formatted string containing information on the active element of any type)
+ Change Queue Dequeue*()'s behaviour of setting the active element. It keeps now the active element
or resets the queue if it was the (previous) head. So you might mix up Queue_Next() with Queue_Dequeue()
without running into trouble.
+ added Queue_SetVal*() - functions to assign a new value of any type to the active element. (Just for
your convenience - you might further use the (faster) syntax e.g.:
*myVar.Variant_PB = Queue_GetActElement() : *myVar\l = 1234 : *myVar\type = #Long
+ added some more examples
+ added #Queue_GetResVersion = 1.1 to check against Queue_VersionInfo()
[/edit]
Hi!
I just finished the Queue-library.
These procedures give you all you need to handle dynamic data. You can use just the 'pure' queue-functionality (enqueue/dequeue) or the 'active element'-browsing for functionality same as lists. Further you can insert and delete elements anywhere inside this queue.
As elements you might use byte/word/long/float/string-values, or structures.
You can arbitrary mix them inside a queue.
You might have a look here (library and source):
http://www.2mal2mal.de/public/purebasic/libs
(Browse for the files in the subdirectory or download the self-named zip)
I updated to version 1.1:
+ fixed a string-memory-hole during clean-up and dequeue/delete (strings are set to "" now)
+ added Queue_DequeueToString() - I just forgot it before. Similar to Queue_GetValToString()
(Returns a formatted string containing information on the active element of any type)
+ Change Queue Dequeue*()'s behaviour of setting the active element. It keeps now the active element
or resets the queue if it was the (previous) head. So you might mix up Queue_Next() with Queue_Dequeue()
without running into trouble.
+ added Queue_SetVal*() - functions to assign a new value of any type to the active element. (Just for
your convenience - you might further use the (faster) syntax e.g.:
*myVar.Variant_PB = Queue_GetActElement() : *myVar\l = 1234 : *myVar\type = #Long
+ added some more examples
+ added #Queue_GetResVersion = 1.1 to check against Queue_VersionInfo()
[/edit]
Hi!
I just finished the Queue-library.
These procedures give you all you need to handle dynamic data. You can use just the 'pure' queue-functionality (enqueue/dequeue) or the 'active element'-browsing for functionality same as lists. Further you can insert and delete elements anywhere inside this queue.
As elements you might use byte/word/long/float/string-values, or structures.
You can arbitrary mix them inside a queue.
You might have a look here (library and source):
http://www.2mal2mal.de/public/purebasic/libs
(Browse for the files in the subdirectory or download the self-named zip)
Last edited by Froggerprogger on Mon Jul 12, 2004 7:49 pm, edited 1 time in total.
%1>>1+1*1/1-1!1|1&1<<$1=1
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: Queue 1.0 - library
two words: freakin sweet
Nice work!
- np
Unless you're already making one.. I can make a linked chm file for you.
Just send me ALL the functions in a text file..
*EDIT*
One question:
What am I doing wrong? Queue_Next seems to work ok in your example.
But for me, it's not letting me grab the last element, unless I remove that
;comment..?
- np
Nice work!
- np
Code: Select all
q = Queue_Create()
Queue_EnqueueS(q, "1")
Queue_EnqueueS(q, "2")
Queue_EnqueueS(q, "3")
Queue_EnqueueS(q, "4")
Queue_EnqueueS(q, "5")
Queue_EnqueueS(q, "6")
Debug Str(Queue_GetNumElems(q)) + " elements left in queue" ; there are no more elements in queue
Debug Queue_DequeueS(q)
Debug Queue_DequeueS(q)
Debug Queue_DequeueS(q)
Debug Queue_DequeueS(q)
Debug Queue_DequeueS(q)
Debug Queue_DequeueS(q)
Debug Str(Queue_GetNumElems(q)) + " elements left in queue" ; there are no more elements in queue
Just send me ALL the functions in a text file..
*EDIT*
One question:
Code: Select all
q = Queue_Create()
Queue_EnqueueS(q, "apples")
Queue_EnqueueS(q, "oranges")
Queue_EnqueueS(q, "pears")
Queue_EnqueueS(q, "bananas")
Queue_EnqueueS(q, "grapes")
Queue_EnqueueS(q, "peaches")
Debug Str(Queue_GetNumElems(q)) + " elements left in queue" ; there are no more elements in queue
Queue_Reset(q)
While Queue_Next(q)
Debug Queue_DequeueS(q)
Wend
; Debug Queue_DequeueS(q)
Queue_Destroy(q, 0)
But for me, it's not letting me grab the last element, unless I remove that
;comment..?
- np
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: Queue 1.0 - library
Queue_Sort() - for strings..
Had a little burst of energy this morning... thought I'd tool with your lib.
- np
Had a little burst of energy this morning... thought I'd tool with your lib.
Code: Select all
q = Queue_Create()
Queue_EnqueueS(q, "apples")
Queue_EnqueueS(q, "oranges")
Queue_EnqueueS(q, "pears")
Queue_EnqueueS(q, "bananas")
Queue_EnqueueS(q, "grapes")
Queue_EnqueueS(q, "peaches")
Procedure Queue_Sort(queue)
l = Queue_GetNumElems(queue)-1:Dim temp.s(l):Queue_Reset(queue)
x = 0:While Queue_Next(queue):temp(x) = Queue_DequeueS(queue):x+1:Wend
temp(x) = Queue_DequeueS(queue):SortArray(temp(), 0, 0, l)
Queue_Clear(queue, 0):Queue_Reset(queue)
For xx = 0 To l:Queue_EnqueueS(queue, temp(xx)):Next xx
Dim temp.s(0);release the array
EndProcedure
Queue_Sort(q)
; list the queue
Queue_Reset(q)
While Queue_Next(q)
Debug Queue_DequeueS(q)
Wend
Debug Queue_DequeueS(q) ; still have to shoot last one out like this
Queue_Destroy(q, 0)
End
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
A help. chm would be pretty cool. Inside the package there's the Queue.pb containing all functions. Behind each of them there's a comment describing in short words exactly what this function does and what values are expected for the parameters.Unless you're already making one.. I can make a linked chm file for you.
Just send me ALL the functions in a text file..
Don't use Queue_Next() with Queue_Dequeue(). Otherwise you are mixing the both concepts. I'll try to explain:What am I doing wrong? Queue_Next seems to work ok in your example.
This queue includes two different concepts:
1. pure queue
2. list
One difference is, that a pure queue doesn't have any 'active element' like a list. In a list you can reset and go to next / previous element and read the value at the active element (+insert/delete).
In a pure queue you can only enqueue and dequeue (+insert/delete).
Dequeue means, that the head element will be deleted, totally independant of the active element.
So if you want do 'dequeue' all elements, you can do this e.g. by
Code: Select all
While Queue_GetNumElems(q) ; check if there are still elements in queue
Debug Queue_DequeueS(q) ; dequeue the head
Wend
Code: Select all
*p.queue = Queue_Create()
Queue_EnqueueS(*p, "TEST1")
Queue_EnqueueS(*p, "TEST2")
Queue_EnqueueS(*p, "TEST3")
While *p\numElems ; check if there are still elements in queue
Debug Queue_DequeueS(*p) ; dequeue the head
Wend
Code: Select all
While Queue_SelectHead(q) ; returns pointer to headelem or 0, so check if there is still a head object
Debug Queue_DequeueS(q) ; dequeue it
Wend
This is how to handle the pure queue-part.
The Reset/Next/Prev/Select - functions let this queue behave like a list. You can navigate through the files and read or write their values.
So you can get all values by:
Code: Select all
Queue_Reset(q)
While Queue_Next(q)
Debug Queue_GetValS(q)
Wend
Or e.g. by:
Code: Select all
Queue_Reset(q)
Repeat
*r.Variant_PB = Queue_Next(q)
If *r
debug *r\s
Endif
Until *r = 0
Code: Select all
Queue_Reset(q)
While Queue_Next(q)
Debug Queue_GetValS(q)
Wend
While Queue_Prev(q)
Debug Queue_GetValS(q)
Wend
Of course it would be nice, when Queue_Next() would work with Queue_Dequeue(), but unfortunately it doesn't.
((
Here the reason:
Queue_Reset() sets active element in front of head.
Queue_Next() sets now the head as the active element
Queue_Dequeue() removes the head and sets it the active element.
|| :
Queue_Next() sets now the head's fellow as active one
Queue_Dequeue() removes the head and sets it the active element.
: ||
After some loops Queue_Next() sets the active element to 0, though there is still one element in queue.
))
Yes, a good idea ! But it would only work if all elements have the same type. A user callback-sort would be quite good for this. Then you could sort structures, too, and you might compare bytes/words/longs/floats with each other.Queue_Sort() - for strings..
Another thing that I noticed is, there's no
Queue_DequeueToString() at the moment, though there is a Queue_GetValToString(). This is a pretty useful command for mixed-type-queues.
I'll catch up this.
Further I could implement Queue_SetVal*() - functions. Atm you can only overwrite values using the Variant_PB-structure.
These are some things for the ToDo-list.
(But not today - I have to take a shower an' go to a bash now

Last edited by Froggerprogger on Sat Jul 10, 2004 7:10 pm, edited 1 time in total.
%1>>1+1*1/1-1!1|1&1<<$1=1
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
..
Nah.. that's what linked lists are for..Frogman wrote:Of course it would be nice, when Queue_Next() would work with Queue_Dequeue(), but unfortunately it doesn't.

less typing for us..

Enjoy the bash!
- np
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
While thniking about the Next/Dequeue - thing a bit longer I had the following idea:
Queue_Dequeue() needn't have to change the active element (which is part of the other concept) to the new head.
It was just an design-idea, so that you can use convenient Queue_GetVal*() immediately after Queue_Dequeue() on the new head.
As an alternative Queue_Dequeue() could reset the list always. Thenwould work. But it's not soo fine I think.
It would be better to leave the active element as it is, so long it makes sense, so here's the idea :
Queue_Dequeue() should leave the active element as it is. (e.g. if element ID 5 is active, after Dequeue() the active element will be still the same, (but on ID 4). This makes sense.
And when the active element was the head itself (which will be removed by Dequeue()) then the list will be resetted, so the active element is 0 !
-> The combination of Next / Dequeue would work then.
Thanks for this hint, I'll change it tomorrow !
... & so forget about some parts of my above blahblah
Queue_Dequeue() needn't have to change the active element (which is part of the other concept) to the new head.
It was just an design-idea, so that you can use convenient Queue_GetVal*() immediately after Queue_Dequeue() on the new head.
As an alternative Queue_Dequeue() could reset the list always. Then
Code: Select all
While Queue_Next()
Queue_Dequeue*()
Wend
It would be better to leave the active element as it is, so long it makes sense, so here's the idea :
Queue_Dequeue() should leave the active element as it is. (e.g. if element ID 5 is active, after Dequeue() the active element will be still the same, (but on ID 4). This makes sense.
And when the active element was the head itself (which will be removed by Dequeue()) then the list will be resetted, so the active element is 0 !
-> The combination of Next / Dequeue would work then.
Thanks for this hint, I'll change it tomorrow !
... & so forget about some parts of my above blahblah

%1>>1+1*1/1-1!1|1&1<<$1=1
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
..
Getting now..Froggerprogger wrote:OK - tomorrow was yesterday, but today I made the update.
- np