mru: use double-linked list from list.h
[git.git] / mru.h
blob80a589eb4c0ebef4d65351418673379fbd6fcc7c
1 #ifndef MRU_H
2 #define MRU_H
4 #include "list.h"
6 /**
7 * A simple most-recently-used cache, backed by a doubly-linked list.
9 * Usage is roughly:
11 * // Create a list. Zero-initialization is required.
12 * static struct mru cache;
13 * INIT_LIST_HEAD(&cache.list);
15 * // Add new item to the end of the list.
16 * void *item;
17 * ...
18 * mru_append(&cache, item);
20 * // Mark an item as used, moving it to the front of the list.
21 * mru_mark(&cache, item);
23 * // Reset the list to empty, cleaning up all resources.
24 * mru_clear(&cache);
26 * Note that you SHOULD NOT call mru_mark() and then continue traversing the
27 * list; it reorders the marked item to the front of the list, and therefore
28 * you will begin traversing the whole list again.
31 struct mru {
32 struct list_head list;
33 void *item;
36 void mru_append(struct mru *head, void *item);
37 void mru_mark(struct mru *head, struct mru *entry);
38 void mru_clear(struct mru *head);
40 #endif /* MRU_H */