Least Used (LRU) Cache

I know that I can use different classes of containers in STL, but it is too expensive and expensive for this purpose.

We have more than 1M + users online, and for each user we need to support 8 unrelated 32-bit data elements. The goal is to

  • find if the item exists in the list,
  • if not, insert. Delete the old entry if it is full.

Brute Force's approach will be to maintain the last pointer to the record and repeat (starting with 8 elements), but I'm looking for materials for better analysis and implementation.

Look at some interesting suggestions in terms of design and algorithm.

+6
source share
6
" ".
  • I: , ; .
  • II: , ; .

    [ . 3 §6.1 (A).]

  • 1 , , , , , - . , , , , .. .

    [. 1 §2.5 (G).]

+2

Hash doubly linked list.
-, , , .

:

x, do:
1. x , ptr.
2. x -, , ptr.
3. , ( ) . , Hash.

+1

, C- LRU,

, LRU Cache.

, . ( ). , .
node .
, . , node .
, . node node . , , node node .

+1

Cuckoo Filter, , set. hash.

:

  • : O (1)
  • : O (1)
  • : O (1)

: .

Parameters of the filter

 1. Two Hash Functions: h1 and h2
 2. An array B with n Buckets. The i-th Bucket will be called B[i]

Input : L, a list of elements to inserted into the cuckoo filter.

Algorithm:
while L is not empty:
    Let x be the 1st item in the list L. Remove x from the list.
    if (B[h1(x)] == empty)
          place x in B[h1(x)];
    else if (B[h2(x)] == empty)
          place x in B[h2(x)];
    else
          Let y be the element in B[h2(x)]
          Prepend y to L
          place x in B[h2(x)]

LRU -, .

.

0

, EJP, , , .

, ( ). , ( - ). ...

, : , ( I) ( II), , :

a, b, c, d
      ^

:

d, b, a, c
      ^

e:

d, e, a, c
   ^

: (d ) - :

d, e, a, c
^

: 8 , , ...

0

Drop Geza. .

, , - 32- 256 . , x86, : _mm256_cmp_epi32_mask , _mm256_lzcnt_epi32 = * 32. SIMD- / - . , , . , -.

0

All Articles