Merge branch 'ps/doc-gc-aggressive-depth-update'
[git/debian.git] / mru.h
blob42e4aeaa1098af8e1460e33933106e32e74affea
1 #ifndef MRU_H
2 #define MRU_H
4 /**
5 * A simple most-recently-used cache, backed by a doubly-linked list.
7 * Usage is roughly:
9 * // Create a list. Zero-initialization is required.
10 * static struct mru cache;
11 * mru_append(&cache, item);
12 * ...
14 * // Iterate in MRU order.
15 * struct mru_entry *p;
16 * for (p = cache.head; p; p = p->next) {
17 * if (matches(p->item))
18 * break;
19 * }
21 * // Mark an item as used, moving it to the front of the list.
22 * mru_mark(&cache, p);
24 * // Reset the list to empty, cleaning up all resources.
25 * mru_clear(&cache);
27 * Note that you SHOULD NOT call mru_mark() and then continue traversing the
28 * list; it reorders the marked item to the front of the list, and therefore
29 * you will begin traversing the whole list again.
32 struct mru_entry {
33 void *item;
34 struct mru_entry *prev, *next;
37 struct mru {
38 struct mru_entry *head, *tail;
41 void mru_append(struct mru *mru, void *item);
42 void mru_mark(struct mru *mru, struct mru_entry *entry);
43 void mru_clear(struct mru *mru);
45 #endif /* MRU_H */