nlptoolkit-datastructure 1.0.4 → 1.0.5

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/README.md CHANGED
@@ -7,7 +7,7 @@ For Developers
7
7
  ============
8
8
 
9
9
  You can also see [Java](https://github.com/starlangsoftware/DataStructure), [Python](https://github.com/starlangsoftware/DataStructure-Py),
10
- [Cython](https://github.com/starlangsoftware/DataStructure-Cy), [Swift](https://github.com/starlangsoftware/DataStructure-Swift),
10
+ [Cython](https://github.com/starlangsoftware/DataStructure-Cy), [Swift](https://github.com/starlangsoftware/DataStructure-Swift), [C](https://github.com/starlangsoftware/DataStructure-C),
11
11
  [C#](https://github.com/starlangsoftware/DataStructure-CS), or [C++](https://github.com/starlangsoftware/DataStructure-CPP) repository.
12
12
 
13
13
  ## Requirements
@@ -0,0 +1,10 @@
1
+ export declare class Queue<T> {
2
+ private list;
3
+ private head;
4
+ private tail;
5
+ private maxSize;
6
+ constructor(maxSize: number);
7
+ enqueue(item: T): void;
8
+ dequeue(): T;
9
+ isEmpty(): boolean;
10
+ }
package/dist/Queue.js ADDED
@@ -0,0 +1,36 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Queue = void 0;
13
+ class Queue {
14
+ constructor(maxSize) {
15
+ this.list = [];
16
+ this.head = 0;
17
+ this.tail = 0;
18
+ this.maxSize = maxSize;
19
+ this.list = new Array(maxSize);
20
+ }
21
+ enqueue(item) {
22
+ this.list[this.tail] = item;
23
+ this.tail = (this.tail + 1) % this.maxSize;
24
+ }
25
+ dequeue() {
26
+ let item = this.list[this.head];
27
+ this.head = (this.head + 1) % this.maxSize;
28
+ return item;
29
+ }
30
+ isEmpty() {
31
+ return this.head == this.tail;
32
+ }
33
+ }
34
+ exports.Queue = Queue;
35
+ });
36
+ //# sourceMappingURL=Queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Queue.js","sourceRoot":"","sources":["../source/Queue.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,MAAa,KAAK;QAOd,YAAY,OAAe;YALnB,SAAI,GAAc,EAAE,CAAA;YAMxB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;YACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;YACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;YACtB,IAAI,CAAC,IAAI,GAAG,IAAI,KAAK,CAAI,OAAO,CAAC,CAAA;QACrC,CAAC;QAEM,OAAO,CAAC,IAAO;YAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YAC3B,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAC9C,CAAC;QAEM,OAAO;YACV,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/B,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;YAC1C,OAAO,IAAI,CAAA;QACf,CAAC;QAEM,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QACjC,CAAC;KAEJ;IA7BD,sBA6BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nlptoolkit-datastructure",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Simple Data Structures Library",
5
5
  "main": "index.js",
6
6
  "types": "index.js",
@@ -0,0 +1,30 @@
1
+ export class Queue<T> {
2
+
3
+ private list : Array<T> = []
4
+ private head : number
5
+ private tail : number
6
+ private maxSize: number
7
+
8
+ constructor(maxSize: number) {
9
+ this.head = 0
10
+ this.tail = 0
11
+ this.maxSize = maxSize
12
+ this.list = new Array<T>(maxSize)
13
+ }
14
+
15
+ public enqueue(item: T){
16
+ this.list[this.tail] = item
17
+ this.tail = (this.tail + 1) % this.maxSize
18
+ }
19
+
20
+ public dequeue(): T{
21
+ let item = this.list[this.head]
22
+ this.head = (this.head + 1) % this.maxSize
23
+ return item
24
+ }
25
+
26
+ public isEmpty(): boolean{
27
+ return this.head == this.tail
28
+ }
29
+
30
+ }