shared: Add LimitQueue which discards oldest entry once limit hit
Dieser Commit ist enthalten in:
Ursprung
00abc6bc1b
Commit
ad06497b4b
48
shared/limitqueue.h
Normale Datei
48
shared/limitqueue.h
Normale Datei
@ -0,0 +1,48 @@
|
||||
#ifndef LIMITQUEUE_H
|
||||
#define LIMITQUEUE_H
|
||||
#include <QQueue>
|
||||
|
||||
template <class T> class LimitQueue
|
||||
{
|
||||
protected:
|
||||
QQueue<T> queue;
|
||||
unsigned int limit = 0;
|
||||
|
||||
public:
|
||||
LimitQueue();
|
||||
LimitQueue(unsigned int limit)
|
||||
{
|
||||
this->limit = limit;
|
||||
}
|
||||
|
||||
void enqueue(const T &t)
|
||||
{
|
||||
if(queue.size() == limit)
|
||||
{
|
||||
queue.dequeue();
|
||||
}
|
||||
queue.enqueue(t);
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
return queue.size();
|
||||
}
|
||||
|
||||
T dequeue()
|
||||
{
|
||||
return queue.dequeue();
|
||||
}
|
||||
|
||||
void setLimit(unsigned int limit)
|
||||
{
|
||||
this->limit = limit;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
queue.clear();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // LIMITQUEUE_H
|
@ -77,6 +77,7 @@ HEADERS += sqlitesearch.h \
|
||||
filescanworker.h \
|
||||
indexer.h \
|
||||
indexsyncer.h \
|
||||
limitqueue.h \
|
||||
logger.h \
|
||||
looqsgeneralexception.h \
|
||||
looqsquery.h \
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren