Fixed-size cache of items looked up by integer key, evicting the oldest item.
More...
Fixed-size cache of items looked up by integer key, evicting the oldest item.
Keys are stored apart from the items so lookups scan a compact array. Most recently pushed items are found first.
static struct glyph s_glyphs[8];
if (!g) {
load_glyph(codepoint, &tmp);
}
Keyed circular cache state.
Definition keyed_circular_cache.h:39
void * keyed_circular_cache_get(KeyedCircularCache *c, KeyedCircularCacheKey key)
Find an item by key.
void keyed_circular_cache_init(KeyedCircularCache *c, KeyedCircularCacheKey *key_buffer, void *data_buffer, size_t item_size, size_t total_items)
Initialize a keyed circular cache.
void keyed_circular_cache_push(KeyedCircularCache *c, KeyedCircularCacheKey key, const void *item)
Copy an item into the cache, evicting the oldest one.
uint32_t KeyedCircularCacheKey
Key of a keyed circular cache.
Definition keyed_circular_cache.h:36
◆ KeyedCircularCache
| struct KeyedCircularCache |
Keyed circular cache state.
| Data Fields |
|
uint8_t * |
cache_data |
Item array. |
|
KeyedCircularCacheKey * |
cache_keys |
Key array. |
|
size_t |
item_size |
Size of an item in bytes. |
|
size_t |
next_item_to_erase_idx |
Index of the next item to evict. |
|
size_t |
total_items |
Number of items. |
◆ KeyedCircularCacheKey
Key of a keyed circular cache.
◆ keyed_circular_cache_get()
Find an item by key.
- Parameters
-
- Returns
- Item in the cache, or NULL.
◆ keyed_circular_cache_init()
Initialize a keyed circular cache.
The key array is used as is, so initialize it with keys that are never looked up.
- Parameters
-
| [out] | c | Cache. |
| key_buffer | Key array of total_items keys. |
| data_buffer | Item array of total_items items. |
| item_size | Size of an item in bytes. |
| total_items | Number of items. |
◆ keyed_circular_cache_push()
Copy an item into the cache, evicting the oldest one.
- Parameters
-
| c | Cache. |
| key | Key of the item. |
| item | Item, of the cache's item size. |