Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::FreeIndexTracker Class Reference

The FreeIndexTracker class tracks which slots from a given range of indices are in use and which are available. More...

#include <qx/core/qx-freeindextracker.h>

Public Member Functions

 FreeIndexTracker (quint64 min=0, quint64 max=1, QSet< quint64 > reserved=QSet< quint64 >())
 
std::optional< quint64 > firstFree () const
 
std::optional< quint64 > firstReserved () const
 
quint64 free () const
 
bool isBooked () const
 
bool isReserved (quint64 index) const
 
std::optional< quint64 > lastFree () const
 
std::optional< quint64 > lastReserved () const
 
quint64 maximum () const
 
quint64 minimum () const
 
std::optional< quint64 > nearestFree (quint64 index) const
 
std::optional< quint64 > nextFree (quint64 index) const
 
std::optional< quint64 > previousFree (quint64 index) const
 
quint64 range () const
 
bool release (quint64 index)
 
bool releaseAll ()
 
bool reserve (quint64 index)
 
bool reserveAll ()
 
quint64 reserved () const
 
std::optional< quint64 > reserveFirstFree ()
 
std::optional< quint64 > reserveLastFree ()
 
std::optional< quint64 > reserveNearestFree (quint64 index)
 
std::optional< quint64 > reserveNextFree (quint64 index)
 
std::optional< quint64 > reservePreviousFree (quint64 index)
 

Detailed Description

The range of an index tracker can be expanded or contracted, and indices within that range can be reserved or released. An example use-case for this class might be tracking which spaces in a parking lot are free.

Constructor & Destructor Documentation

◆ FreeIndexTracker()

Qx::FreeIndexTracker::FreeIndexTracker ( quint64 min = 0,
quint64 max = 1,
QSet< quint64 > reserved = QSet<quint64>() )

Creates an index tracker for the range min to max, with the indices from reserved already reserved.

If any of the values within reserved fall outside the range of min:max, the range of the tracker will automatically be resized to cover them.

Warning
min must be less than max.

Member Function Documentation

◆ firstFree()

std::optional< quint64 > Qx::FreeIndexTracker::firstFree ( ) const

Returns the lowest available index, or std::nullopt if all are reserved.

◆ firstReserved()

std::optional< quint64 > Qx::FreeIndexTracker::firstReserved ( ) const

Returns the lowest index that is currently reserved, or std::nullopt if all are free.

◆ free()

quint64 Qx::FreeIndexTracker::free ( ) const

Returns the number of unoccupied indices.

◆ isBooked()

bool Qx::FreeIndexTracker::isBooked ( ) const

Returns true if all indices are reserved; otherwise, returns false.

◆ isReserved()

bool Qx::FreeIndexTracker::isReserved ( quint64 index) const

Returns true if index is occupied; otherwise returns false.

◆ lastFree()

std::optional< quint64 > Qx::FreeIndexTracker::lastFree ( ) const

Returns the highest available index, or std::nullopt if all are reserved.

◆ lastReserved()

std::optional< quint64 > Qx::FreeIndexTracker::lastReserved ( ) const

Returns the highest index that is currently reserved, or std::nullopt if all are free.

◆ maximum()

quint64 Qx::FreeIndexTracker::maximum ( ) const

Returns the upper bound of the index tracker.

◆ minimum()

quint64 Qx::FreeIndexTracker::minimum ( ) const

Returns the lower bound of the index tracker.

◆ nearestFree()

std::optional< quint64 > Qx::FreeIndexTracker::nearestFree ( quint64 index) const

Returns the nearest free index to index, or std::nullopt if all are reserved.

◆ nextFree()

std::optional< quint64 > Qx::FreeIndexTracker::nextFree ( quint64 index) const

Returns the nearest free index that is at or after index, or std::nullopt if all are reserved.

◆ previousFree()

std::optional< quint64 > Qx::FreeIndexTracker::previousFree ( quint64 index) const

Returns the nearest free index that is at or before index, or std::nullopt if all are reserved.

◆ range()

quint64 Qx::FreeIndexTracker::range ( ) const

Returns the range of indices that the tracker covers.

This function is equivalent to (maximum() - minimum()) + 1.

◆ release()

bool Qx::FreeIndexTracker::release ( quint64 index)

Attempts to mark index as unoccupied and returns true if successful, or false if the index was already free.

◆ releaseAll()

bool Qx::FreeIndexTracker::releaseAll ( )

Attemps to mark all indicies as unoccupied and returns true if successful, or false if all were already free.

◆ reserve()

bool Qx::FreeIndexTracker::reserve ( quint64 index)

Attempts to mark index as occupied and returns true if successful, or false if the index was already reserved.

◆ reserveAll()

bool Qx::FreeIndexTracker::reserveAll ( )

Attemps to mark all indicies as occupied and returns true if successful, or false if all were already reserved.

◆ reserved()

quint64 Qx::FreeIndexTracker::reserved ( ) const

Returns the number of occupied indices.

◆ reserveFirstFree()

std::optional< quint64 > Qx::FreeIndexTracker::reserveFirstFree ( )

Attempts to mark the lowest available index as occupied and return it if successful, or std::nullopt if there are no free indices.

◆ reserveLastFree()

std::optional< quint64 > Qx::FreeIndexTracker::reserveLastFree ( )

Attempts to mark the highest available index as occupied and return it if successful, or std::nullopt if there are no free indices.

◆ reserveNearestFree()

std::optional< quint64 > Qx::FreeIndexTracker::reserveNearestFree ( quint64 index)

Attempts to mark the nearest free index to index as occupied and returns it if successful, or std::nullopt if there are no free indices.

◆ reserveNextFree()

std::optional< quint64 > Qx::FreeIndexTracker::reserveNextFree ( quint64 index)

Attempts to mark the nearest free index that is at or after index as occupied and returns it if successful, or std::nullopt if there are no free indices.

◆ reservePreviousFree()

std::optional< quint64 > Qx::FreeIndexTracker::reservePreviousFree ( quint64 index)

Attempts to mark the nearest free index that is at or before index as occupied and returns it if successful, or std::nullopt if there are no free indices.


The documentation for this class was generated from the following files: