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();
534 const size_t keyHash = THash{}(key);
536 auto& list =
lists[listIdx];
537 Entry* prev2 =
nullptr;
538 Entry* prev1 =
reinterpret_cast<Entry*
>(&list);
539 Entry* actual = list.first();
543 while( actual !=
nullptr ) {
544 if ( actual->hashCode == keyHash
545 && TEqual{}(TValueDescriptor().Key(actual->data), key) )
548 if (prev1 !=
nullptr) {
549 prev1->next( actual->next() );
550 actual->next( list.next() );
553 return std::make_pair(
true,
Iterator(actual,
this, listIdx ));
557 actual= actual->next();
565 prev2->next(
nullptr );
566 prev1->data.~StoredType();
567 prev1->hashCode= keyHash;
568 prev1->next( list.next() );
570 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
575 newEntry->hashCode= keyHash;
576 newEntry->next(list.next());
578 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
609template<
typename TAllocator,
610 typename TKey,
typename TMapped,
611 typename THash = std::hash <TKey>,
612 typename TEqual = std::equal_to<TKey> >
645template<
typename TAllocator,
647 typename THash = std::hash <T>,
648 typename TEqual = std::equal_to<T> >
656template<
typename TAllocator,
657 typename TValueDescriptor,
658 typename THash = std::hash <typename TValueDescriptor::KeyType>,
659 typename TEqual = std::equal_to<typename TValueDescriptor::KeyType> >
664template<
typename TAllocator,
665 typename TKey,
typename TMapped,
666 typename THash = std::hash <TKey>,
667 typename TEqual = std::equal_to<TKey> >
672template<
typename TAllocator,
674 typename THash = std::hash <T>,
675 typename TEqual = std::equal_to<T> >
TConstOrMutable & reference
Implementation of std::iterator_traits.
integer difference_type
Implementation of std::iterator_traits.
TConstOrMutable & Construct(TArgs &&... args) const
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.
TForwardIterator(const TMutable &mutableIt)
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.
lang::AllocatorMember< TAllocator > allocBase
The type of the base class that stores the allocator.
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)
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
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_DEBUG_CRITICAL_SECTIONS
LRUCacheTable< TAllocator, containers::TPairDescriptor< TKey, TMapped >, THash, TEqual > LRUCacheMap
LRUCacheTable< TAllocator, TIdentDescriptor< T >, THash, TEqual > LRUCacheSet
containers::LRUCacheTable< TAllocator, containers::TPairDescriptor< TKey, TMapped > > LRUCacheMap
Type alias in namespace alib.
containers::LRUCacheTable< TAllocator, TValueDescriptor, THash, TEqual > LRUCacheTable
Type alias in namespace alib.
containers::LRUCacheTable< TAllocator, containers::TIdentDescriptor< T >, THash, TEqual > LRUCacheSet
Type alias in namespace alib.
lang::integer integer
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