1
- import { cacheValue } from './types.ts'
1
+ import type { CacheValue } from './types.ts'
2
2
3
3
/**
4
4
* Class definition for linked list containing cached values for both LRU and LFU.
5
5
*/
6
6
export class Node {
7
7
next : Node | null ;
8
8
prev : Node | null ;
9
- value : cacheValue ;
9
+ value : CacheValue ;
10
10
key : string ;
11
11
count : number ;
12
12
byteSize : number ;
@@ -15,7 +15,7 @@ export class Node {
15
15
16
16
constructor (
17
17
key : string ,
18
- value : cacheValue ,
18
+ value : CacheValue ,
19
19
byteSize : number ,
20
20
timeStamp : Date ,
21
21
parent ?: FreqNode
@@ -42,11 +42,11 @@ export class ValueDoublyLinkedList {
42
42
43
43
public addHead (
44
44
key : string ,
45
- value : cacheValue ,
45
+ value : CacheValue ,
46
46
byteSize : number ,
47
47
timeStamp : Date ,
48
48
parent ?: FreqNode
49
- ) {
49
+ ) : Node {
50
50
const node = new Node ( key , value , byteSize , timeStamp , parent ) ;
51
51
if ( ! this . head ) {
52
52
this . head = node ;
@@ -59,7 +59,7 @@ export class ValueDoublyLinkedList {
59
59
return this . head ;
60
60
}
61
61
62
- public delete ( node : Node | null ) {
62
+ public delete ( node : Node | null ) : Node | undefined {
63
63
if ( ! node ) {
64
64
return ;
65
65
}
@@ -132,7 +132,7 @@ export class FreqDoublyLinkedList {
132
132
this . tail = null ;
133
133
}
134
134
135
- public addNewFreq ( key : string , value : cacheValue , byteSize : number , timeStamp : Date ) {
135
+ public addNewFreq ( key : string , value : CacheValue , byteSize : number , timeStamp : Date ) : Node {
136
136
if ( ! this . head ) {
137
137
this . head = new FreqNode ( 1 ) ;
138
138
this . tail = this . head ;
@@ -146,7 +146,7 @@ export class FreqDoublyLinkedList {
146
146
return this . head . valList . addHead ( key , value , byteSize , timeStamp , this . head ) ;
147
147
}
148
148
149
- public increaseFreq ( node : Node ) {
149
+ public increaseFreq ( node : Node ) : Node | undefined {
150
150
if ( ! node . parent ) {
151
151
return ;
152
152
}
@@ -175,11 +175,11 @@ export class FreqDoublyLinkedList {
175
175
return parent . next . valList . addHead ( key , value , byteSize , timeStamp , parent . next ) ;
176
176
}
177
177
178
- public deleteLeastFreq = ( ) => this . head ?
178
+ public deleteLeastFreq = ( ) : Node | undefined => this . head ?
179
179
this . deleteValNode ( this . head . valList . tail )
180
180
: undefined ;
181
181
182
- public deleteValNode ( node : Node | null ) {
182
+ public deleteValNode ( node : Node | null ) : Node | undefined {
183
183
if ( ! node || ! node . parent ) {
184
184
return ;
185
185
}
@@ -193,7 +193,7 @@ export class FreqDoublyLinkedList {
193
193
return node ;
194
194
}
195
195
196
- public delete ( freqNode : FreqNode | null ) {
196
+ public delete ( freqNode : FreqNode | null ) : FreqNode | undefined {
197
197
if ( ! freqNode ) {
198
198
return ;
199
199
}
0 commit comments