@@ -40,12 +40,14 @@ async function rangelistPerf(n) {
40
40
41
41
const r = spacedinput ( n ) ;
42
42
43
+ // insert (range, value) pairs
43
44
const ts1 = Date . now ( ) ;
44
45
r . forEach ( ( i ) => s . set ( mkrange ( i , i + 1 ) , "r" + i ) ) ;
45
46
const ts2 = Date . now ( ) ;
46
47
47
48
console . log ( tag , "setup duration" , ts2 - ts1 + "ms" ) ;
48
49
50
+ // retrieve values of all valid keys
49
51
const t = [ ] ;
50
52
const miss = [ ] ;
51
53
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -60,7 +62,25 @@ async function rangelistPerf(n) {
60
62
}
61
63
62
64
console . log ( tag , "get:avg(nodes-visited)" , log2 ( n ) , "~=" , s . avgGetIter ) ;
65
+ s . avgGetIter = 0 ; // reset
63
66
67
+ // search nearby items, upto r.length no. of times
68
+ const tf = [ ] ;
69
+ const missf = [ ] ;
70
+ for ( let j = 0 , i = 0 , x = null ; j < r . length ; j ++ ) {
71
+ i = nearbyInt ( i , 100 , 0 , n ) ;
72
+
73
+ const t1 = Date . now ( ) ;
74
+ x = s . search ( mkrange ( i , i ) , x ) [ 1 ] ;
75
+ const t2 = Date . now ( ) ;
76
+ tf . push ( t2 - t1 ) ;
77
+
78
+ if ( x == null ) missf . push ( i ) ;
79
+ }
80
+
81
+ console . log ( tag , "find:avg(nodes-visited)" , log2 ( n ) , "~=" , s . avgGetIter ) ;
82
+
83
+ // delete all keys
64
84
const td = [ ] ;
65
85
const missd = [ ] ;
66
86
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -77,7 +97,7 @@ async function rangelistPerf(n) {
77
97
logmissing ( tag + " get:" , miss ) ;
78
98
logmissing ( tag + " del:" , missd ) ;
79
99
logquantiles ( tag , t , rlExpectedP99ForSize1M ) ;
80
- logsums ( tag , t , td , rlExpectedSumForSize1M ) ;
100
+ logsums ( tag , t , tf , rlExpectedSumForSize1M ) ;
81
101
82
102
console . log ( tag , "---fin---" ) ;
83
103
@@ -92,12 +112,14 @@ async function balancedRangeListPerf(n) {
92
112
93
113
const r = spacedinput ( n ) ;
94
114
115
+ // insert (range, value) pairs
95
116
const ts1 = Date . now ( ) ;
96
117
r . forEach ( ( i ) => s . set ( mkrange ( i , i + 1 ) , "r" + i ) ) ;
97
118
const ts2 = Date . now ( ) ;
98
119
99
120
console . log ( tag , "setup duration" , ts2 - ts1 + "ms" ) ;
100
121
122
+ // balance rangelist
101
123
const ts3 = Date . now ( ) ;
102
124
s = balancedCopy ( s ) ;
103
125
const ts4 = Date . now ( ) ;
@@ -128,7 +150,7 @@ async function balancedRangeListPerf(n) {
128
150
i = nearbyInt ( i , 100 , 0 , n ) ;
129
151
130
152
const t1 = Date . now ( ) ;
131
- x = s . search ( mkrange ( i , i ) , x ) ;
153
+ x = s . search ( mkrange ( i , i ) , x ) [ 1 ] ;
132
154
const t2 = Date . now ( ) ;
133
155
tf . push ( t2 - t1 ) ;
134
156
@@ -155,12 +177,14 @@ async function hashMapPerf(n) {
155
177
156
178
const r = spacedinput ( n ) ;
157
179
180
+ // insert (k, v) pairs
158
181
const ot1 = Date . now ( ) ;
159
182
r . forEach ( ( i ) => s . set ( i , "m" + i ) ) ;
160
183
const ot2 = Date . now ( ) ;
161
184
162
185
console . log ( tag , "setup duration" , ot2 - ot1 + "ms" ) ;
163
186
187
+ // retrieve values of all valid keys
164
188
const t = [ ] ;
165
189
const miss = [ ] ;
166
190
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -174,6 +198,7 @@ async function hashMapPerf(n) {
174
198
if ( x == null ) miss . push ( i ) ;
175
199
}
176
200
201
+ // delete all keys
177
202
const td = [ ] ;
178
203
const missd = [ ] ;
179
204
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -254,7 +279,7 @@ function nearbyInt(i, jump, min, max) {
254
279
const n = add ? i + vec : i - vec ;
255
280
256
281
if ( n < min ) return min + vec ;
257
- if ( n > max ) return max - vec ;
282
+ if ( n >= max ) return max - vec ;
258
283
return n ;
259
284
}
260
285
0 commit comments