jc-structure 0.0.2 → 0.0.4
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 +34 -1
- package/dist/jc-structure.umd.cjs +1 -1
- package/index.d.ts +5 -17
- package/package.json +1 -1
- package/types/global.d.ts +18 -0
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
class e {
|
|
2
|
+
items = {};
|
|
3
|
+
count = 0;
|
|
4
|
+
lowestCount = 0;
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
dequeue() {
|
|
8
|
+
if (this.isEmpty()) return;
|
|
9
|
+
const t = this.items[this.lowestCount];
|
|
10
|
+
return delete this.items[this.lowestCount], this.lowestCount++, t;
|
|
11
|
+
}
|
|
12
|
+
enqueue(...t) {
|
|
13
|
+
t.forEach((s) => {
|
|
14
|
+
this.items[this.count] = s, this.count++;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
front() {
|
|
18
|
+
return this.isEmpty() ? void 0 : this.items[this.lowestCount];
|
|
19
|
+
}
|
|
20
|
+
isEmpty() {
|
|
21
|
+
return this.size() === 0;
|
|
22
|
+
}
|
|
23
|
+
size() {
|
|
24
|
+
return this.count - this.lowestCount;
|
|
25
|
+
}
|
|
26
|
+
clear() {
|
|
27
|
+
this.items = {}, this.count = 0, this.lowestCount = 0;
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class o {
|
|
2
34
|
items = {};
|
|
3
35
|
count = 0;
|
|
4
36
|
constructor() {
|
|
@@ -31,5 +63,6 @@ class e {
|
|
|
31
63
|
}
|
|
32
64
|
}
|
|
33
65
|
export {
|
|
34
|
-
e as
|
|
66
|
+
e as Queue,
|
|
67
|
+
o as Stack
|
|
35
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t["jc-structure"]={}))})(this,(function(t){"use strict";class e{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const s=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,s}enqueue(...s){s.forEach(i=>{this.items[this.count]=i,this.count++})}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class u{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const s=this.items[this.count];return delete this.items[this.count],s}push(...s){s.forEach(i=>{this.items[this.count]=i,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}t.Queue=e,t.Stack=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 数据结构元素长度
|
|
8
|
-
*/
|
|
9
|
-
size(): number;
|
|
10
|
-
/**
|
|
11
|
-
* 清除数据结构元素
|
|
12
|
-
*/
|
|
13
|
-
clear(): void;
|
|
14
|
-
/**
|
|
15
|
-
* 重写 toString 方法
|
|
16
|
-
*/
|
|
17
|
-
toString(): string;
|
|
1
|
+
declare module "jc-structure" {
|
|
2
|
+
class Stack<T> implements IStack<T> {}
|
|
3
|
+
|
|
4
|
+
class Queue<T> implements IQueue<T> {}
|
|
5
|
+
export { Stack, Queue };
|
|
18
6
|
}
|
package/package.json
CHANGED