Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@js-sdsl/stack

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-sdsl/stack - npm Package Compare versions

Comparing version 4.1.5 to 4.2.0-beta.0

dist/cjs/index.js.map

51

dist/cjs/index.d.ts

@@ -1,2 +0,49 @@

export { default as Stack } from "./container/OtherContainer/Stack";
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 Stack<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Insert element to stack's end.
*/
push(element: T): void;
/**
* @description Removes the end element.
*/
pop(): void;
/**
* @description Accesses the end element.
*/
top(): T | undefined;
}
export { Stack };

45

dist/cjs/index.js

@@ -7,15 +7,38 @@ "use strict";

Object.defineProperty(exports, "Stack", {
enumerable: true,
get: function() {
return _Stack.default;
class Base {
constructor() {
this.i = 0;
}
});
size() {
return this.i;
}
empty() {
return this.i === 0;
}
}
var _Stack = _interopRequireDefault(require("./container/OtherContainer/Stack"));
class Stack extends Base {
constructor(t = []) {
super();
this.h = [];
t.forEach((t => this.push(t)));
}
clear() {
this.i = 0;
this.h.length = 0;
}
push(t) {
this.h.push(t);
this.i += 1;
}
pop() {
this.h.pop();
if (this.i > 0) this.i -= 1;
}
top() {
return this.h[this.i - 1];
}
}
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
exports.Stack = Stack;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,49 @@

export { default as Stack } from "./container/OtherContainer/Stack";
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 Stack<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Insert element to stack's end.
*/
push(element: T): void;
/**
* @description Removes the end element.
*/
pop(): void;
/**
* @description Accesses the end element.
*/
top(): T | undefined;
}
export { Stack };

@@ -1,1 +0,74 @@

export { default as Stack } from "./container/OtherContainer/Stack";
var extendStatics = function(t, n) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, n) {
t.__proto__ = n;
} || function(t, n) {
for (var i in n) if (Object.prototype.hasOwnProperty.call(n, i)) t[i] = n[i];
};
return extendStatics(t, n);
};
function __extends(t, n) {
if (typeof n !== "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
extendStatics(t, n);
function __() {
this.constructor = t;
}
t.prototype = n === null ? Object.create(n) : (__.prototype = n.prototype, new __);
}
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 Stack = function(t) {
__extends(Stack, t);
function Stack(n) {
if (n === void 0) {
n = [];
}
var i = t.call(this) || this;
i.i = [];
n.forEach((function(t) {
return i.push(t);
}));
return i;
}
Stack.prototype.clear = function() {
this.t = 0;
this.i.length = 0;
};
Stack.prototype.push = function(t) {
this.i.push(t);
this.t += 1;
};
Stack.prototype.pop = function() {
this.i.pop();
if (this.t > 0) this.t -= 1;
};
Stack.prototype.top = function() {
return this.i[this.t - 1];
};
return Stack;
}(Base);
export { Stack };
//# sourceMappingURL=index.js.map
{
"name": "@js-sdsl/stack",
"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",

@@ -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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc