nlptoolkit-datastructure 1.0.4 → 1.0.6
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 +1 -1
- package/dist/Queue.d.ts +11 -0
- package/dist/Queue.js +39 -0
- package/dist/Queue.js.map +1 -0
- package/package.json +1 -1
- package/source/Queue.ts +34 -0
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
|
package/dist/Queue.d.ts
ADDED
package/dist/Queue.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
peek() {
|
|
31
|
+
return this.list[this.head];
|
|
32
|
+
}
|
|
33
|
+
isEmpty() {
|
|
34
|
+
return this.head == this.tail;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Queue = Queue;
|
|
38
|
+
});
|
|
39
|
+
//# 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,IAAI;YACP,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QAEM,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QACjC,CAAC;KAEJ;IAjCD,sBAiCC"}
|
package/package.json
CHANGED
package/source/Queue.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 peek(): T{
|
|
27
|
+
return this.list[this.head]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public isEmpty(): boolean{
|
|
31
|
+
return this.head == this.tail
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|