|
Tkrzw
|
LRU cache. More...
#include <tkrzw_containers.h>
Classes | |
| class | Iterator |
| Iterator to access each record. More... | |
Public Member Functions | |
| LRUCache (size_t capacity) | |
| Constructor. | |
| std::shared_ptr< VALUETYPE > | Add (int64_t id, VALUETYPE *value) |
| Adds a record. | |
| void | GiveBack (int64_t id, std::shared_ptr< VALUETYPE > &&value) |
| Gives back a record which has been removed. | |
| std::shared_ptr< VALUETYPE > | Get (int64_t id) |
| Gets the value of a record. | |
| void | Remove (int64_t id) |
| Removes a record. | |
| std::shared_ptr< VALUETYPE > | RemoveLRU (int64_t *id=nullptr) |
| Removes the least recent used record. | |
| size_t | Size () const |
| Gets the number of records. | |
| bool | IsEmpty () const |
| Checks whether no records exist. | |
| bool | IsSaturated () const |
| Checks whether stored records exceeds the capacity. | |
| void | Clear () |
| Removes all records. | |
| Iterator | MakeIterator () |
| Makes an iterator for each record. | |
LRU cache.
| VALUETYPE | the value type. |
| tkrzw::LRUCache< VALUETYPE >::LRUCache | ( | size_t | capacity | ) |
Constructor.
| capacity | The maximum number of records in the cache. |
| std::shared_ptr< VALUETYPE > tkrzw::LRUCache< VALUETYPE >::Add | ( | int64_t | id, |
| VALUETYPE * | value ) |
Adds a record.
| id | The ID of the record. |
| value | The pointer to the value object. Ownership is taken. |
If there is an existing record of the same ID, the new value object is just deleted and the return value refers to the existing record.
| void tkrzw::LRUCache< VALUETYPE >::GiveBack | ( | int64_t | id, |
| std::shared_ptr< VALUETYPE > && | value ) |
Gives back a record which has been removed.
| id | The ID of the record. |
| value | The moved pointer to the value object. Ownership is taken. |
| std::shared_ptr< VALUETYPE > tkrzw::LRUCache< VALUETYPE >::Get | ( | int64_t | id | ) |
Gets the value of a record.
| id | The ID of the record. |
| void tkrzw::LRUCache< VALUETYPE >::Remove | ( | int64_t | id | ) |
Removes a record.
| id | The ID of the record. |
| std::shared_ptr< VALUETYPE > tkrzw::LRUCache< VALUETYPE >::RemoveLRU | ( | int64_t * | id = nullptr | ) |
Removes the least recent used record.
| id | The pointer to store the ID of the record. If it is nullptr, it is ignored. |
| size_t tkrzw::LRUCache< VALUETYPE >::Size | ( | ) | const |
Gets the number of records.
| bool tkrzw::LRUCache< VALUETYPE >::IsEmpty | ( | ) | const |
Checks whether no records exist.
| bool tkrzw::LRUCache< VALUETYPE >::IsSaturated | ( | ) | const |
Checks whether stored records exceeds the capacity.
| void tkrzw::LRUCache< VALUETYPE >::Clear | ( | ) |
Removes all records.
| LRUCache< VALUETYPE >::Iterator tkrzw::LRUCache< VALUETYPE >::MakeIterator | ( | ) |
Makes an iterator for each record.