-
Notifications
You must be signed in to change notification settings - Fork 90
/
example.html
executable file
·94 lines (78 loc) · 2.08 KB
/
example.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lru</title>
<style type="text/css">
body {
font-family:
-apple-system,BlinkMacSystemFont,
"Segoe UI",
Roboto,
Oxygen,
Ubuntu,
Cantarell,
"Open Sans",
"Helvetica Neue",
sans-serif;
letter-spacing:0;
font-weight:400;
font-style:normal;
text-rendering:optimizeLegibility;
-moz-font-feature-settings:"liga" on;
background: white;
color:rgba(0,0,0,.8);
font-size:13px;
line-height:1.4;
margin:2em;
}
a { text-decoration:inherit; color: inherit; }
a:hover { color:#30C2FF; }
b { font-weight: 500; }
ul { list-style:none; }
li { line-height:1.4; }
h2 { font-size: 16px; font-weight:600; }
.log {
background: rgba(0,0,0,0.05);
white-space: pre-line;
display: inline-block;
}
#out {
}
</style>
<!-- <script src="https://unpkg.com/amdld/amdld.min.js"></script> -->
<script src="lru.js"></script>
</head>
<body>
<h2>Expected results:</h2>
<div class="log">adam:29 < john:26 < angela:24
adam:29 < angela:24 < john:26
angela:24 < john:26 < zorro:141
</div>
<h2>Actual results:</h2>
<div class="log" id="out"></div>
<script>
const out = document.querySelector('#out')
function log(s) { out.innerText += s + '\n' }
let c = new LRUMap(3)
c.set('adam', 29)
c.set('john', 26)
c.set('angela', 24)
log(c.toString()) // -> "adam:29 < john:26 < angela:24"
c.get('john') // -> 26
// Now 'john' is the most recently used entry, since we just requested it
log(c.toString()) // -> "adam:29 < angela:24 < john:26"
c.set('zorro', 141) // -> {key:adam, value:29}
// Because we only have room for 3 entries, adding 'zorro' caused 'adam'
// to be removed in order to make room for the new entry
log(c.toString()) // -> "angela:24 < john:26 < zorro:141"
// With AMDLD:
// define(['lru'], function(lru) {
// let c = new lru.LRUMap(3)
// // ...
// })
</script>
</body>
</html>