|
Zero
0.1.0
|
Multiple Clocks with a Common Set of Entries. More...
#include <multi_clock.hpp>
Classes | |
| class | IndexPair |
| Pair of keys. More... | |
Public Member Functions | |
| MultiHandedClock (key_type entryCount) | |
| Constructor of Multiple Clocks with a Common Set of Entries. More... | |
| ~MultiHandedClock () | |
| Destructor of Multiple Clocks with a Common Set of Entries. More... | |
| template<ClockIndex clock> | |
| void | getHead (value_type &head) const |
| Get the value of the entry where the clock hand of the specified clock points to. More... | |
| template<ClockIndex clock> | |
| void | setHead (const value_type newValue) |
| Set the value of the entry where the clock hand of the specified clock points to. More... | |
| template<ClockIndex clock> | |
| void | getHeadIndex (key_type &headIndex) const |
| Get the index of the entry where the clock hand of the specified clock points to. More... | |
| template<ClockIndex clock> | |
| void | moveHead () |
| Move the clock hand forward. More... | |
| template<ClockIndex clock> | |
| void | addTail (const key_type &index) |
| Make the specified index the__ZERO_MULTICLOCK_HPP tail of the specified clock. More... | |
| template<ClockIndex clock> | |
| void | addTail (key_type &&index) |
| Make the specified index the tail of the specified clock (with move semantics) More... | |
| void | addBefore (const key_type &inside, const key_type &newEntry) |
| Add the specified index before another index in an arbitrary clock. More... | |
| void | addBefore (const key_type &inside, key_type &&newEntry) |
| Add the specified index before another index in an arbitrary clock (with move semantics) More... | |
| void | addAfter (const key_type &inside, const key_type &newEntry) |
| Add the specified index after another index in an arbitrary clock. More... | |
| void | addAfter (const key_type &inside, const key_type &&newEntry) |
| Add the specified index after another index in an arbitrary clock (with move semantics) More... | |
| template<ClockIndex clock> | |
| void | removeHead (key_type &removedIndex) |
| Remove the head entry from the specified clock. More... | |
| void | remove (const key_type &index) |
| Remove the specified entry from any clock. More... | |
| template<ClockIndex source, ClockIndex destination> | |
| void | switchHeadToTail (key_type &movedIndex) |
| Moves an entry from the head of one clock to the tail of another one. More... | |
| template<ClockIndex clock> | |
| key_type | sizeOf () const noexcept |
| Returns the number of entries in the specified clock. More... | |
| template<ClockIndex clock> | |
| bool | isEmpty () const noexcept |
Returns true if the specified clock is empty. More... | |
| bool | isValidIndex (const key_type &index) const noexcept |
Returns true if the specified index is valid. More... | |
| bool | isContainedIndex (const key_type &index) const noexcept |
Returns true if the specified index is contained in any clock. More... | |
| value_type & | get (const key_type &index) noexcept |
| Returns a reference to the value that corresponds to the specified index. More... | |
| const value_type & | get (const key_type &index) const noexcept |
| Returns a reference to the value that corresponds to the specified index. noexcept More... | |
| void | set (const key_type &index, const value_type &newValue) noexcept |
| Sets the value that corresponds to the specified index. More... | |
| void | set (const key_type &index, value_type &&newValue) noexcept |
| Sets the value that corresponds to the specified index (with move semantics) More... | |
| value_type & | operator[] (const key_type &index) noexcept |
| Returns a reference to the value that corresponds to the specified index. More... | |
| const value_type & | operator[] (const key_type &index) const noexcept |
| Returns a reference to the value that corresponds to the specified index. noexcept More... | |
| ClockIndex & | getClockIndex (const key_type &index) noexcept |
| Returns a reference to the index of the clock where the specified index is contained in. More... | |
| const ClockIndex & | getClockIndex (const key_type &index) const noexcept |
| Returns a reference to the index of the clock where the specified index is contained in. noexcept More... | |
Private Attributes | |
| key_type | _entryCount |
| Number of entries the clocks can hold. More... | |
| std::vector< value_type > | _values |
| Values. More... | |
| std::vector< IndexPair > | _clocks |
| Clocks. More... | |
| std::vector< ClockIndex > | _clockMembership |
| Membership of indexes to clocks. More... | |
| std::array< key_type, clock_count > | _hands |
| Clock hands. More... | |
| std::array< key_type, clock_count > | _sizes |
| Number of elements in the clocks. More... | |
Multiple Clocks with a Common Set of Entries.
Represents multiple clocks of key-value pairs using one common set of entries. The total size of the clocks (number of key-value pairs) is fixed but the sizes of the different clocks are variable and limiting those is not supported. The keys are stored implicitly as array indices for the values and therefore it works best when the domain of the keys is very limited. Each clock has an index (starting from 0) which is required when working with it. It is possible to add an entry at the tail of a clock and to remove one from its head. It is also possible to get the key or get/set the value of the entry where the clock hand of a clock points to. In addition to the typical interface of a single clock, it is possible to swap one entry from one clock's head to another clock's tail.
The computational complexity of the methods of this class is in \(\mathcal{O}\left(1\right)\) and the space complexity of this class is in \(\mathcal{O}\left(n\right)\) regarding the key range.
| key_type | The data type of the key of the key-value pairs where each key is unique within one instance of this data structure. |
| value_type | The data type of the value of the key-value pairs where each value instance corresponds to a key. |
| clock_count | Contains the total number of clocks contained in this MultiHandedClock and therefore it specifies the highest valid ClockIndex, the number of clock _hands etc. The actual number of clocks might be smaller as some clocks can be empty. |
| invalid_index | This specifies an invalid key which can be used to mark that a clock is empty and therefore the clock hand points to this value. This should have the semantics of null for the specified key template parameter therefore a natural choice of this for the case that key is a pointer would be nullptr. |
| invalid_clock_index | This specifies an invalid clock index which can be used to mark inside _clockMembership that an index does not belong to any clock. This should have the semantics of null for ClockIndex and is equal to clock_count (greatest clock index plus 1). |
|
inline |
Constructor of Multiple Clocks with a Common Set of Entries.
Constructs a new MultiHandedClock with a specified combined capacity of the clocks and a number of (initially empty) clocks specified in the template parameter clock_count . This constructor allocates the memory to store _entryCount entries.
| entryCount | The range of the clock indexes and the combined size of the clocks. |
|
inline |
Destructor of Multiple Clocks with a Common Set of Entries.
Destructs this instance of MultiHandedClock and deallocates the memory used to store the clocks.
|
inline |
Add the specified index after another index in an arbitrary clock.
Adds a new entry with the specified index newEntry in the clock after the entry inside. The entry that was after inside before will be IndexPair._after newEntry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| inside | This index will be the entry before the new entry. |
| newEntry | This is the index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified newEntry or inside is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified newEntry could not be added because it is already contained in some clock. |
| MultiHandedClockNotContainedException | If the position for the insertion is not valid because the specified inside is not contained in any clock. |
|
inline |
Add the specified index after another index in an arbitrary clock (with move semantics)
Adds a new entry with the specified index newEntry in the clock after the entry inside using move semantics. The entry that was after inside before will be IndexPair._after newEntry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| inside | This index will be the entry before the new entry. |
| newEntry | This is the index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified newEntry or inside is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified newEntry could not be added because it is already contained in some clock. |
| MultiHandedClockNotContainedException | If the position for the insertion is not valid because the specified inside is not contained in any clock. |
|
inline |
Add the specified index before another index in an arbitrary clock.
Adds a new entry with the specified index newEntry in the clock before the entry inside. The entry that was before inside before will be IndexPair._before newEntry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| inside | This index will be the entry after the new entry. |
| newEntry | This is the index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified newEntry or inside is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified newEntry could not be added because it is already contained in some clock. |
| MultiHandedClockNotContainedException | If the position for the insertion is not valid because the specified inside is not contained in any clock. |
|
inline |
Add the specified index before another index in an arbitrary clock (with move semantics)
Adds a new entry with the specified index newEntry in the clock before the entry inside using move semantics. The entry that was before inside before will be IndexPair._before newEntry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| inside | This index will be the entry after the new entry. |
| newEntry | This is the index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified newEntry or inside is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified newEntry could not be added because it is already contained in some clock. |
| MultiHandedClockNotContainedException | If the position for the insertion is not valid because the specified inside is not contained in any clock. |
|
inline |
Make the specified index the__ZERO_MULTICLOCK_HPP tail of the specified clock.
Adds a new entry with the specified index to the tail of the specified clock. The new entry will be the tail of the clock and the previous tail entry will be IndexPair._before the new entry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| clock | The clock where the new entry should be added to at the tail. |
| index | The index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified index is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified index could not be added because it is already contained in some clock. |
|
inline |
Make the specified index the tail of the specified clock (with move semantics)
Adds a new entry with the specified index to the tail of the specified clock using move semantics. The new entry will be the tail of the clock and the previous tail entry will be IndexPair._before the new entry. Adding a new entry is only possible if the index is not already contained inside any clock of the same MultiHandedClock.
| clock | The clock where the new entry should be added to at the tail. |
| index | The index of the new entry. |
| MultiHandedClockInvalidIndexException | If the specified index is invalid. |
| MultiHandedClockAlreadyContainedException | If the specified index could not be added because it is already contained in some clock. |
|
inlinenoexcept |
Returns a reference to the value that corresponds to the specified index.
Returns a reference to the value that corresponds to the specified index, independent of the membership of that index to any clock.
| index | The index whose value gets returned. |
invalid_index else.
|
inlinenoexcept |
Returns a reference to the value that corresponds to the specified index. noexcept
Returns a reference to the value that corresponds to the specified index, independent of the membership of that index to any clock.
| index | The index whose value gets returned. |
invalid_index else. noexcept
|
inlinenoexcept |
Returns a reference to the index of the clock where the specified index is contained in.
Returns a reference to the index of the clock where the specified index is contained in or template parameter invalid_clock_index of the specified index is invalid or not contained in any clock.
| index | The index whose clock index gets returned. |
invalid_clock_index of the index is invalid in this MultiHandedClock or if it is not contained in any clock.
|
inlinenoexcept |
Returns a reference to the index of the clock where the specified index is contained in. noexcept
Returns a reference to the index of the clock where the specified index is contained in or template parameter invalid_clock_index of the specified index is invalid or not contained in any clock.
| index | The index whose clock index gets returned. |
invalid_clock_index of the index is invalid in this MultiHandedClock or if it is not contained in any clock. noexcept
|
inline |
Get the value of the entry where the clock hand of the specified clock points to.
Returns the value of the head of the specified clock.
| clock | The clock whose head's value should be returned. |
| [out] | head | The value of the head of the specified clock. |
| MultiHandedClockEmptyException | If the specified clock is empty. |
|
inline |
Get the index of the entry where the clock hand of the specified clock points to.
Returns the index of the head of the specified clock.
| clock | The clock whose head should be returned. |
| [out] | headIndex | The index of the head of the specified clock. |
| MultiHandedClockEmptyException | If the specified clock is empty. |
|
inlinenoexcept |
Returns true if the specified index is contained in any clock.
Returns true if the specified index is valid in this MultiHandedClock and if it is contained in any clock within this MultiHandedClock.
| index | The index whose clock membership is checked. |
true if the specified index is contained in any clock.
|
inlinenoexcept |
Returns true if the specified clock is empty.
Returns true if the specified clock currently contains entries.
| clock | The clock whose emptiness gets returned. |
true if the specified clock contains entries, false else.
|
inlinenoexcept |
Returns true if the specified index is valid.
Returns true if the specified index is valid in this MultiHandedClock.
| index | The index whose validity is checked. |
true if the specified index is valid.
|
inline |
Move the clock hand forward.
Moves the tail entry of the specified clock before the head of the same clock. Therefore the previous tail entry becomes the new head entry. The previous head will become the element IndexPair._before the new head and the new tail will be the element IndexPair._after the new head.
| clock | The clock whose clock hand should be moved. |
| MultiHandedClockEmptyException | If the specified clock is empty. |
|
inlinenoexcept |
Returns a reference to the value that corresponds to the specified index.
Returns a reference to the value that corresponds to the specified index, independent of the membership of that index to any clock.
| index | The index whose value gets returned. |
invalid_index , else.
|
inlinenoexcept |
Returns a reference to the value that corresponds to the specified index. noexcept
Returns a reference to the value that corresponds to the specified index, independent of the membership of that index to any clock.
| index | The index whose value gets returned. |
invalid_index , else. noexcept
|
inline |
Remove the specified entry from any clock.
Removed the specified entry from any clock. The entry before this entry will be before the entry after the specified entry and the entry after this entry will be after the entry before the specified entry.
| index | The index of the entry that gets removed. |
| MultiHandedClockInvalidIndexException | If the specified index is invalid (and therefore also not contained in any clock). |
| MultiHandedClockNotContainedException | If the specified index could not be removed from some clock because it is not contained in one. |
|
inline |
Remove the head entry from the specified clock.
Removes the entry at the head of the specified clock from that clock. The new head of the clock will be the entry after the removed entry and therefore the clock hand will point to that index.
| clock | The index of the clock whose head entry will be removed. |
| [out] | removedKey | The index of the entry that was removed. |
| MultiHandedClockEmptyException | If the specified clock is empty. |
|
inlinenoexcept |
Sets the value that corresponds to the specified index.
Sets the value that corresponds to the specified index, independent of the membership of that index to any clock.
| index | The index whose value gets set. |
| newValue | The new value for the specified index if this index is valid inside this MultiHandedClock or for the template parameter invalid_index , else. |
|
inlinenoexcept |
Sets the value that corresponds to the specified index (with move semantics)
Sets the value that corresponds to the specified index using move semantics, independent of the membership of that index to any clock.
| index | The index whose value gets set. |
| newValue | The new value for the specified index if this index is valid inside this MultiHandedClock or for the template parameter invalid_index , else. |
|
inline |
Set the value of the entry where the clock hand of the specified clock points to.
Sets the value of the head of the specified clock to the specified value.
| clock | The clock whose head's value should be set. |
| newValue | The new value of the head of the specified clock. |
| MultiHandedClockEmptyException | If the specified clock is empty. |
|
inlinenoexcept |
Returns the number of entries in the specified clock.
Returns the number of entries that is currently contained in the specified clock.
| clock | The clock whose current size gets returned. |
clock .
|
inline |
Moves an entry from the head of one clock to the tail of another one.
Removes the index at the head of the source clock and adds it as tail of the destination clock.
| source | The index of the clock whose head gets moved. The head will be removed from this clock. |
| destination | The index of the clock where the moved entry gets added to the tail. |
| [out] | movedIndex | The index of the entry that was moved from one clock to another. |
| MultiHandedClockEmptyException | If the head of the specified source could not be taken because the clock is empty. |
|
private |
Membership of indexes to clocks.
This array specifies for each index in the domain to which clock it belongs. If an index is not part of a clock, the template parameter invalid_clock_index is used.
|
private |
Clocks.
Contains the doubly linked, circular lists representing the clocks (every not empty clock is contained in here). The IndexPair stored at index i contains the indexes within the same clock after i and before i .
|
private |
Number of entries the clocks can hold.
Contains the number of key-value pairs that can be stored in the clocks combined. When this MultiHandedClock is initialized, it allocates memory to hold this many entries. This also specifies the highest key that is allowed in the clocks (_entryCount - 1 ).
|
private |
Clock hands.
Contains the clock hands of the clocks. Therefore it contains the index of each clock's head. If a clock is empty, this contains the template parameter invalid_index .
|
private |
Number of elements in the clocks.
Contains for each clock the number of elements this clock currently has.
|
private |
Values.
Holds the values corresponding the keys. The corresponding key is the index of this array.
1.8.12