Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-freeindextracker.h
1#ifndef QX_FREEINDEXTRACKER_H
2#define QX_FREEINDEXTRACKER_H
3
4// Standard Library Includes
5#include <concepts>
6
7// Qt Includes
8#include <QSet>
9
10// Intra-component Includes
12
13namespace Qx
14{
15
16class QX_CORE_EXPORT FreeIndexTracker
17{
18//-Instance Members----------------------------------------------------------------------------------------------
19private:
20 // std::vector<bool> Used over QList<bool> since it's is often optimized by std library implementations to use individual bits per element
21 std::vector<bool> mReserved;
22 quint64 mFree;
23 quint64 mMin;
24 quint64 mMax;
25
26//-Constructor---------------------------------------------------------------------------------------------------
27public:
28 FreeIndexTracker(quint64 min = 0, quint64 max = 1, QSet<quint64> reserved = QSet<quint64>());
29
30//-Instance Functions----------------------------------------------------------------------------------------------
31private:
32 quint64 internalIdx(quint64 extIdx) const;
33 quint64 externalIdx(quint64 intIdx) const;
34 bool resrv(quint64 extIdx);
35 bool relse(quint64 extIdx);
36
37public:
38 bool isReserved(quint64 index) const;
39 quint64 minimum() const;
40 quint64 maximum() const;
41 quint64 range() const;
42 quint64 free() const;
43 quint64 reserved() const;
44 bool isBooked() const;
45
46 std::optional<quint64> firstReserved() const;
47 std::optional<quint64> lastReserved() const;
48 std::optional<quint64> firstFree() const;
49 std::optional<quint64> lastFree() const;
50 std::optional<quint64> previousFree(quint64 index) const;
51 std::optional<quint64> nextFree(quint64 index) const;
52 std::optional<quint64> nearestFree(quint64 index) const;
53
54 bool reserve(quint64 index);
55 std::optional<quint64> reserveFirstFree();
56 std::optional<quint64> reserveLastFree();
57 std::optional<quint64> reserveNextFree(quint64 index);
58 std::optional<quint64> reservePreviousFree(quint64 index);
59 std::optional<quint64> reserveNearestFree(quint64 index);
60 bool reserveAll();
61
62 bool release(quint64 index);
63 bool releaseAll();
64};
65
66}
67
68#endif // QX_FREEINDEXTRACKER_H
The FreeIndexTracker class tracks which slots from a given range of indices are in use and which are ...
Definition qx-freeindextracker.h:17
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
The qx-algorithm header file provides various mathematical/algorithmic functions.