125template<
typename TAllocator,
126 typename TValueDescriptor,
127 typename THash = std::hash <typename TValueDescriptor::KeyType>,
128 typename TEqual = std::equal_to<typename TValueDescriptor::KeyType> >
130#if ALIB_DEBUG_CRITICAL_SECTIONS
151 using KeyType =
typename TValueDescriptor::KeyType;
202 template<
typename TConstOrMutable>
237 template<
typename TMutable>
238 requires std::same_as<TMutable, TForwardIterator<StoredType>>
330 template<
typename... TArgs>
333 return *
new( &
entry->data ) TConstOrMutable(std::forward<TArgs>(args)...);
347 return TValueDescriptor().Key(
entry->data);
355 return TValueDescriptor().Mapped(
entry->data);
451 result+=
lists[i].count();
465 auto newCapacity= newQtyLists * newQtyEntriesPerList;
480 for(
integer i = 0; i < newQtyLists; ++i )
492 auto* elem=
lists[i].first();
533 const size_t keyHash = THash{}(key);
535 auto& list =
lists[listIdx];
536 Entry* prev2 =
nullptr;
537 Entry* prev1 =
reinterpret_cast<Entry*
>(&list);
538 Entry* actual = list.first();
542 while( actual !=
nullptr ) {
543 if ( actual->hashCode == keyHash
544 && TEqual{}(TValueDescriptor().Key(actual->data), key) )
547 if (prev1 !=
nullptr) {
548 prev1->next( actual->next() );
549 actual->next( list.next() );
552 return std::make_pair(
true,
Iterator(actual,
this, listIdx ));
556 actual= actual->next();
564 prev2->next(
nullptr );
565 prev1->data.~StoredType();
566 prev1->hashCode= keyHash;
567 prev1->next( list.next() );
569 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
574 newEntry->hashCode= keyHash;
575 newEntry->next(list.next());
577 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
608template<
typename TAllocator,
609 typename TKey,
typename TMapped,
610 typename THash = std::hash <TKey>,
611 typename TEqual = std::equal_to<TKey> >
644template<
typename TAllocator,
646 typename THash = std::hash <T>,
647 typename TEqual = std::equal_to<T> >
655template<
typename TAllocator,
656 typename TValueDescriptor,
657 typename THash = std::hash <typename TValueDescriptor::KeyType>,
658 typename TEqual = std::equal_to<typename TValueDescriptor::KeyType> >
663template<
typename TAllocator,
664 typename TKey,
typename TMapped,
665 typename THash = std::hash <TKey>,
666 typename TEqual = std::equal_to<TKey> >
671template<
typename TAllocator,
673 typename THash = std::hash <T>,
674 typename TEqual = std::equal_to<T> >
#define ALIB_DEBUG_CRITICAL_SECTIONS
#define ALIB_ASSERT_ERROR(cond, domain,...)
TConstOrMutable & reference
Implementation of std::iterator_traits.
integer difference_type
Implementation of std::iterator_traits.
TConstOrMutable & Construct(TArgs &&... args) const
TForwardIterator(const TMutable &mutableIt)
TConstOrMutable * pointer
Implementation of std::iterator_traits.
TForwardIterator(Entry *pEntry, LRUCacheTable *pTable, integer pListIdx)
const KeyType & Key() const
TForwardIterator & operator=(const TForwardIterator &other)=default
bool operator==(TForwardIterator other) const
TConstOrMutable & operator*() const
TForwardIterator & operator++()
bool operator!=(TForwardIterator other) const
MappedType & Mapped() const
TForwardIterator operator++(int)
TConstOrMutable & Value() const
TForwardIterator(const TForwardIterator &other)=default
std::forward_iterator_tag iterator_category
Implementation of std::iterator_traits.
TForwardIterator()
Default constructor.
TConstOrMutable value_type
Implementation of std::iterator_traits.
TForwardIterator(LRUCacheTable *pTable, integer pListIdx)
TConstOrMutable * operator->() const
ConstIterator end() const
LRUCacheTable(TAllocator &pAllocator, integer tableSize, integer listSize)
void Clear()
Clears this cache.
ConstIterator cbegin() const
std::pair< bool, Iterator > Try(const KeyType &key)
TForwardIterator< StoredType > Iterator
The mutable iterator over the cache entries.
ConstIterator begin() const
TForwardIterator< const StoredType > ConstIterator
The constant iterator over the cache entries.
void Reserve(integer newQtyLists, integer newQtyEntriesPerList)
lang::SidiListHook< Entry > ForwardList
Shortcut to a forward list.
TAllocator AllocatorType
Type definition publishing template parameter TAllocator.
LRUCacheTable(integer tableSize, integer listSize)
lang::AllocatorMember< TAllocator > allocBase
The type of the base class that stores the allocator.
TValueDescriptor DescriptorType
Type definition publishing template parameter TValueDescriptor.
integer CapacityLists() const
typename TValueDescriptor::MappedType MappedType
typename TValueDescriptor::StoredType StoredType
typename TValueDescriptor::KeyType KeyType
integer CapacityEntries() const
~LRUCacheTable()
Destructor. Calls the destructor of each cached value.
ConstIterator cend() const
TEqual EqualType
Type definition publishing template parameter TEqual.
THash HashType
Type definition publishing template parameter THash.
integer Size() const noexcept
LRUCacheTable< TAllocator, containers::TPairDescriptor< TKey, TMapped >, THash, TEqual > LRUCacheMap
LRUCacheTable< TAllocator, TIdentDescriptor< T >, THash, TEqual > LRUCacheSet
containers::LRUCacheTable< TAllocator, TValueDescriptor, THash, TEqual > LRUCacheTable
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
containers::LRUCacheTable< TAllocator, containers::TIdentDescriptor< T >, THash, TEqual > LRUCacheSet
Type alias in namespace alib.
containers::LRUCacheTable< TAllocator, containers::TPairDescriptor< TKey, TMapped > > LRUCacheMap
Type alias in namespace alib.
The node type of the cache lists.
StoredType data
The data cached.
size_t hashCode
This entries hash code (calculated once on insertion).
AllocatorInterface< TAllocator > AI() const noexcept
DbgCriticalSections(const char *name)
TElement * first() const noexcept
bool isEmpty() const noexcept