jc-structure 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,26 +1,74 @@
1
1
  declare module "jc-structure" {
2
- import type { IStack } from "./types/stack";
3
- import type { IQueue } from "./types/queue";
4
- import type { IHeap } from "./types/heap";
2
+ interface Structure {
3
+ /**
4
+ * 判断数据结构是否为空
5
+ */
6
+ isEmpty(): boolean;
7
+ /**
8
+ * 数据结构元素长度
9
+ */
10
+ size(): number;
11
+ /**
12
+ * 清除数据结构元素
13
+ */
14
+ clear(): void;
15
+ /**
16
+ * 重写 toString 方法
17
+ */
18
+ toString(): string;
19
+ }
5
20
  /**
6
21
  * 栈类,采用object实现
7
22
  */
8
- interface Stack<T> extends IStack<T> {}
23
+ interface Stack<T> extends Structure {
24
+ /**
25
+ * #### 移除栈顶元素并返回该元素
26
+ */
27
+ pop(): T | undefined;
28
+
29
+ /**
30
+ * #### 向栈顶添加元素
31
+ * @param args 要添加的元素,key可以是多个或一个元素。
32
+ */
33
+ push(items: T | Array<T>): this;
34
+ push(...args: Array<T>): this;
35
+
36
+ /**
37
+ * #### 返回栈顶元素,但不移除
38
+ */
39
+ peek(): T | undefined;
40
+ }
9
41
  interface StackConstructor {
10
42
  new <T>(): Stack<T>;
11
43
  readonly prototype: Stack<T>;
12
44
  }
13
- declare const Stack: StackConstructor;
45
+ declare var Stack: StackConstructor;
14
46
 
15
47
  /**
16
48
  * 队列类,采用object实现
17
49
  */
18
- interface Queue<T> extends IQueue<T> {}
50
+ interface Queue<T> extends Structure {
51
+ /**
52
+ * #### 移除队列头部元素并返回该元素
53
+ */
54
+ dequeue(): T | undefined;
55
+
56
+ /**
57
+ * #### 向队列末尾添加元素
58
+ * @param args 要添加的元素
59
+ */
60
+ enqueue(items: T | Array<T>): this;
61
+ enqueue(...args: Array<T>): this;
62
+ /**
63
+ * #### 返回队列头部元素,但不移除
64
+ */
65
+ front(): T | undefined;
66
+ }
19
67
  interface QueueConstructor {
20
68
  new <T>(): Queue<T>;
21
69
  readonly prototype: Queue<T>;
22
70
  }
23
- declare const Queue: QueueConstructor;
71
+ declare var Queue: QueueConstructor;
24
72
 
25
73
  type CompareResult = -1 | 0 | 1;
26
74
 
@@ -34,21 +82,38 @@ declare module "jc-structure" {
34
82
  /**
35
83
  * 最小堆
36
84
  */
37
- interface MinHeap<T> extends IHeap<T> {}
85
+ interface MinHeap<T> extends Structure {
86
+ /**
87
+ * #### 插入一个值,返回一个布尔值
88
+ * @param value 要插入的值
89
+ */
90
+ insert(value: T): boolean;
91
+
92
+ /**
93
+ * #### 移除最小值或最大值,返回该值
94
+ */
95
+ extract(): T | undefined;
96
+
97
+ /**
98
+ * 查找一个值
99
+ * @param value 要查找的值
100
+ */
101
+ find(): T | undefined;
102
+ }
38
103
  interface MinHeapConstructor {
39
104
  new <T>(fn?: CompareFn<T>): MinHeap<T>;
40
105
  readonly prototype: MinHeap<T>;
41
106
  }
42
- declare const MinHeap: MinHeapConstructor;
107
+ declare var MinHeap: MinHeapConstructor;
43
108
 
44
109
  /**
45
110
  * 最大堆
46
111
  */
47
- interface Constructor {
112
+ interface MaxConstructor {
48
113
  new <T>(fn?: CompareFn<T>): MinHeap<T>;
49
114
  readonly prototype: MinHeap<T>;
50
115
  }
51
- declare const MaxHeap: Constructor;
116
+ declare var MaxHeap: MaxConstructor;
52
117
  /**
53
118
  * LRU缓存类
54
119
  */
@@ -69,7 +134,7 @@ declare module "jc-structure" {
69
134
  new <K, V>(capacity?: number): LRU<K, V>;
70
135
  readonly prototype: LRU<K, V>;
71
136
  }
72
- declare const LRU: LRUConstructor;
137
+ declare var LRU: LRUConstructor;
73
138
 
74
139
  /**
75
140
  * 链表节点类
@@ -269,7 +334,7 @@ declare module "jc-structure" {
269
334
  */
270
335
  toRoman(num: number): string;
271
336
  }
272
- declare const Roman: RomanConstructor;
337
+ declare var Roman: RomanConstructor;
273
338
 
274
339
  interface Point {
275
340
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
package/types/global.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare interface Structure {
1
+ interface Structure {
2
2
  /**
3
3
  * 判断数据结构是否为空
4
4
  */
@@ -19,10 +19,16 @@ export declare interface Structure {
19
19
 
20
20
  type CompareResult = -1 | 0 | 1;
21
21
 
22
+ /**
23
+ * #### 比较函数接口
24
+ */
22
25
  interface CompareFn<T> {
23
26
  (a: T, b: T): CompareResult;
24
27
  }
25
28
 
29
+ /**
30
+ * #### 对象接口,用于存储数据结构元素,值类型默认为 any
31
+ */
26
32
  interface Obj<V = any> {
27
33
  [key: string]: V;
28
34
  }
package/types/heap.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- // import type { Structure } from "./global";
2
-
3
- export declare interface IHeap<T> extends Structure {
1
+ /**
2
+ * #### 堆
3
+ */
4
+ interface IHeap<T> extends Structure {
4
5
  /**
5
6
  * #### 插入一个值,返回一个布尔值
6
7
  * @param value 要插入的值
package/types/queue.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * #### 队列接口
3
3
  */
4
- export declare interface IQueue<T> extends Structure {
4
+ interface IQueue<T> extends Structure {
5
5
  /**
6
6
  * #### 移除队列头部元素并返回该元素
7
7
  */
package/types/stack.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import type { Structure } from "./global";
2
-
3
- export interface StructureObj<T> {
1
+ interface StructureObj<T> {
4
2
  [key: number]: T;
5
3
  }
6
4
 
7
5
  /**
8
6
  * #### 栈接口
9
7
  */
10
- export declare interface IStack<T> extends Structure {
8
+ interface IStack<T> extends Structure {
11
9
  /**
12
10
  * #### 移除栈顶元素并返回该元素
13
11
  */