@js-sdsl/priority-queue
Advanced tools
Comparing version 4.1.5 to 4.2.0-beta.0
@@ -1,2 +0,104 @@ | ||
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue"; | ||
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase"; | ||
declare abstract class Base { | ||
/** | ||
* @return The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.size()); // 2 | ||
*/ | ||
size(): number; | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @example | ||
* container.clear(); | ||
* console.log(container.empty()); // true | ||
*/ | ||
empty(): boolean; | ||
/** | ||
* @description Clear the container. | ||
* @example | ||
* container.clear(); | ||
* console.log(container.empty()); // true | ||
*/ | ||
abstract clear(): void; | ||
} | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare class PriorityQueue<T> extends Base { | ||
/** | ||
* @description PriorityQueue's constructor. | ||
* @param container Initialize container, must have a forEach function. | ||
* @param cmp Compare function. | ||
* @param copy When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
* @example | ||
* new PriorityQueue(); | ||
* new PriorityQueue([1, 2, 3]); | ||
* new PriorityQueue([1, 2, 3], (x, y) => x - y); | ||
* new PriorityQueue([1, 2, 3], (x, y) => x - y, false); | ||
*/ | ||
constructor(container?: initContainer<T>, cmp?: (x: T, y: T) => number, copy?: boolean); | ||
clear(): void; | ||
/** | ||
* @description Push element into a container in order. | ||
* @param item The element you want to push. | ||
* @example queue.push(1); | ||
*/ | ||
push(item: T): void; | ||
/** | ||
* @description Removes the top element. | ||
* @example queue.pop(); | ||
*/ | ||
pop(): void; | ||
/** | ||
* @description Accesses the top element. | ||
* @example const top = queue.top(); | ||
*/ | ||
top(): T | undefined; | ||
/** | ||
* @description Check if element is in heap. | ||
* @param item The item want to find. | ||
* @return Boolean about if element is in heap. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* console.log(que.find(obj)); // true | ||
*/ | ||
find(item: T): boolean; | ||
/** | ||
* @description Remove specified item from heap. | ||
* @param item The item want to remove. | ||
* @return Boolean about if remove success. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* que.remove(obj); | ||
*/ | ||
remove(item: T): boolean; | ||
/** | ||
* @description Update item and it's pos in the heap. | ||
* @param item The item want to update. | ||
* @return Boolean about if update success. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* obj.id = 2; | ||
* que.updateItem(obj); | ||
*/ | ||
updateItem(item: T): boolean; | ||
/** | ||
* @return Return a copy array of heap. | ||
* @example const arr = queue.toArray(); | ||
*/ | ||
toArray(): T[]; | ||
} | ||
export { PriorityQueue }; |
@@ -7,15 +7,114 @@ "use strict"; | ||
Object.defineProperty(exports, "PriorityQueue", { | ||
enumerable: true, | ||
get: function() { | ||
return _PriorityQueue.default; | ||
class Base { | ||
constructor() { | ||
this.i = 0; | ||
} | ||
}); | ||
size() { | ||
return this.i; | ||
} | ||
empty() { | ||
return this.i === 0; | ||
} | ||
} | ||
var _PriorityQueue = _interopRequireDefault(require("./container/OtherContainer/PriorityQueue")); | ||
class PriorityQueue extends Base { | ||
constructor(t = [], s = ((t, s) => { | ||
if (t > s) return -1; | ||
if (t < s) return 1; | ||
return 0; | ||
}), i = true) { | ||
super(); | ||
this.h = s; | ||
if (Array.isArray(t)) { | ||
this.u = i ? [ ...t ] : t; | ||
} else { | ||
this.u = []; | ||
t.forEach((t => this.u.push(t))); | ||
} | ||
this.i = this.u.length; | ||
const h = this.i >> 1; | ||
for (let t = this.i - 1 >> 1; t >= 0; --t) { | ||
this.o(t, h); | ||
} | ||
} | ||
l(t) { | ||
const s = this.u[t]; | ||
while (t > 0) { | ||
const i = t - 1 >> 1; | ||
const h = this.u[i]; | ||
if (this.h(h, s) <= 0) break; | ||
this.u[t] = h; | ||
t = i; | ||
} | ||
this.u[t] = s; | ||
} | ||
o(t, s) { | ||
const i = this.u[t]; | ||
while (t < s) { | ||
let s = t << 1 | 1; | ||
const h = s + 1; | ||
let e = this.u[s]; | ||
if (h < this.i && this.h(e, this.u[h]) > 0) { | ||
s = h; | ||
e = this.u[h]; | ||
} | ||
if (this.h(e, i) >= 0) break; | ||
this.u[t] = e; | ||
t = s; | ||
} | ||
this.u[t] = i; | ||
} | ||
clear() { | ||
this.i = 0; | ||
this.u.length = 0; | ||
} | ||
push(t) { | ||
this.u.push(t); | ||
this.l(this.i); | ||
this.i += 1; | ||
} | ||
pop() { | ||
if (!this.i) return; | ||
const t = this.u.pop(); | ||
this.i -= 1; | ||
if (this.i) { | ||
this.u[0] = t; | ||
this.o(0, this.i >> 1); | ||
} | ||
} | ||
top() { | ||
return this.u[0]; | ||
} | ||
find(t) { | ||
return this.u.indexOf(t) >= 0; | ||
} | ||
remove(t) { | ||
const s = this.u.indexOf(t); | ||
if (s < 0) return false; | ||
if (s === 0) { | ||
this.pop(); | ||
} else if (s === this.i - 1) { | ||
this.u.pop(); | ||
this.i -= 1; | ||
} else { | ||
this.u.splice(s, 1, this.u.pop()); | ||
this.i -= 1; | ||
this.l(s); | ||
this.o(s, this.i >> 1); | ||
} | ||
return true; | ||
} | ||
updateItem(t) { | ||
const s = this.u.indexOf(t); | ||
if (s < 0) return false; | ||
this.l(s); | ||
this.o(s, this.i >> 1); | ||
return true; | ||
} | ||
toArray() { | ||
return [ ...this.u ]; | ||
} | ||
} | ||
function _interopRequireDefault(e) { | ||
return e && e.t ? e : { | ||
default: e | ||
}; | ||
} | ||
exports.PriorityQueue = PriorityQueue; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,104 @@ | ||
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue"; | ||
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase"; | ||
declare abstract class Base { | ||
/** | ||
* @return The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.size()); // 2 | ||
*/ | ||
size(): number; | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @example | ||
* container.clear(); | ||
* console.log(container.empty()); // true | ||
*/ | ||
empty(): boolean; | ||
/** | ||
* @description Clear the container. | ||
* @example | ||
* container.clear(); | ||
* console.log(container.empty()); // true | ||
*/ | ||
abstract clear(): void; | ||
} | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare class PriorityQueue<T> extends Base { | ||
/** | ||
* @description PriorityQueue's constructor. | ||
* @param container Initialize container, must have a forEach function. | ||
* @param cmp Compare function. | ||
* @param copy When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
* @example | ||
* new PriorityQueue(); | ||
* new PriorityQueue([1, 2, 3]); | ||
* new PriorityQueue([1, 2, 3], (x, y) => x - y); | ||
* new PriorityQueue([1, 2, 3], (x, y) => x - y, false); | ||
*/ | ||
constructor(container?: initContainer<T>, cmp?: (x: T, y: T) => number, copy?: boolean); | ||
clear(): void; | ||
/** | ||
* @description Push element into a container in order. | ||
* @param item The element you want to push. | ||
* @example queue.push(1); | ||
*/ | ||
push(item: T): void; | ||
/** | ||
* @description Removes the top element. | ||
* @example queue.pop(); | ||
*/ | ||
pop(): void; | ||
/** | ||
* @description Accesses the top element. | ||
* @example const top = queue.top(); | ||
*/ | ||
top(): T | undefined; | ||
/** | ||
* @description Check if element is in heap. | ||
* @param item The item want to find. | ||
* @return Boolean about if element is in heap. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* console.log(que.find(obj)); // true | ||
*/ | ||
find(item: T): boolean; | ||
/** | ||
* @description Remove specified item from heap. | ||
* @param item The item want to remove. | ||
* @return Boolean about if remove success. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* que.remove(obj); | ||
*/ | ||
remove(item: T): boolean; | ||
/** | ||
* @description Update item and it's pos in the heap. | ||
* @param item The item want to update. | ||
* @return Boolean about if update success. | ||
* @example | ||
* const que = new PriorityQueue([], (x, y) => x.id - y.id); | ||
* const obj = { id: 1 }; | ||
* que.push(obj); | ||
* obj.id = 2; | ||
* que.updateItem(obj); | ||
*/ | ||
updateItem(item: T): boolean; | ||
/** | ||
* @return Return a copy array of heap. | ||
* @example const arr = queue.toArray(); | ||
*/ | ||
toArray(): T[]; | ||
} | ||
export { PriorityQueue }; |
@@ -1,1 +0,186 @@ | ||
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue"; | ||
var extendStatics = function(t, i) { | ||
extendStatics = Object.setPrototypeOf || { | ||
__proto__: [] | ||
} instanceof Array && function(t, i) { | ||
t.__proto__ = i; | ||
} || function(t, i) { | ||
for (var r in i) if (Object.prototype.hasOwnProperty.call(i, r)) t[r] = i[r]; | ||
}; | ||
return extendStatics(t, i); | ||
}; | ||
function __extends(t, i) { | ||
if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); | ||
extendStatics(t, i); | ||
function __() { | ||
this.constructor = t; | ||
} | ||
t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); | ||
} | ||
function __read(t, i) { | ||
var r = typeof Symbol === "function" && t[Symbol.iterator]; | ||
if (!r) return t; | ||
var e = r.call(t), n, u = [], s; | ||
try { | ||
while ((i === void 0 || i-- > 0) && !(n = e.next()).done) u.push(n.value); | ||
} catch (t) { | ||
s = { | ||
error: t | ||
}; | ||
} finally { | ||
try { | ||
if (n && !n.done && (r = e["return"])) r.call(e); | ||
} finally { | ||
if (s) throw s.error; | ||
} | ||
} | ||
return u; | ||
} | ||
function __spreadArray(t, i, r) { | ||
if (r || arguments.length === 2) for (var e = 0, n = i.length, u; e < n; e++) { | ||
if (u || !(e in i)) { | ||
if (!u) u = Array.prototype.slice.call(i, 0, e); | ||
u[e] = i[e]; | ||
} | ||
} | ||
return t.concat(u || Array.prototype.slice.call(i)); | ||
} | ||
var Base = function() { | ||
function Base() { | ||
this.t = 0; | ||
} | ||
Base.prototype.size = function() { | ||
return this.t; | ||
}; | ||
Base.prototype.empty = function() { | ||
return this.t === 0; | ||
}; | ||
return Base; | ||
}(); | ||
(function(t) { | ||
__extends(Container, t); | ||
function Container() { | ||
return t !== null && t.apply(this, arguments) || this; | ||
} | ||
return Container; | ||
})(Base); | ||
var PriorityQueue = function(t) { | ||
__extends(PriorityQueue, t); | ||
function PriorityQueue(i, r, e) { | ||
if (i === void 0) { | ||
i = []; | ||
} | ||
if (r === void 0) { | ||
r = function(t, i) { | ||
if (t > i) return -1; | ||
if (t < i) return 1; | ||
return 0; | ||
}; | ||
} | ||
if (e === void 0) { | ||
e = true; | ||
} | ||
var n = t.call(this) || this; | ||
n.i = r; | ||
if (Array.isArray(i)) { | ||
n.u = e ? __spreadArray([], __read(i), false) : i; | ||
} else { | ||
n.u = []; | ||
i.forEach((function(t) { | ||
return n.u.push(t); | ||
})); | ||
} | ||
n.t = n.u.length; | ||
var u = n.t >> 1; | ||
for (var s = n.t - 1 >> 1; s >= 0; --s) { | ||
n.o(s, u); | ||
} | ||
return n; | ||
} | ||
PriorityQueue.prototype.h = function(t) { | ||
var i = this.u[t]; | ||
while (t > 0) { | ||
var r = t - 1 >> 1; | ||
var e = this.u[r]; | ||
if (this.i(e, i) <= 0) break; | ||
this.u[t] = e; | ||
t = r; | ||
} | ||
this.u[t] = i; | ||
}; | ||
PriorityQueue.prototype.o = function(t, i) { | ||
var r = this.u[t]; | ||
while (t < i) { | ||
var e = t << 1 | 1; | ||
var n = e + 1; | ||
var u = this.u[e]; | ||
if (n < this.t && this.i(u, this.u[n]) > 0) { | ||
e = n; | ||
u = this.u[n]; | ||
} | ||
if (this.i(u, r) >= 0) break; | ||
this.u[t] = u; | ||
t = e; | ||
} | ||
this.u[t] = r; | ||
}; | ||
PriorityQueue.prototype.clear = function() { | ||
this.t = 0; | ||
this.u.length = 0; | ||
}; | ||
PriorityQueue.prototype.push = function(t) { | ||
this.u.push(t); | ||
this.h(this.t); | ||
this.t += 1; | ||
}; | ||
PriorityQueue.prototype.pop = function() { | ||
if (!this.t) return; | ||
var t = this.u.pop(); | ||
this.t -= 1; | ||
if (this.t) { | ||
this.u[0] = t; | ||
this.o(0, this.t >> 1); | ||
} | ||
}; | ||
PriorityQueue.prototype.top = function() { | ||
return this.u[0]; | ||
}; | ||
PriorityQueue.prototype.find = function(t) { | ||
return this.u.indexOf(t) >= 0; | ||
}; | ||
PriorityQueue.prototype.remove = function(t) { | ||
var i = this.u.indexOf(t); | ||
if (i < 0) return false; | ||
if (i === 0) { | ||
this.pop(); | ||
} else if (i === this.t - 1) { | ||
this.u.pop(); | ||
this.t -= 1; | ||
} else { | ||
this.u.splice(i, 1, this.u.pop()); | ||
this.t -= 1; | ||
this.h(i); | ||
this.o(i, this.t >> 1); | ||
} | ||
return true; | ||
}; | ||
PriorityQueue.prototype.updateItem = function(t) { | ||
var i = this.u.indexOf(t); | ||
if (i < 0) return false; | ||
this.h(i); | ||
this.o(i, this.t >> 1); | ||
return true; | ||
}; | ||
PriorityQueue.prototype.toArray = function() { | ||
return __spreadArray([], __read(this.u), false); | ||
}; | ||
return PriorityQueue; | ||
}(Base); | ||
export { PriorityQueue }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@js-sdsl/priority-queue", | ||
"version": "4.1.5", | ||
"version": "4.2.0-beta.0", | ||
"description": "javascript standard data structure library which benchmark against C++ STL", | ||
@@ -12,8 +12,2 @@ "main": "./dist/cjs/index.js", | ||
}, | ||
"browserslist": [ | ||
"last 2 version", | ||
"> 1%", | ||
"not dead", | ||
"maintained node versions" | ||
], | ||
"sideEffects": false, | ||
@@ -30,4 +24,5 @@ "homepage": "https://js-sdsl.github.io", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-typescript": "^9.0.2", | ||
"@types/babel__core": "^7.1.19", | ||
"@types/chai": "^4.3.3", | ||
"@types/chai": "^3.5.2", | ||
"@types/delete-empty": "^3.0.2", | ||
@@ -51,7 +46,7 @@ "@types/gulp": "^4.0.9", | ||
"browserslist": "^4.21.3", | ||
"caniuse-lite": "^1.0.30001380", | ||
"chai": "^4.3.6", | ||
"chai": "^3.5.0", | ||
"commitlint": "^17.0.3", | ||
"compare-versions": "^5.0.1", | ||
"conventional-changelog-conventionalcommits": "^5.0.0", | ||
"crypto": "^1.0.1", | ||
"delete-empty": "^3.0.0", | ||
@@ -67,3 +62,2 @@ "eslint": "^8.23.1", | ||
"gulp-rename": "^2.0.0", | ||
"gulp-rollup-2": "^1.3.1", | ||
"gulp-sourcemaps": "^3.0.0", | ||
@@ -77,13 +71,17 @@ "gulp-tap": "^2.0.0", | ||
"karma-chrome-launcher": "^3.1.1", | ||
"karma-edge-launcher": "^0.4.2", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-mocha": "^2.0.1", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-requirejs": "^1.1.0", | ||
"karma-safarinative-launcher": "^1.1.0", | ||
"karma-typescript": "^5.5.3", | ||
"lint-staged": "^13.0.3", | ||
"merge-stream": "^2.0.0", | ||
"mocha": "^10.0.0", | ||
"mocha": "^9.2.2", | ||
"nyc": "^15.1.0", | ||
"requirejs": "^2.3.6", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-typescript2": "^0.33.0", | ||
"rollup-plugin-license": "^3.0.0", | ||
"rollup-plugin-ts": "^3.0.2", | ||
"ts-macros": "^1.3.3", | ||
@@ -90,0 +88,0 @@ "ts-mocha": "^10.0.0", |
137
README.md
@@ -23,28 +23,61 @@ <p align="center"> | ||
## Included data structures | ||
## ✨ Included data structures | ||
- Vector | ||
- Stack | ||
- Queue | ||
- LinkList | ||
- Deque | ||
- PriorityQueue | ||
- OrderedSet (using RBTree) | ||
- OrderedMap (using RBTree) | ||
- HashSet | ||
- HashMap | ||
- **Stack** - first in first out stack. | ||
- **Queue** - first in last out queue. | ||
- **PriorityQueue** - heap-implemented priority queue. | ||
- **Vector** - protected array, cannot to operate properties like `length` directly. | ||
- **LinkList** - linked list of non-contiguous memory addresses. | ||
- **Deque** - double-ended-queue, O(1) time complexity to inserting elements front and back or getting elements by index. | ||
- **OrderedSet** - sorted set which implemented by red black tree. | ||
- **OrderedMap** - sorted map which implemented by red black tree. | ||
- **HashSet** - refer to the hash set implemented by java. | ||
- **HashMap** - refer to the hash map implemented by java. | ||
## Benchmark | ||
## ⚔️ Benchmark | ||
We are benchmarking against other popular data structure libraries. In some ways we're better than the best library. See [benchmark](https://js-sdsl.github.io/#/test/benchmark-analyze). | ||
## Supported platforms | ||
## 🖥 Supported platforms | ||
- node.js (using es6) | ||
- react/vue (using es5) | ||
- browser (support most browsers) | ||
<table> | ||
<tr align="center"> | ||
<td> | ||
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" /> | ||
<div>IE / Edge</div> | ||
</td> | ||
<td> | ||
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" /> | ||
<div>Firefox</div> | ||
</td> | ||
<td> | ||
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" /> | ||
<div>Chrome</div> | ||
</td> | ||
<td> | ||
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" /> | ||
<div>Safari</div> | ||
</td> | ||
<td> | ||
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" /> | ||
<div>Opera</div> | ||
</td> | ||
<td> | ||
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" /> | ||
<div>NodeJs</div> | ||
</td> | ||
</tr> | ||
<tr align="center"> | ||
<td>Edge 12</td> | ||
<td>31</td> | ||
<td>49</td> | ||
<td>10</td> | ||
<td>36</td> | ||
<td>10</td> | ||
</tr> | ||
</table> | ||
## Download | ||
## 📦 Download | ||
Download directly | ||
Download directly by cdn: | ||
@@ -54,3 +87,3 @@ - [js-sdsl.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js) (for development) | ||
Or install js-sdsl using npm | ||
Or install js-sdsl using npm: | ||
@@ -61,4 +94,19 @@ ```bash | ||
## Usage | ||
Or you can download the isolation packages containing only the containers you want: | ||
| package | npm | install | | ||
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------| | ||
| [@js-sdsl/stack](https://js-sdsl.github.io/js-sdsl/classes/Stack.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/stack)](https://www.npmjs.com/package/@js-sdsl/stack) | `npm i @js-sdsl/stack` | | ||
| [@js-sdsl/queue](https://js-sdsl.github.io/js-sdsl/classes/Queue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/queue)](https://www.npmjs.com/package/@js-sdsl/queue) | `npm i @js-sdsl/queue` | | ||
| [@js-sdsl/priority-queue](https://js-sdsl.github.io/js-sdsl/classes/PriorityQueue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/priority-queue)](https://www.npmjs.com/package/@js-sdsl/priority-queue) | `npm i @js-sdsl/priority-queue` | | ||
| [@js-sdsl/vector](https://js-sdsl.github.io/js-sdsl/classes/Vector.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/vector)](https://www.npmjs.com/package/@js-sdsl/vector) | `npm i @js-sdsl/vector` | | ||
| [@js-sdsl/link-list](https://js-sdsl.github.io/js-sdsl/classes/LinkList.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/link-list)](https://www.npmjs.com/package/@js-sdsl/link-list) | `npm i @js-sdsl/link-list` | | ||
| [@js-sdsl/deque](https://js-sdsl.github.io/js-sdsl/classes/Deque.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/deque)](https://www.npmjs.com/package/@js-sdsl/deque) | `npm i @js-sdsl/deque` | | ||
| [@js-sdsl/ordered-set](https://js-sdsl.github.io/js-sdsl/classes/OrderedSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-set)](https://www.npmjs.com/package/@js-sdsl/ordered-set) | `npm i @js-sdsl/ordered-set` | | ||
| [@js-sdsl/ordered-map](https://js-sdsl.github.io/js-sdsl/classes/OrderedMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-map)](https://www.npmjs.com/package/@js-sdsl/ordered-map) | `npm i @js-sdsl/ordered-map` | | ||
| [@js-sdsl/hash-set](https://js-sdsl.github.io/js-sdsl/classes/HashSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-set)](https://www.npmjs.com/package/@js-sdsl/hash-set) | `npm i @js-sdsl/hash-set` | | ||
| [@js-sdsl/hash-map](https://js-sdsl.github.io/js-sdsl/classes/HashMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-map)](https://www.npmjs.com/package/@js-sdsl/hash-map) | `npm i @js-sdsl/hash-map` | | ||
## 🪒 Usage | ||
You can visit our [official website](https://js-sdsl.github.io/) to get more information. | ||
@@ -68,2 +116,10 @@ | ||
For previous versions of the documentation, please visit: | ||
`https://js-sdsl.github.io/js-sdsl/previous/v${version}/index.html` | ||
E.g. | ||
[https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html) | ||
### For browser | ||
@@ -104,8 +160,4 @@ | ||
## Build by source code | ||
## 🛠 Test | ||
You can pull this repository and run `yarn build` to rebuild this library. | ||
## Test | ||
### Unit test | ||
@@ -121,8 +173,21 @@ | ||
## Maintainers | ||
## ⌨️ Development | ||
[@ZLY201](https://github.com/ZLY201) | ||
Use Gitpod, a free online dev environment for GitHub. | ||
## Contributing | ||
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl) | ||
Or clone locally: | ||
```bash | ||
$ git clone https://github.com/js-sdsl/js-sdl.git | ||
$ cd js-sdsl | ||
$ npm install | ||
$ npm run dev # development mode | ||
``` | ||
Then you can see the output in `dist/cjs` folder. | ||
## 🤝 Contributing | ||
Feel free to dive in! Open an issue or submit PRs. It may be helpful to read the [Contributor Guide](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md). | ||
@@ -153,4 +218,16 @@ | ||
## License | ||
## ❤️ Sponsors and Backers | ||
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201 | ||
The special thanks to these sponsors or backers because they provided support at a very early stage: | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.github.io/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
Thanks also give to these sponsors or backers: | ||
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support) | ||
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support) | ||
## 🪪 License | ||
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201) |
@@ -23,16 +23,16 @@ <p align="center"> | ||
## 包含的数据结构 | ||
## ✨ 包含的数据结构 | ||
- Vector | ||
- Stack | ||
- Queue | ||
- LinkList | ||
- Deque | ||
- PriorityQueue | ||
- OrderedSet (using RBTree) | ||
- OrderedMap (using RBTree) | ||
- HashSet | ||
- HashMap | ||
- **Stack** - 先进先出的堆栈 | ||
- **Queue** - 先进后出的队列 | ||
- **PriorityQueue** - 堆实现的优先级队列 | ||
- **Vector** - 受保护的数组,不能直接操作像 `length` 这样的属性 | ||
- **LinkList** - 非连续内存地址的链表 | ||
- **Deque** - 双端队列,向前和向后插入元素或按索引获取元素的 O(1) 时间复杂度 | ||
- **OrderedSet** - 由红黑树实现的排序集合 | ||
- **OrderedMap** - 由红黑树实现的排序字典 | ||
- **HashSet** - 参考 java 实现的哈希集合 | ||
- **HashMap** - 参考 java 实现的哈希字典 | ||
## 基准测试 | ||
## ⚔️ 基准测试 | ||
@@ -43,9 +43,42 @@ 我们和其他数据结构库进行了基准测试,在某些场景我们甚至超过了当前最流行的库 | ||
## 支持的平台 | ||
## 🖥 支持的平台 | ||
- node.js (using es6) | ||
- react/vue (using es5) | ||
- browser (support most browsers) | ||
<table> | ||
<tr align="center"> | ||
<td> | ||
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" /> | ||
<div>IE / Edge</div> | ||
</td> | ||
<td> | ||
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" /> | ||
<div>Firefox</div> | ||
</td> | ||
<td> | ||
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" /> | ||
<div>Chrome</div> | ||
</td> | ||
<td> | ||
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" /> | ||
<div>Safari</div> | ||
</td> | ||
<td> | ||
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" /> | ||
<div>Opera</div> | ||
</td> | ||
<td> | ||
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" /> | ||
<div>NodeJs</div> | ||
</td> | ||
</tr> | ||
<tr align="center"> | ||
<td>Edge 12</td> | ||
<td>31</td> | ||
<td>49</td> | ||
<td>10</td> | ||
<td>36</td> | ||
<td>10</td> | ||
</tr> | ||
</table> | ||
## 下载 | ||
## 📦 下载 | ||
@@ -63,4 +96,19 @@ 使用 cdn 直接引入 | ||
## 使用说明 | ||
或者根据需要安装以下任意单个包 | ||
| package | npm | install | | ||
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------| | ||
| [@js-sdsl/stack](https://js-sdsl.github.io/js-sdsl/classes/Stack.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/stack)](https://www.npmjs.com/package/@js-sdsl/stack) | `npm i @js-sdsl/stack` | | ||
| [@js-sdsl/queue](https://js-sdsl.github.io/js-sdsl/classes/Queue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/queue)](https://www.npmjs.com/package/@js-sdsl/queue) | `npm i @js-sdsl/queue` | | ||
| [@js-sdsl/priority-queue](https://js-sdsl.github.io/js-sdsl/classes/PriorityQueue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/priority-queue)](https://www.npmjs.com/package/@js-sdsl/priority-queue) | `npm i @js-sdsl/priority-queue` | | ||
| [@js-sdsl/vector](https://js-sdsl.github.io/js-sdsl/classes/Vector.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/vector)](https://www.npmjs.com/package/@js-sdsl/vector) | `npm i @js-sdsl/vector` | | ||
| [@js-sdsl/link-list](https://js-sdsl.github.io/js-sdsl/classes/LinkList.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/link-list)](https://www.npmjs.com/package/@js-sdsl/link-list) | `npm i @js-sdsl/link-list` | | ||
| [@js-sdsl/deque](https://js-sdsl.github.io/js-sdsl/classes/Deque.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/deque)](https://www.npmjs.com/package/@js-sdsl/deque) | `npm i @js-sdsl/deque` | | ||
| [@js-sdsl/ordered-set](https://js-sdsl.github.io/js-sdsl/classes/OrderedSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-set)](https://www.npmjs.com/package/@js-sdsl/ordered-set) | `npm i @js-sdsl/ordered-set` | | ||
| [@js-sdsl/ordered-map](https://js-sdsl.github.io/js-sdsl/classes/OrderedMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-map)](https://www.npmjs.com/package/@js-sdsl/ordered-map) | `npm i @js-sdsl/ordered-map` | | ||
| [@js-sdsl/hash-set](https://js-sdsl.github.io/js-sdsl/classes/HashSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-set)](https://www.npmjs.com/package/@js-sdsl/hash-set) | `npm i @js-sdsl/hash-set` | | ||
| [@js-sdsl/hash-map](https://js-sdsl.github.io/js-sdsl/classes/HashMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-map)](https://www.npmjs.com/package/@js-sdsl/hash-map) | `npm i @js-sdsl/hash-map` | | ||
## 🪒 使用说明 | ||
您可以[访问我们的主页](https://js-sdsl.github.io/)获取更多信息 | ||
@@ -70,2 +118,10 @@ | ||
想要查看从前版本的文档,请访问: | ||
`https://js-sdsl.github.io/js-sdsl/previous/v${version}/index.html` | ||
例如: | ||
[https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html) | ||
### 在浏览器中使用 | ||
@@ -106,8 +162,4 @@ | ||
## 从源码构建 | ||
## 🛠 测试 | ||
您可以克隆此仓库后运行 `yarn build` 命令重新构建这个库 | ||
## 测试 | ||
### 单元测试 | ||
@@ -123,8 +175,21 @@ | ||
## 维护者 | ||
## ⌨️ 开发 | ||
[@ZLY201](https://github.com/ZLY201) | ||
可以使用 Gitpod 进行在线编辑: | ||
## 贡献 | ||
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl) | ||
或者在本地使用以下命令获取源码进行开发: | ||
```bash | ||
$ git clone https://github.com/js-sdsl/js-sdl.git | ||
$ cd js-sdsl | ||
$ npm install | ||
$ npm run dev # development mode | ||
``` | ||
之后您在 `dist/cjs` 文件夹中可以看到在 `dev` 模式下打包生成的产物 | ||
## 🤝 贡献 | ||
我们欢迎所有的开发人员提交 issue 或 pull request,阅读[贡献者指南](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md)可能会有所帮助 | ||
@@ -155,4 +220,16 @@ | ||
## 许可证 | ||
## ❤️ 赞助者 | ||
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201 | ||
特别鸣谢下列赞助商和支持者们,他们在非常早期的时候为我们提供了支持: | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.github.io/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
同样感谢这些赞助商和支持者们: | ||
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support) | ||
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support) | ||
## 🪪 许可证 | ||
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
118548
809
227
72
13
1
1