-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLandlord.cpp
More file actions
58 lines (52 loc) · 1.88 KB
/
Copy pathLandlord.cpp
File metadata and controls
58 lines (52 loc) · 1.88 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Landlord.h"
#include <cassert>
#include <cmath>
namespace Caching {
inline uint64_t LFromLength(uint64_t len) { return len;}
Landlord::Landlord(size_t maxPstings) : totalPostings(0), accumulator(0) {
maxPostings = maxPstings;
}
void Landlord::miss(term_t term, size_t length) {
while (totalPostings > maxPostings) { //remove overflows!
assert(!heap.empty());
auto it = heap.begin();
Term *tptr = *it;
assert(totalPostings >= tptr->length);
totalPostings -= tptr->length;
BaseCache::evict(tptr->term);
heap.erase(it);
}
while (totalPostings + length > maxPostings) { //evict to accommodate with bound size policy
assert(!heap.empty());
auto it = heap.begin();
Term *tptr = *it;
if(tptr->L > accumulator)
return; //don't add it!
assert(totalPostings >= tptr->length);
totalPostings -= tptr->length;
BaseCache::evict(tptr->term);
heap.erase(it);
}
Term *tptr = placeNew(term, length);
accumulator += LFromLength(length);
tptr->L = accumulator;
totalPostings += length;
heap.insert(tptr);
}
#define DODGY_HIT_MODE
void Landlord::hit(Term *tptr, size_t newLength) {
heap.erase(tptr); //erase first, since
++(tptr->hitCount); //could be violating the map now!
uint64_t mult = 1; // tptr->hitCount
tptr->L = accumulator + (LFromLength(newLength) * mult); //reset L
if(tptr->length != newLength) { //cache data not coherent
#ifdef DODGY_HIT_MODE
assert(totalPostings >= tptr->length);
totalPostings -= tptr->length;
totalPostings += newLength;
tptr->length = newLength;
#endif
}
heap.insert(tptr);
}
}