jc-structure 0.2.8 → 0.2.9
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/dist/jc-structure.js +0 -1
- package/index.d.ts +223 -366
- package/package.json +1 -1
- package/types/index.d.ts +4 -0
- package/types/linkedList.d.ts +48 -11
- package/types/lru.d.ts +22 -0
package/dist/jc-structure.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./types/index.d.ts" />
|
|
2
2
|
|
|
3
3
|
declare module "jc-structure" {
|
|
4
|
+
//#region data structure
|
|
4
5
|
/**
|
|
5
6
|
* 栈类,采用object实现
|
|
6
7
|
*/
|
|
@@ -28,393 +29,249 @@ declare module "jc-structure" {
|
|
|
28
29
|
clear(): void;
|
|
29
30
|
toString(): string;
|
|
30
31
|
}
|
|
31
|
-
// interface Queue<T> extends DataStructure {
|
|
32
|
-
// /**
|
|
33
|
-
// * #### 移除队列头部元素并返回该元素
|
|
34
|
-
// */
|
|
35
|
-
// dequeue(): T | undefined;
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// enqueue(...args: Array<T>): this;
|
|
43
|
-
// /**
|
|
44
|
-
// * #### 返回队列头部元素,但不移除
|
|
45
|
-
// */
|
|
46
|
-
// front(): T | undefined;
|
|
47
|
-
// }
|
|
48
|
-
// interface QueueConstructor {
|
|
49
|
-
// new <T>(): Queue<T>;
|
|
50
|
-
// readonly prototype: Queue<T>;
|
|
51
|
-
// }
|
|
52
|
-
// var Queue: QueueConstructor;
|
|
53
|
-
|
|
54
|
-
// type CompareResult = -1 | 0 | 1;
|
|
55
|
-
|
|
56
|
-
// interface CompareFn<T> {
|
|
57
|
-
// (a: T, b: T): CompareResult;
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// interface Obj<V = any> {
|
|
61
|
-
// [key: string]: V;
|
|
62
|
-
// }
|
|
63
|
-
// /**
|
|
64
|
-
// * 最小堆
|
|
65
|
-
// */
|
|
66
|
-
// interface MinHeap<T> extends DataStructure {
|
|
67
|
-
// /**
|
|
68
|
-
// * #### 插入一个值,返回一个布尔值
|
|
69
|
-
// * @param value 要插入的值
|
|
70
|
-
// */
|
|
71
|
-
// insert(value: T): boolean;
|
|
72
|
-
|
|
73
|
-
// /**
|
|
74
|
-
// * #### 移除最小值或最大值,返回该值
|
|
75
|
-
// */
|
|
76
|
-
// extract(): T | undefined;
|
|
77
|
-
|
|
78
|
-
// /**
|
|
79
|
-
// * 查找一个值
|
|
80
|
-
// * @param value 要查找的值
|
|
81
|
-
// */
|
|
82
|
-
// find(): T | undefined;
|
|
83
|
-
// }
|
|
84
|
-
// interface MinHeapConstructor {
|
|
85
|
-
// new <T>(fn?: CompareFn<T>): MinHeap<T>;
|
|
86
|
-
// readonly prototype: MinHeap;
|
|
87
|
-
// }
|
|
88
|
-
// var MinHeap: MinHeapConstructor;
|
|
89
|
-
|
|
90
|
-
// /**
|
|
91
|
-
// * 最大堆
|
|
92
|
-
// */
|
|
93
|
-
// interface MaxConstructor {
|
|
94
|
-
// new <T>(fn?: CompareFn<T>): MinHeap<T>;
|
|
95
|
-
// readonly prototype: MinHeap<T>;
|
|
96
|
-
// }
|
|
97
|
-
// var MaxHeap: MaxConstructor;
|
|
98
|
-
|
|
99
|
-
// /**
|
|
100
|
-
// * LRU缓存类
|
|
101
|
-
// */
|
|
102
|
-
// interface LRU<K, V> {
|
|
103
|
-
// /**
|
|
104
|
-
// * 获取缓存的值
|
|
105
|
-
// * @param key 键值
|
|
106
|
-
// */
|
|
107
|
-
// get(key: K): V | undefined;
|
|
108
|
-
// /**
|
|
109
|
-
// * 更新缓存
|
|
110
|
-
// * @param key 键值
|
|
111
|
-
// * @param value 缓存的值
|
|
112
|
-
// */
|
|
113
|
-
// update(key: K, value: V): void;
|
|
114
|
-
// }
|
|
115
|
-
// interface LRUConstructor {
|
|
116
|
-
// new <K, V>(capacity?: number): LRU<K, V>;
|
|
117
|
-
// readonly prototype: LRU;
|
|
118
|
-
// }
|
|
119
|
-
// var LRU: LRUConstructor;
|
|
120
|
-
|
|
121
|
-
// export class JcNode<T> {
|
|
122
|
-
// value: T;
|
|
123
|
-
// next: JcNode<T> | null;
|
|
124
|
-
// constructor(value: T, next: JcNode<T> | null = null): void;
|
|
125
|
-
// }
|
|
126
|
-
|
|
127
|
-
// export interface ILinkedList<T> {
|
|
128
|
-
// indexOf(element: T): number;
|
|
129
|
-
// getElementAt(index: number): JcNode<T> | null;
|
|
130
|
-
// getValueAt(index: number): T | undefined;
|
|
131
|
-
// insert(element: T, index: number): boolean;
|
|
132
|
-
// push(element: T): void;
|
|
133
|
-
// remove(element: T): T | null;
|
|
134
|
-
// removeAt(index: number): T | null;
|
|
135
|
-
// isEmpty(): boolean;
|
|
136
|
-
// size(): number;
|
|
137
|
-
// clear(): void;
|
|
138
|
-
// toString(): string;
|
|
139
|
-
// toArray(): T[];
|
|
140
|
-
// [Symbol.iterator](): Iterator<T>;
|
|
141
|
-
// }
|
|
142
|
-
|
|
143
|
-
// export class LinkedList<T> implements ILinkedList<T> {
|
|
144
|
-
// constructor(elements?: T[]);
|
|
145
|
-
// }
|
|
146
|
-
|
|
147
|
-
// export type NodeType<T> = JcNode<T>;
|
|
148
|
-
// export type ListType<T> = LinkedList<T>;
|
|
33
|
+
export class JcNode<T> {
|
|
34
|
+
value: T;
|
|
35
|
+
next: JcNode<T> | null;
|
|
36
|
+
constructor(value: T, next: JcNode<T> | null = null): void;
|
|
37
|
+
}
|
|
149
38
|
|
|
150
39
|
/**
|
|
151
|
-
*
|
|
40
|
+
* 双向链表类
|
|
152
41
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// * #### 判断键是否存在
|
|
170
|
-
// * @param key 键
|
|
171
|
-
// */
|
|
172
|
-
// has(key: K): boolean;
|
|
42
|
+
export class LinkedList<T> implements ILinkedList<T> {
|
|
43
|
+
constructor(elements?: T[]): LinkedList<T>;
|
|
44
|
+
indexOf(element: T): number;
|
|
45
|
+
getElementAt(index: number): JcNode<T> | null;
|
|
46
|
+
getValueAt(index: number): T | undefined;
|
|
47
|
+
insert(element: T, index: number): boolean;
|
|
48
|
+
push(element: T): void;
|
|
49
|
+
remove(element: T): T | null;
|
|
50
|
+
removeAt(index: number): T | null;
|
|
51
|
+
isEmpty(): boolean;
|
|
52
|
+
size(): number;
|
|
53
|
+
clear(): void;
|
|
54
|
+
toString(): string;
|
|
55
|
+
toArray(): T[];
|
|
56
|
+
[Symbol.iterator](): Iterator<T>;
|
|
57
|
+
}
|
|
173
58
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
59
|
+
export class MinHeap<T> implements IHeap<T> {
|
|
60
|
+
constructor(compareFn?: CompareFn<T>);
|
|
61
|
+
static swap<T>(arr: T[], index1: number, index2: number): void;
|
|
62
|
+
insert(value: T): boolean;
|
|
63
|
+
extract(): T | undefined;
|
|
64
|
+
find(): T | undefined;
|
|
65
|
+
isEmpty(): boolean;
|
|
66
|
+
size(): number;
|
|
67
|
+
clear(): void;
|
|
68
|
+
toString(): string;
|
|
69
|
+
}
|
|
179
70
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// keys(): Array<K>;
|
|
71
|
+
export class MaxHeap<T> extends MinHeap<T> {
|
|
72
|
+
constructor(compareFn?: CompareFn<T>);
|
|
73
|
+
}
|
|
184
74
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
75
|
+
export class LRU<K, V> implements ILru<K, V> {
|
|
76
|
+
constructor(capacity?: number);
|
|
77
|
+
get(key: K): V | undefined;
|
|
78
|
+
update(key: K, value: V): void;
|
|
79
|
+
}
|
|
189
80
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
81
|
+
export class ValuePair<K, V> {
|
|
82
|
+
key: K;
|
|
83
|
+
value: V;
|
|
84
|
+
constructor(key: K, value: V);
|
|
85
|
+
}
|
|
194
86
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
87
|
+
export class Dictionary<K, V> implements IDictionary<K, V> {
|
|
88
|
+
set(key: K, value: V): void;
|
|
89
|
+
remove(key: K): ValuePair<K, V> | undefined;
|
|
90
|
+
has(key: K): boolean;
|
|
91
|
+
get(key: K): ValuePair<K, V> | undefined;
|
|
92
|
+
keys(): K[];
|
|
93
|
+
values(): V[];
|
|
94
|
+
keyValues(): Array<[K, V]>;
|
|
95
|
+
forEach(callbackFunc: (key: K, value: V) => boolean | void): void;
|
|
96
|
+
isEmpty(): boolean;
|
|
97
|
+
size(): number;
|
|
98
|
+
clear(): void;
|
|
99
|
+
toString(): string;
|
|
100
|
+
}
|
|
200
101
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
// /**
|
|
210
|
-
// * 重写 toString 方法
|
|
211
|
-
// */
|
|
212
|
-
// toString(): string;
|
|
213
|
-
// /**
|
|
214
|
-
// * 清除数据结构元素
|
|
215
|
-
// */
|
|
216
|
-
// clear(): void;
|
|
217
|
-
// }
|
|
102
|
+
export class Graph<T> implements IGraph<T> {
|
|
103
|
+
constructor(isDirected?: boolean);
|
|
104
|
+
addVertex(v: T): void;
|
|
105
|
+
addEdge(v: T, w: T): void;
|
|
106
|
+
getVertices(): T[];
|
|
107
|
+
getAdjacencyList(): Dictionary<T, T[]>;
|
|
108
|
+
toString(): string;
|
|
109
|
+
}
|
|
218
110
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// /**
|
|
225
|
-
// * #### 添加顶点的方法
|
|
226
|
-
// * @param v 顶点
|
|
227
|
-
// */
|
|
228
|
-
// addVertex(v: T): void;
|
|
229
|
-
// /**
|
|
230
|
-
// * #### 添加边的方法
|
|
231
|
-
// * @param v 顶点
|
|
232
|
-
// * @param w
|
|
233
|
-
// */
|
|
234
|
-
// addEdge(v: T, w: T): void;
|
|
235
|
-
// /**
|
|
236
|
-
// * #### 获取顶点集合的方法
|
|
237
|
-
// */
|
|
238
|
-
// getVertices(): Array<T>;
|
|
239
|
-
// /**
|
|
240
|
-
// * #### 获取邻接表的方法
|
|
241
|
-
// */
|
|
242
|
-
// getAdjacencyList(): IDictionary<T, Array<T>>;
|
|
243
|
-
// }
|
|
111
|
+
export class Point {
|
|
112
|
+
constructor(x: number, y: number);
|
|
113
|
+
static distance(p1: Point, p2: Point): number;
|
|
114
|
+
distanceTo(p: Point): number;
|
|
115
|
+
}
|
|
244
116
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
// * #### 计算点与点之间的距离,实例方法
|
|
256
|
-
// * @param p 点p
|
|
257
|
-
// */
|
|
258
|
-
// distanceTo(p: Point): number;
|
|
259
|
-
// }
|
|
260
|
-
// interface PointConstructor {
|
|
261
|
-
// new (x: number, y: number): Point;
|
|
262
|
-
// /**
|
|
263
|
-
// * #### 计算两点之间的距离
|
|
264
|
-
// * @param p1 点1
|
|
265
|
-
// * @param p2 点2
|
|
266
|
-
// */
|
|
267
|
-
// distance(p1: Point, p2: Point): number;
|
|
268
|
-
// }
|
|
269
|
-
// var Point: PointConstructor;
|
|
117
|
+
interface PointConstructor {
|
|
118
|
+
new (x: number, y: number): Point;
|
|
119
|
+
/**
|
|
120
|
+
* #### 计算两点之间的距离
|
|
121
|
+
* @param p1 点1
|
|
122
|
+
* @param p2 点2
|
|
123
|
+
*/
|
|
124
|
+
distance(p1: Point, p2: Point): number;
|
|
125
|
+
}
|
|
126
|
+
var Point: PointConstructor;
|
|
270
127
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
128
|
+
interface Line {
|
|
129
|
+
/**
|
|
130
|
+
* #### 线段长度
|
|
131
|
+
*/
|
|
132
|
+
get length(): number;
|
|
133
|
+
/**
|
|
134
|
+
* #### 线段中点
|
|
135
|
+
*/
|
|
136
|
+
get midpoint(): Point;
|
|
137
|
+
/**
|
|
138
|
+
* #### 线段角度(弧度)
|
|
139
|
+
*/
|
|
140
|
+
get angle(): number;
|
|
141
|
+
/**
|
|
142
|
+
* #### 获取线段的方向向量
|
|
143
|
+
*/
|
|
144
|
+
get direction(): Point;
|
|
145
|
+
/**
|
|
146
|
+
* #### 获取线段的起点
|
|
147
|
+
*/
|
|
148
|
+
get start(): Point;
|
|
149
|
+
/**
|
|
150
|
+
* #### 获取线段的终点
|
|
151
|
+
*/
|
|
152
|
+
get end(): Point;
|
|
153
|
+
/**
|
|
154
|
+
* #### 判断点是否在线段上
|
|
155
|
+
* @param point
|
|
156
|
+
* @param tolerance 容差,默认1e-10
|
|
157
|
+
*/
|
|
158
|
+
containsPoint(point: Point, tolerance?: number): boolean;
|
|
159
|
+
}
|
|
160
|
+
interface LineConstructor {
|
|
161
|
+
new (p1: Point, p2: Point): Line;
|
|
162
|
+
readonly prototype: Line;
|
|
306
163
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
164
|
+
/**
|
|
165
|
+
* #### 判断线段是否平行
|
|
166
|
+
* @param line 线段
|
|
167
|
+
* @param tolerance 容差,默认1e-10
|
|
168
|
+
*/
|
|
169
|
+
sloped(line: Line, tolerance?: number): number | null;
|
|
313
170
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
171
|
+
/**
|
|
172
|
+
* #### 判断线段是否平行
|
|
173
|
+
* @param line1 线段1
|
|
174
|
+
* @param line2 线段2
|
|
175
|
+
* @param tolerance 容差,默认1e-10
|
|
176
|
+
*/
|
|
177
|
+
isParallel(line1: Line, line2: Line, tolerance?: number): boolean;
|
|
321
178
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
179
|
+
/**
|
|
180
|
+
* #### 判断线段是否相交
|
|
181
|
+
* @param line1 线段1
|
|
182
|
+
* @param line2 线段2
|
|
183
|
+
*/
|
|
184
|
+
isIntersecting(line1: Line, line2: Line): boolean;
|
|
328
185
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
186
|
+
/**
|
|
187
|
+
* #### 获取两线段交点
|
|
188
|
+
* @param line1 线段1
|
|
189
|
+
* @param line2 线段2
|
|
190
|
+
* @param tolerance 容差,默认1e-10
|
|
191
|
+
*/
|
|
192
|
+
getIntersection(line1: Line, line2: Line, tolerance?: number): Point | null;
|
|
336
193
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
194
|
+
/**
|
|
195
|
+
* #### 获取线段到点的距离
|
|
196
|
+
* @param line1 线段1
|
|
197
|
+
* @param line2 线段2
|
|
198
|
+
* @param tolerance 容差,默认1e-10
|
|
199
|
+
*/
|
|
200
|
+
distanceToPoint(line: Line, point: Point, tolerance?: number): number;
|
|
201
|
+
}
|
|
202
|
+
var Line: LineConstructor;
|
|
346
203
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
204
|
+
enum TriangleType {
|
|
205
|
+
Equilateral = "equilateral", // 等边
|
|
206
|
+
Isosceles = "isosceles", // 等腰
|
|
207
|
+
Scalene = "scalene", // 不等边
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* ### 三角形类
|
|
211
|
+
*/
|
|
212
|
+
interface Triangle {
|
|
213
|
+
readonly p1: Point;
|
|
214
|
+
readonly p2: Point;
|
|
215
|
+
readonly p3: Point;
|
|
216
|
+
/**
|
|
217
|
+
* #### 获取三角形的边长
|
|
218
|
+
*/
|
|
219
|
+
get side(): [number, number, number];
|
|
220
|
+
/**
|
|
221
|
+
* #### 获取三角形的内心点
|
|
222
|
+
*/
|
|
223
|
+
get centroid(): Point;
|
|
224
|
+
/**
|
|
225
|
+
* #### 获取三角形的外切园心点
|
|
226
|
+
*/
|
|
227
|
+
get circumcenter(): Point;
|
|
228
|
+
/**
|
|
229
|
+
* #### 获取三角形的内切园心点
|
|
230
|
+
*/
|
|
231
|
+
get incenter(): Point;
|
|
232
|
+
/**
|
|
233
|
+
* #### 获取三角形的周长
|
|
234
|
+
*/
|
|
235
|
+
perimeter(): number;
|
|
236
|
+
/**
|
|
237
|
+
* #### 获取三角形的面积
|
|
238
|
+
*/
|
|
239
|
+
area(): number;
|
|
240
|
+
/**
|
|
241
|
+
* #### 判断点是否在三角形内
|
|
242
|
+
* @param point
|
|
243
|
+
*/
|
|
244
|
+
containsPoint(point: Point): boolean;
|
|
245
|
+
}
|
|
246
|
+
interface TriangleConstructor {
|
|
247
|
+
new (p1: Point, p2: Point, p3: Point): Triangle;
|
|
248
|
+
readonly prototype: Triangle;
|
|
392
249
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
250
|
+
/**
|
|
251
|
+
* #### 判断三条边是否能构成三角形
|
|
252
|
+
* @param a
|
|
253
|
+
* @param b
|
|
254
|
+
* @param c
|
|
255
|
+
*/
|
|
256
|
+
isValid(a: number, b: number, c: number): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
|
|
259
|
+
* @param a
|
|
260
|
+
* @param b
|
|
261
|
+
* @param c
|
|
262
|
+
*/
|
|
263
|
+
area(a: number, b: number, c: number): number;
|
|
264
|
+
/**
|
|
265
|
+
* #### 获取三角形的角度
|
|
266
|
+
* @param a
|
|
267
|
+
* @param b
|
|
268
|
+
* @param c
|
|
269
|
+
*/
|
|
270
|
+
getAngles(a: number, b: number, c: number): [number, number, number];
|
|
414
271
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
272
|
+
getTYpe(a: number, b: number, c: number): TriangleType;
|
|
273
|
+
}
|
|
274
|
+
var Triangle: TriangleConstructor;
|
|
418
275
|
|
|
419
276
|
/**
|
|
420
277
|
* ### 向量类
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
package/types/linkedList.d.ts
CHANGED
|
@@ -1,28 +1,65 @@
|
|
|
1
|
-
class JcNode<T> {
|
|
2
|
-
value: T;
|
|
3
|
-
next: JcNode<T> | null;
|
|
4
|
-
constructor(value: T, next: JcNode<T> | null = null): void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
|
-
* ####
|
|
2
|
+
* #### 双向链表接口
|
|
9
3
|
*/
|
|
10
4
|
interface ILinkedList<T> {
|
|
5
|
+
/**
|
|
6
|
+
* #### 查找元素位置
|
|
7
|
+
* @param element 元素
|
|
8
|
+
*/
|
|
11
9
|
indexOf(element: T): number;
|
|
10
|
+
/**
|
|
11
|
+
* #### 获取指定位置的元素
|
|
12
|
+
* @param index 索引
|
|
13
|
+
*/
|
|
12
14
|
getElementAt(index: number): JcNode<T> | null;
|
|
15
|
+
/**
|
|
16
|
+
* #### 获取指定位置的值
|
|
17
|
+
* @param index 索引
|
|
18
|
+
*/
|
|
13
19
|
getValueAt(index: number): T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* #### 在指定位置插入元素
|
|
22
|
+
* @param element 元素
|
|
23
|
+
* @param index 索引
|
|
24
|
+
*/
|
|
14
25
|
insert(element: T, index: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* #### 在链表尾部添加元素
|
|
28
|
+
* @param element 元素
|
|
29
|
+
*/
|
|
15
30
|
push(element: T): void;
|
|
31
|
+
/**
|
|
32
|
+
* #### 删除指定元素
|
|
33
|
+
* @param element 元素
|
|
34
|
+
*/
|
|
16
35
|
remove(element: T): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* #### 删除指定位置的元素
|
|
38
|
+
* @param index 索引
|
|
39
|
+
*/
|
|
17
40
|
removeAt(index: number): T | null;
|
|
41
|
+
/**
|
|
42
|
+
* #### 判断链表是否为空
|
|
43
|
+
*/
|
|
18
44
|
isEmpty(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* #### 获取链表长度
|
|
47
|
+
*/
|
|
19
48
|
size(): number;
|
|
49
|
+
/**
|
|
50
|
+
* #### 清空链表
|
|
51
|
+
*/
|
|
20
52
|
clear(): void;
|
|
53
|
+
/**
|
|
54
|
+
* #### 将链表转换为字符串
|
|
55
|
+
*/
|
|
21
56
|
toString(): string;
|
|
57
|
+
/**
|
|
58
|
+
* #### 将链表转换为数组
|
|
59
|
+
*/
|
|
22
60
|
toArray(): T[];
|
|
61
|
+
/**
|
|
62
|
+
* #### 实现了 [Symbol.iterator] 方法,使链表可以被 for...of 循环遍历
|
|
63
|
+
*/
|
|
23
64
|
[Symbol.iterator](): Iterator<T>;
|
|
24
65
|
}
|
|
25
|
-
|
|
26
|
-
class LinkedList<T> implements ILinkedList<T> {
|
|
27
|
-
constructor(elements?: T[]);
|
|
28
|
-
}
|
package/types/lru.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface LRU_Node<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
prev?: LRU_Node<T>;
|
|
4
|
+
next?: LRU_Node<T>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* #### Least Recently Used Cache
|
|
9
|
+
*/
|
|
10
|
+
interface ILru<K, V> {
|
|
11
|
+
/**
|
|
12
|
+
* #### Get the value of the key
|
|
13
|
+
* @param key
|
|
14
|
+
*/
|
|
15
|
+
get(key: K): V | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* #### Set the value of the key
|
|
18
|
+
* @param key
|
|
19
|
+
* @param value
|
|
20
|
+
*/
|
|
21
|
+
update(key: K, value: V): void;
|
|
22
|
+
}
|