summaryrefslogtreecommitdiff
path: root/mru.h
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2018-02-13 13:39:05 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-02-13 13:39:05 -0800
commitafc8aa3fbf249cfc2f75c7586b9d32f172ab97a1 (patch)
tree9e094f4c5032333ff27eadd42a3b6040aa3473a7 /mru.h
parentMerge branch 'jh/partial-clone' (diff)
parentmru: use double-linked list from list.h (diff)
downloadtgif-afc8aa3fbf249cfc2f75c7586b9d32f172ab97a1.tar.xz
Merge branch 'ot/mru-on-list'
The first step to getting rid of mru API and using the doubly-linked list API directly instead. * ot/mru-on-list: mru: use double-linked list from list.h
Diffstat (limited to 'mru.h')
-rw-r--r--mru.h31
1 files changed, 13 insertions, 18 deletions
diff --git a/mru.h b/mru.h
index 42e4aeaa10..80a589eb4c 100644
--- a/mru.h
+++ b/mru.h
@@ -1,6 +1,8 @@
#ifndef MRU_H
#define MRU_H
+#include "list.h"
+
/**
* A simple most-recently-used cache, backed by a doubly-linked list.
*
@@ -8,18 +10,15 @@
*
* // Create a list. Zero-initialization is required.
* static struct mru cache;
- * mru_append(&cache, item);
- * ...
+ * INIT_LIST_HEAD(&cache.list);
*
- * // Iterate in MRU order.
- * struct mru_entry *p;
- * for (p = cache.head; p; p = p->next) {
- * if (matches(p->item))
- * break;
- * }
+ * // Add new item to the end of the list.
+ * void *item;
+ * ...
+ * mru_append(&cache, item);
*
* // Mark an item as used, moving it to the front of the list.
- * mru_mark(&cache, p);
+ * mru_mark(&cache, item);
*
* // Reset the list to empty, cleaning up all resources.
* mru_clear(&cache);
@@ -29,17 +28,13 @@
* you will begin traversing the whole list again.
*/
-struct mru_entry {
- void *item;
- struct mru_entry *prev, *next;
-};
-
struct mru {
- struct mru_entry *head, *tail;
+ struct list_head list;
+ void *item;
};
-void mru_append(struct mru *mru, void *item);
-void mru_mark(struct mru *mru, struct mru_entry *entry);
-void mru_clear(struct mru *mru);
+void mru_append(struct mru *head, void *item);
+void mru_mark(struct mru *head, struct mru *entry);
+void mru_clear(struct mru *head);
#endif /* MRU_H */