6 #ifndef ACE_TIME_LINK_REGISTRAR_H
7 #define ACE_TIME_LINK_REGISTRAR_H
10 #include <AceCommon.h>
11 #include "../common/compat.h"
12 #include "LinkEntry.h"
16 class LinkRegistrarTest_isSorted;
29 template<
typename LE,
typename LEB,
typename LRGB>
38 const LE* linkRegistry
42 mLinkRegistry(linkRegistry)
50 return (mLinkRegistry && i < mLinkRegistrySize)
51 ? LRGB(mLinkRegistry).linkEntry(i)
57 if (mLinkRegistrySize == 0 || mLinkRegistry ==
nullptr) {
62 return LRGB(mLinkRegistry).linkEntry(index);
75 friend class ::LinkRegistrarTest_isSorted;
81 static bool isSorted(
const LE* registry, uint16_t registrySize) {
82 const LRGB linkRegistry(registry);
83 return ace_common::isSortedByKey(
84 (
size_t) registrySize,
85 [&linkRegistry](
size_t i) {
86 const LE* linkEntry = linkRegistry.linkEntry(i);
87 return LEB(linkEntry).linkId();
97 uint16_t registrySize, uint32_t linkId) {
98 const LRGB linkRegistry(registry);
100 for (uint16_t i = 0; i < registrySize; ++i) {
101 const LE* linkEntry = linkRegistry.linkEntry(i);
102 if (linkId == LEB(linkEntry).linkId()) {
131 uint16_t registrySize, uint32_t linkId) {
132 const LRGB linkRegistry(registry);
133 return (uint16_t) ace_common::binarySearchByKey(
134 (
size_t) registrySize,
136 [&linkRegistry](
size_t i) {
137 const LE* linkEntry = linkRegistry.linkEntry(i);
138 return LEB(linkEntry).linkId();
155 uint16_t
const mLinkRegistrySize;
156 bool const mIsSorted;
157 const LE*
const mLinkRegistry;
172 basic::LinkEntryBroker,
173 basic::LinkRegistryBroker
178 const basic::LinkEntry* linkRegistry
214 extended::LinkEntryBroker,
215 extended::LinkRegistryBroker
220 const extended::LinkEntry* linkRegistry
The classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zonedb...
The classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zonedb...
Data broker for accessing a LinkEntry.
Concrete template instantiation of LinkRegistrarTemplate for basic::LinkEntry.
Data broker for a LinkRegistry composed of LinkEntry records.
Data broker for accessing a LinkEntry.
Concrete template instantiation of LinkRegistrarTemplate for extended::LinkEntry.
Data broker for a LinkRegistry composed of LinkEntry records.
Class that allows looking up the LinkEntry (LE) from its LinkRegistry (LRGB) using its linkId.
const LE * getLinkEntryForIndex(uint16_t i) const
Return the LinkEntry at index i.
const LE * getLinkEntryForId(uint32_t linkId) const
Return the LinkEntry using the linkId.
LinkRegistrarTemplate(uint16_t linkRegistrySize, const LE *linkRegistry)
Constructor.
uint16_t linkRegistrySize() const
Return the number of (thin) links.
static const uint16_t kInvalidIndex
Invalid index to indicate error or not found.
uint16_t findIndexForIdLinear(uint32_t linkId) const
Exposed only for benchmarking purposes.
uint16_t findIndexForId(uint32_t linkId) const
Find the index for linkId.
static uint16_t binarySearchById(const LE *registry, uint16_t registrySize, uint32_t linkId)
Find the registry index corresponding to linkId using a binary search.
static const uint8_t kBinarySearchThreshold
Use binarySearchById() if linkRegistrySize >= threshold.
uint16_t findIndexForIdBinary(uint32_t linkId) const
Exposed only for benchmarking purposes.
static bool isSorted(const LE *registry, uint16_t registrySize)
Determine if the given link registry is sorted by id.
static uint16_t linearSearchById(const LE *registry, uint16_t registrySize, uint32_t linkId)
Find the registry index corresponding to linkId using linear search.