From 7ee31ad36b62b34d442b150f2211f6ba55df20af Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Thu, 15 Dec 2022 22:14:16 +0000 Subject: [PATCH] Copy diagram from scrap paper into code for clarity. --- src/Db.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Db.c b/src/Db.c index 82aa2fb..45b85eb 100644 --- a/src/Db.c +++ b/src/Db.c @@ -40,6 +40,25 @@ struct Db size_t maxCache; HashMap *cache; + /* + * The cache uses a double linked list (see DbRef + * below) to know which objects are most and least + * recently used. The following diagram helps me + * know what way all the pointers go, because it + * can get very confusing sometimes. For example, + * there's nothing stopping "next" from pointing to + * least recent, and "prev" from pointing to most + * recent, so hopefully this clarifies the pointer + * terminology used when dealing with the linked + * list: + * + * mostRecent leastRecent + * | prev prev | prev + * +---+ ---> +---+ ---> +---+ ---> NULL + * |ref| |ref| |ref| + * NULL <--- +---+ <--- +---+ <--- +---+ + * next next next + */ DbRef *mostRecent; DbRef *leastRecent; };