1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export default class CacheList {
|
13 | private head;
|
14 | private tail;
|
15 | private hashtable;
|
16 | private length;
|
17 | |
18 |
|
19 |
|
20 | constructor();
|
21 | /**
|
22 | * insert node to the head of the list
|
23 | *
|
24 | * @param node
|
25 | */
|
26 | private insertNodeToHead;
|
27 | /**
|
28 | * remove node
|
29 | *
|
30 | * @param node
|
31 | */
|
32 | private removeNode;
|
33 | /**
|
34 | * @return true if list is empty
|
35 | */
|
36 | isEmpty(): boolean;
|
37 | /**
|
38 | * refresh node so it is rotated to the head
|
39 | *
|
40 | * @param key - key of the node
|
41 | */
|
42 | refresh(key: string): void;
|
43 | /**
|
44 | * insert new node to the head and add it in the hashtable
|
45 | *
|
46 | * @param key - the key of the node
|
47 | */
|
48 | insertItem(key: string): void;
|
49 | /**
|
50 | * @return the LAST Recently Visited key
|
51 | */
|
52 | getLastItem(): string;
|
53 | /**
|
54 | * remove the cache key from the list and hashtable
|
55 | * @param key - the key of the node
|
56 | */
|
57 | removeItem(key: string): void;
|
58 | /**
|
59 | * @return length of the list
|
60 | */
|
61 | getSize(): number;
|
62 | /**
|
63 | * @return true if the key is in the hashtable
|
64 | * @param key
|
65 | */
|
66 | containsKey(key: string): boolean;
|
67 | /**
|
68 | * clean up the list and hashtable
|
69 | */
|
70 | clearList(): void;
|
71 | /**
|
72 | * @return all keys in the hashtable
|
73 | */
|
74 | getKeys(): string[];
|
75 | /**
|
76 | * mainly for test
|
77 | *
|
78 | * @param key
|
79 | * @return true if key is the head node
|
80 | */
|
81 | isHeadNode(key: string): boolean;
|
82 | /**
|
83 | * mainly for test
|
84 | *
|
85 | * @param key
|
86 | * @return true if key is the tail node
|
87 | */
|
88 | isTailNode(key: string): boolean;
|
89 | }
|