Skip to content

Commit 3a4343b

Browse files
committed
导出
1 parent 2f18d12 commit 3a4343b

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

lfu-cache/MyLinkedList.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
import { DoublyLinkedList } from "../design-linked-list/DoublyLinkedList.ts";
2-
3-
export class MyLinkedList<T = number> {
4-
readonly #freq_list_head = DoublyLinkedList<T>();
5-
readonly #freq_list_tail = DoublyLinkedList<T>();
6-
constructor() {
7-
this.#freq_list_head.next = this.#freq_list_tail;
8-
this.#freq_list_tail.prev = this.#freq_list_head;
9-
}
10-
first_node() {
11-
return this.#freq_list_head.next === this.#freq_list_tail
12-
? null
13-
: this.#freq_list_head.next;
14-
}
15-
insert_First(node: DoublyLinkedList<T>): void {
16-
this.insert_After(this.#freq_list_head, node);
17-
}
18-
remove_node(node: DoublyLinkedList<T>): void {
19-
const prev = node.prev;
20-
const next = node.next;
21-
if (prev && next) {
22-
prev.next = next;
23-
24-
next.prev = prev;
25-
} else {
26-
throw Error("next prev node not in list");
27-
}
28-
}
29-
insert_After(
30-
prev_node: DoublyLinkedList<T>,
31-
new_node: DoublyLinkedList<T>
32-
): void {
33-
const next = prev_node.next;
34-
const prev = prev_node;
35-
if (prev && next) {
36-
prev.next = new_node;
37-
new_node.prev = prev;
38-
new_node.next = next;
39-
next.prev = new_node;
40-
} else {
41-
throw Error("next prev_node not in list");
42-
}
43-
}
44-
}
1+
import { DoublyLinkedList } from "../design-linked-list/DoublyLinkedList.ts";
2+
3+
export class MyLinkedList<T = number> {
4+
readonly #freq_list_head = DoublyLinkedList<T>();
5+
readonly #freq_list_tail = DoublyLinkedList<T>();
6+
constructor() {
7+
this.#freq_list_head.next = this.#freq_list_tail;
8+
this.#freq_list_tail.prev = this.#freq_list_head;
9+
}
10+
11+
first_node() {
12+
return this.#freq_list_head.next === this.#freq_list_tail
13+
? null
14+
: this.#freq_list_head.next;
15+
}
16+
insert_First(node: DoublyLinkedList<T>): void {
17+
this.insert_After(this.#freq_list_head, node);
18+
}
19+
remove_node(node: DoublyLinkedList<T>): void {
20+
const prev = node.prev;
21+
const next = node.next;
22+
if (prev && next) {
23+
prev.next = next;
24+
25+
next.prev = prev;
26+
} else {
27+
throw Error("next prev node not in list");
28+
}
29+
}
30+
insert_After(
31+
prev_node: DoublyLinkedList<T>,
32+
new_node: DoublyLinkedList<T>,
33+
): void {
34+
const next = prev_node.next;
35+
const prev = prev_node;
36+
if (prev && next) {
37+
prev.next = new_node;
38+
new_node.prev = prev;
39+
new_node.next = next;
40+
next.prev = new_node;
41+
} else {
42+
throw Error("next prev_node not in list");
43+
}
44+
}
45+
}

lfu-cache/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class LFUCache {
9595
// debugger;
9696
if (!this.#has(key)) {
9797
if (this.#size === this.#capacity) {
98-
const to_be_removed_key =
99-
this.#least_frequently_recently_used_key();
98+
const to_be_removed_key = this
99+
.#least_frequently_recently_used_key();
100100
if (typeof to_be_removed_key === "number") {
101101
this.#delete(to_be_removed_key);
102102
}

mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { uniqueStraightLineEquation } from "./max-points-on-a-line/uniqueStraigh
5757
import { searchSegmentChildren } from "./my-calendar-ii/searchSegmentChildren.ts";
5858
import { searchSegmentLeaf } from "./my-calendar-ii/searchSegmentLeaf.ts";
5959
import { counter } from "./substring-with-concatenation-of-all-words/counter.ts";
60+
import { MyLinkedList } from "./lfu-cache/MyLinkedList.ts";
6061
export {
6162
TrieNode,
6263
TrieNodeCountWordsEqualTo,
@@ -95,3 +96,4 @@ export { cos, dot, norm };
9596
export { abs_bigint, searchSegmentChildren, searchSegmentLeaf };
9697
export { counter };
9798
export { Node as MultilevelDoublyLinkedListNode } from "./flatten-a-multilevel-doubly-linked-list/Node.ts";
99+
export { MyLinkedList };

0 commit comments

Comments
 (0)