MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / insert

Function insert

CPP/structures/LRU.cpp:5–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3list<int> q;
4int sz;
5void insert(int x)
6{
7
8 // if not present
9 if (mp.find(x) == mp.end())
10 {
11 if (q.size() == sz)
12 {
13 int last = q.back();
14 q.pop_back();
15 mp.erase(last);
16 }
17 }
18 // if present
19 else
20 mp.erase(x);
21
22 q.push_front(x);
23 mp[x] = q.begin();
24}
25
26void display()
27{

Callers 1

mainFunction · 0.70

Calls 4

pop_backMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected