AceTime  1.7.4
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | Friends | List of all members
ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB > Class Template Reference

Class that allows looking up the LinkEntry (LE) from its LinkRegistry (LRGB) using its linkId. More...

#include <LinkRegistrar.h>

Public Member Functions

 LinkRegistrarTemplate (uint16_t linkRegistrySize, const LE *linkRegistry)
 Constructor.
 
uint16_t linkRegistrySize () const
 Return the number of (thin) links.
 
const LE * getLinkEntryForIndex (uint16_t i) const
 Return the LinkEntry at index i. More...
 
const LE * getLinkEntryForId (uint32_t linkId) const
 Return the LinkEntry using the linkId. More...
 
uint16_t findIndexForId (uint32_t linkId) const
 Find the index for linkId. More...
 

Static Public Attributes

static const uint16_t kInvalidIndex = 0xffff
 Invalid index to indicate error or not found.
 

Protected Member Functions

uint16_t findIndexForIdLinear (uint32_t linkId) const
 Exposed only for benchmarking purposes.
 
uint16_t findIndexForIdBinary (uint32_t linkId) const
 Exposed only for benchmarking purposes.
 

Static Protected Member Functions

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. More...
 
static uint16_t binarySearchById (const LE *registry, uint16_t registrySize, uint32_t linkId)
 Find the registry index corresponding to linkId using a binary search. More...
 

Static Protected Attributes

static const uint8_t kBinarySearchThreshold = 8
 Use binarySearchById() if linkRegistrySize >= threshold.
 

Friends

class ::LinkRegistrarTest_isSorted
 

Detailed Description

template<typename LE, typename LEB, typename LRGB>
class ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >

Class that allows looking up the LinkEntry (LE) from its LinkRegistry (LRGB) using its linkId.

Template Parameters
LELinkEntry type (e.g. basic::LinkEntry)
LEBLinkEntryBroker type (e.g. basic::LinkEntryBroker)
LRGBLinkRegistryBroker type (e.g. basic::LinkRegistryBroker)

Definition at line 30 of file LinkRegistrar.h.

Member Function Documentation

◆ binarySearchById()

template<typename LE , typename LEB , typename LRGB >
static uint16_t ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >::binarySearchById ( const LE *  registry,
uint16_t  registrySize,
uint32_t  linkId 
)
inlinestaticprotected

Find the registry index corresponding to linkId using a binary search.

Returns kInvalidIndex if not found.

The largest registrySize is UINT16_MAX so the largest valid index is UINT16_MAX - 1. This allows us to set kInvalidIndex to UINT16_MAX to indicate "Not Found".

Definition at line 130 of file LinkRegistrar.h.

◆ findIndexForId()

template<typename LE , typename LEB , typename LRGB >
uint16_t ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >::findIndexForId ( uint32_t  linkId) const
inline

Find the index for linkId.

Return kInvalidIndex if not found.

Definition at line 66 of file LinkRegistrar.h.

◆ getLinkEntryForId()

template<typename LE , typename LEB , typename LRGB >
const LE* ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >::getLinkEntryForId ( uint32_t  linkId) const
inline

Return the LinkEntry using the linkId.

Return nullptr if not found.

Definition at line 56 of file LinkRegistrar.h.

◆ getLinkEntryForIndex()

template<typename LE , typename LEB , typename LRGB >
const LE* ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >::getLinkEntryForIndex ( uint16_t  i) const
inline

Return the LinkEntry at index i.

Return nullptr if i is out of range.

Definition at line 49 of file LinkRegistrar.h.

◆ linearSearchById()

template<typename LE , typename LEB , typename LRGB >
static uint16_t ace_time::internal::LinkRegistrarTemplate< LE, LEB, LRGB >::linearSearchById ( const LE *  registry,
uint16_t  registrySize,
uint32_t  linkId 
)
inlinestaticprotected

Find the registry index corresponding to linkId using linear search.

Returns kInvalidIndex if not found.

Definition at line 96 of file LinkRegistrar.h.


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