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;
204 template<
typename TConstOrMutable>
240 template<
typename TMutable>
241 requires std::same_as<TMutable, TForwardIterator<StoredType>>
319 return !(*
this == other);
346 template<
typename... TArgs>
350 return *
new( &
entry->data ) TConstOrMutable(std::forward<TArgs>(args)...);
366 return TValueDescriptor().Key(
entry->data);
375 return TValueDescriptor().Mapped(
entry->data);
473 result+=
lists[i].count();
488 auto newCapacity= newQtyLists * newQtyEntriesPerList;
505 for(
integer i = 0; i < newQtyLists; ++i )
519 auto* elem=
lists[i].first();
563 const size_t keyHash = THash{}(key);
565 auto& list =
lists[listIdx];
566 Entry* prev2 =
nullptr;
567 Entry* prev1 =
reinterpret_cast<Entry*
>(&list);
568 Entry* actual = list.first();
572 while( actual !=
nullptr )
574 if ( actual->hashCode == keyHash
575 && TEqual{}(TValueDescriptor().Key(actual->data), key) )
578 if (prev1 !=
nullptr)
580 prev1->next( actual->next() );
581 actual->next( list.next() );
584 return std::make_pair(
true,
Iterator(actual,
this, listIdx ));
588 actual= actual->next();
597 prev2->next(
nullptr );
598 prev1->data.~StoredType();
599 prev1->hashCode= keyHash;
600 prev1->next( list.next() );
602 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
607 newEntry->hashCode= keyHash;
608 newEntry->next(list.next());
610 return std::make_pair(
false,
Iterator(list.first(),
this, listIdx ));
641template<
typename TAllocator,
642 typename TKey,
typename TMapped,
643 typename THash = std::hash <TKey>,
644 typename TEqual = std::equal_to<TKey> >
677template<
typename TAllocator,
679 typename THash = std::hash <T>,
680 typename TEqual = std::equal_to<T> >
688template<
typename TAllocator,
689 typename TValueDescriptor,
690 typename THash = std::hash <typename TValueDescriptor::KeyType>,
691 typename TEqual = std::equal_to<typename TValueDescriptor::KeyType> >
696template<
typename TAllocator,
697 typename TKey,
typename TMapped,
698 typename THash = std::hash <TKey>,
699 typename TEqual = std::equal_to<TKey> >
704template<
typename TAllocator,
706 typename THash = std::hash <T>,
707 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 allocator type that TAllocator specifies.
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