Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's design the data structures for a caching proxy. We need a map from URLs to content; let's use a hash table. We also need a way to find pages to evict; let's use a FIFO queue to track the order in which URLs were last accessed, so that we can implement LRU eviction. In C, the data structure could look something like</p> <pre><code>struct node { struct node *queueprev, *queuenext; struct node **hashbucketprev, *hashbucketnext; const char *url; const void *content; size_t contentlength; }; struct node *queuehead; /* circular doubly-linked list */ struct node **hashbucket; </code></pre> <p>One subtlety: to avoid a special case and wasting space in the hash buckets, <code>x-&gt;hashbucketprev</code> points to the pointer that points to <code>x</code>. If <code>x</code> is first in the bucket, it points into <code>hashbucket</code>; otherwise, it points into another node. We can remove <code>x</code> from its bucket with</p> <pre><code>x-&gt;hashbucketnext-&gt;hashbucketprev = x-&gt;hashbucketprev; *(x-&gt;hashbucketprev) = x-&gt;hashbucketnext; </code></pre> <p>When evicting, we iterate over the least recently accessed nodes via the <code>queuehead</code> pointer. Without <code>hashbucketprev</code>, we would need to hash each node and find its predecessor with a linear search, since we did not reach it via <code>hashbucketnext</code>. (Whether that's really bad is debatable, given that the hash should be cheap and the chain should be short. I suspect that the comment you're asking about was basically a throwaway.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload