blob: 9721d85232c6f861176ec9e10335d01814ef4ea7 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package mru
import (
"sync"
"sync/atomic"
)
// Order is a concurrent most-recently-used ordering over keys.
//
// The front is the most-recently-used key.
// Order expresses recency only,
// never priority;
// a caller that needs a fixed priority order
// must arrange its keys in that order itself.
// Order never evicts.
//
// Reads are lock-free over an immutable snapshot,
// so a concurrent Touch or Sync
// never perturbs an in-progress walk.
//
// Labels: MT-Safe.
type Order[K comparable] struct {
snapshot atomic.Pointer[[]K]
mu sync.Mutex
}
|