jc-structure 0.0.1 → 0.0.3

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
@@ -12,7 +12,7 @@ interface Structure {
12
12
  */
13
13
  clear(): void;
14
14
  /**
15
- * 数据结构字符串表示
15
+ * 重写 toString 方法
16
16
  */
17
17
  toString(): string;
18
18
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -30,10 +30,12 @@
30
30
  },
31
31
  "scripts": {
32
32
  "dev": "vite",
33
- "build": "tsc && vite build"
33
+ "build": "tsc && vite build",
34
+ "test": "vitest"
34
35
  },
35
36
  "devDependencies": {
36
37
  "typescript": "~5.9.2",
37
- "vite": "^7.1.5"
38
+ "vite": "^7.1.5",
39
+ "vitest": "^4.0.15"
38
40
  }
39
41
  }
@@ -0,0 +1,16 @@
1
+ interface IQueue<T> extends Structure {
2
+ /**
3
+ * #### 移除队列头部元素并返回该元素
4
+ */
5
+ dequeue(): T | undefined;
6
+
7
+ /**
8
+ * #### 向队列末尾添加元素
9
+ * @param args 要添加的元素
10
+ */
11
+ enqueue(...args: Array<T>): void;
12
+ /**
13
+ * #### 返回队列头部元素,但不移除
14
+ */
15
+ front(): T | undefined;
16
+ }
package/types/stack.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- interface StackObj<T> {
1
+ interface StructureObj<T> {
2
2
  [key: number]: T;
3
3
  }
4
4
 
5
5
  interface IStack<T> extends Structure {
6
6
  /**
7
- * 移除栈顶元素并返回该元素
7
+ * #### 移除栈顶元素并返回该元素
8
8
  */
9
9
  pop(): T | undefined;
10
10