5#ifndef LINE_SOLVERS_LDES_LDES_CACHE_H
6#define LINE_SOLVERS_LDES_LDES_CACHE_H
50 std::vector<std::list<std::size_t>>
lists;
83 std::vector<std::vector<HeldRequest>>
held;
95 std::size_t
retrieval_of(std::size_t item, std::size_t cls)
const {
101 int find(std::size_t item)
const {
102 for (std::size_t l = 0; l <
lists.size(); ++l)
103 for (std::size_t v :
lists[l])
104 if (v == item)
return static_cast<int>(l);
139 const std::size_t up = (climb && at + 1 < cs.
lists.size()) ? at + 1 : at;
142 cs.
lists[at].remove(item);
143 cs.
lists[at].push_front(item);
147 std::list<std::size_t>& lo = cs.
lists[at];
148 std::list<std::size_t>& hi = cs.
lists[up];
156 const std::size_t victim =
158 ? *std::next(hi.begin(),
static_cast<std::ptrdiff_t
>(
159 std::min<std::size_t>(hi.size() - 1,
160 static_cast<std::size_t
>(
161 u_random * hi.size()))))
168 if (hi_after > cs.
cap_of(up) || (cs.
cap_of(at) >= 0.0 && lo_after > cs.
cap_of(at)))
return;
174 lo.push_front(victim);
176 lo.push_back(victim);
181 if (cs.
lists.empty())
return;
182 const std::size_t target = 0;
183 std::list<std::size_t>& list = cs.
lists[target];
184 const std::size_t cap = cs.
capacity[target];
189 const std::size_t pos =
190 std::min<std::size_t>(list.size() - 1,
static_cast<std::size_t
>(u_random * list.size()));
191 auto it = std::next(list.begin(),
static_cast<std::ptrdiff_t
>(pos));
200 if (list.size() + 1 > cap && !list.empty()) resulting -= cs.
size_of(list.back());
201 if (resulting > cs.
cap_of(target))
return;
203 list.push_front(item);
204 if (list.size() > cap) list.pop_back();
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
@ CLIMB
move up one position on a hit (transposition rule)
@ QLRU
q-LRU: LRU with probabilistic admission on a miss
void cache_hit(CacheState &cs, std::size_t item, std::size_t at, double u_random)
Serve a HIT in list at.
void cache_miss(CacheState &cs, std::size_t item, double u_admit, double u_random)
Serve a MISS: insert into the entry list, evicting if it is full.
bool cache_refreshes(lang::ReplacementStrategy p)
True for the policies that refresh recency on a hit.
A request parked while its item was being fetched.
double t_sys
its system arrival time, for response time
std::size_t cls
the ACCESS class that read the cache
double hold_time
when it was parked
Live state of one Cache node.
std::vector< double > misses
per access class
double cap_of(std::size_t l) const
int find(std::size_t item) const
The list holding item, or -1.
std::vector< int > hit_class
std::vector< double > item_size
empty = unconstrained
bool has_retrieval
Cache.setRetrievalSystem: a miss FETCHES the item through a sub-network instead of being served at on...
double delayed_wait
summed parked time over all releases
double size_of(std::size_t item) const
double qlru
q-LRU admission probability on a miss
std::vector< double > cost_cap
empty = unconstrained
double list_cost(std::size_t l) const
std::vector< std::list< std::size_t > > lists
per list, most recent at the front
std::vector< double > delayed
per access class, delayed-hit count
int fetches_item(std::size_t cls) const
The item cls fetches, or -1.
std::vector< int > miss_class
0-based destination class, -1 = unset
std::size_t retrieval_of(std::size_t item, std::size_t cls) const
The retrieval class of item for access class cls, or 0.
lang::ReplacementStrategy policy
std::vector< double > fetch_start
per item, when that fetch began
std::vector< std::vector< double > > popularity
Per access class: the item popularity, as a cumulative law.
std::vector< std::size_t > capacity
per list
std::vector< int > retrieval_class_to_item
Per class: the item it fetches, or -1 when it is not a retrieval class.
double total_fetch_time
summed fetch duration
std::vector< double > hits
std::vector< char > in_flight
per item, a fetch is outstanding
std::vector< std::vector< std::size_t > > retrieval_class
(nitems x nclasses) the per-item retrieval class, 0 = none.
std::vector< std::vector< HeldRequest > > held
per item