Home » U++ Library support » U++ Core » simple queue form Array(Vector...)
simple queue form Array(Vector...) [message #3547] |
Thu, 01 June 2006 11:00 |
qwerty
Messages: 130 Registered: May 2006
|
Experienced Member |
|
|
some simple way(other than fundametnally Array && few C++ code:)) to set the size of array and if size of Array reach specified size_value, the first element will disapperar to keep size latest recently values in :> ???
|
|
|
Re: simple queue form Array(Vector...) [message #3553 is a reply to message #3547] |
Thu, 01 June 2006 14:03 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
qwerty: what you are looking for is some sort of FIFO queue, which is not directly part of U++ core (AFAIK).
(well, actually the BiVector *IS* FIFO queue, but it lacks some auto-size guard, etc.. i.e. some higher logic of some queue, but there's no point to add such logic into basic container class IMHO).
What's wrong with BiVector and few lines of C++ code?
As the AddHead(const T& x) and AddTail(const T& x) and few others are not virtual, you can't simply derive new BiVector class and add automatic guard of number of elements with "AutoDrop" feature, yet I think the classic "few C++ code" solution is a good choice here.
BiVector<element> myQueue;
int myQueueMaxLength = 40;
void AddAndKeepSize(const element & el) {
while ( myQueue.GetCount() >= myQueueMaxLength )
myQueue.DropHead();
myQueue.AddTail(el);
}
//to add new element use:
AddAndKeepSize(element);
That's basically it. It would be nice to embed it into some class ... depends where and how you need it and how much you dislike globals + globals functions outside of any class.
[Updated on: Thu, 01 June 2006 14:04] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat Sep 21 03:27:24 CEST 2024
Total time taken to generate the page: 0.02921 seconds
|