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.
@@ -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 Stack
66
+ e as Queue,
67
+ o as Stack
35
68
  };
@@ -1 +1 @@
1
- (function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t["jc-structure"]={}))})(this,(function(t){"use strict";class i{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const e=this.items[this.count];return delete this.items[this.count],e}push(...e){e.forEach(s=>{this.items[this.count]=s,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.Stack=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
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
- interface Structure {
2
- /**
3
- * 判断数据结构是否为空
4
- */
5
- isEmpty(): boolean;
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -0,0 +1,18 @@
1
+ interface Structure {
2
+ /**
3
+ * 判断数据结构是否为空
4
+ */
5
+ isEmpty(): boolean;
6
+ /**
7
+ * 数据结构元素长度
8
+ */
9
+ size(): number;
10
+ /**
11
+ * 清除数据结构元素
12
+ */
13
+ clear(): void;
14
+ /**
15
+ * 重写 toString 方法
16
+ */
17
+ toString(): string;
18
+ }