06b10d8a24213c7eb8895a647978280908bf4d877d42228c205305ea53b08ea44a91da1050b1f675b5ba811ee40dc1c38322934433240cd89e2467c9ccaf9f 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <p align="center">
  2. <a href="https://js-sdsl.org/" target="_blank" rel="noopener noreferrer">
  3. <img src="https://js-sdsl.org/assets/image/logo/logo-removebg.png" alt="js-sdsl logo" width="120" />
  4. </a>
  5. </p>
  6. <h3><p align="center">A javascript standard data structure library which benchmark against C++ STL</p></h3>
  7. <p align="center">
  8. <a href="https://www.npmjs.com/package/js-sdsl"><img src="https://img.shields.io/npm/v/js-sdsl.svg" alt="NPM Version" /></a>
  9. <a href="https://github.com/js-sdsl/js-sdsl/actions/workflows/build.yml"><img src="https://img.shields.io/github/actions/workflow/status/js-sdsl/js-sdsl/build.yml" alt="Build Status" /></a>
  10. <a href='https://coveralls.io/github/js-sdsl/js-sdsl?branch=main'><img src='https://coveralls.io/repos/github/js-sdsl/js-sdsl/badge.svg?branch=main' alt='Coverage Status' /></a>
  11. <a href="https://github.com/js-sdsl/js-sdsl"><img src="https://img.shields.io/github/stars/js-sdsl/js-sdsl.svg" alt="GITHUB Star" /></a>
  12. <a href="https://npmcharts.com/compare/js-sdsl?minimal=true"><img src="https://img.shields.io/npm/dm/js-sdsl.svg" alt="NPM Downloads" /></a>
  13. <a href="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"><img src="https://img.badgesize.io/https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js?compression=gzip&style=flat-square/" alt="Gzip Size"></a>
  14. <a href="https://openbase.com/js/js-sdsl?utm_source=embedded&amp;utm_medium=badge&amp;utm_campaign=rate-badge"><img src="https://badges.openbase.com/js/rating/js-sdsl.svg?token=fh3LMNOV+JSWykSjtg1rA8kouSYkJoIDzGbvaByq5X0=" alt="Rate this package"/></a>
  15. <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/js-sdsl.svg" alt="MIT-license" /></a>
  16. <a href="https://github.com/js-sdsl/js-sdsl/"><img src="https://img.shields.io/github/languages/top/js-sdsl/js-sdsl.svg" alt="GITHUB-language" /></a>
  17. </p>
  18. <p align="center">English | <a href="https://github.com/js-sdsl/js-sdsl/blob/main/README.zh-CN.md">简体中文</a></p>
  19. ## ✨ Included data structures
  20. - **Stack** - first in last out stack.
  21. - **Queue** - first in first out queue.
  22. - **PriorityQueue** - heap-implemented priority queue.
  23. - **Vector** - protected array, cannot to operate properties like `length` directly.
  24. - **LinkList** - linked list of non-contiguous memory addresses.
  25. - **Deque** - double-ended-queue, O(1) time complexity to `unshift` or getting elements by index.
  26. - **OrderedSet** - sorted set which implemented by red black tree.
  27. - **OrderedMap** - sorted map which implemented by red black tree.
  28. - **HashSet** - refer to the [polyfill of ES6 Set](https://github.com/rousan/collections-es6).
  29. - **HashMap** - refer to the [polyfill of ES6 Map](https://github.com/rousan/collections-es6).
  30. ## ⚔️ Benchmark
  31. We are benchmarking against other popular data structure libraries. In some ways we're better than the best library. See [benchmark](https://js-sdsl.org/#/test/benchmark-analyze).
  32. ## 🖥 Supported platforms
  33. <table>
  34. <tr align="center">
  35. <td>
  36. <img alt="IE / Edge" src="https://js-sdsl.org/assets/image/platform/edge.png" />
  37. <div>IE / Edge</div>
  38. </td>
  39. <td>
  40. <img alt="Firefox" src="https://js-sdsl.org/assets/image/platform/firefox.png" />
  41. <div>Firefox</div>
  42. </td>
  43. <td>
  44. <img alt="Chrome" src="https://js-sdsl.org/assets/image/platform/chrome.png" />
  45. <div>Chrome</div>
  46. </td>
  47. <td>
  48. <img alt="Safari" src="https://js-sdsl.org/assets/image/platform/safari.png" />
  49. <div>Safari</div>
  50. </td>
  51. <td>
  52. <img alt="Opera" src="https://js-sdsl.org/assets/image/platform/opera.png" />
  53. <div>Opera</div>
  54. </td>
  55. <td>
  56. <img alt="NodeJs" src="https://js-sdsl.org/assets/image/platform/nodejs.png" />
  57. <div>NodeJs</div>
  58. </td>
  59. </tr>
  60. <tr align="center">
  61. <td>Edge 12</td>
  62. <td>31</td>
  63. <td>49</td>
  64. <td>10</td>
  65. <td>36</td>
  66. <td>10</td>
  67. </tr>
  68. </table>
  69. ## 📦 Download
  70. Download directly by cdn:
  71. - [js-sdsl.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js) (for development)
  72. - [js-sdsl.min.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js) (for production)
  73. Or install js-sdsl using npm:
  74. ```bash
  75. npm install js-sdsl
  76. ```
  77. Or you can download the isolation packages containing only the containers you want:
  78. | package | npm | size | docs |
  79. |---------------------------------------------------|-----------------------------------------------------------------------|------------------------------------------------------------------|-----------------------------|
  80. | [@js-sdsl/stack][stack-package] | [![NPM Package][stack-npm-version]][stack-npm-link] | [![GZIP Size][stack-umd-size]][stack-umd-link] | [link][stack-docs] |
  81. | [@js-sdsl/queue][queue-package] | [![NPM Package][queue-npm-version]][queue-npm-link] | [![GZIP Size][queue-umd-size]][queue-umd-link] | [link][queue-docs] |
  82. | [@js-sdsl/priority-queue][priority-queue-package] | [![NPM Package][priority-queue-npm-version]][priority-queue-npm-link] | [![GZIP Size][priority-queue-umd-size]][priority-queue-umd-link] | [link][priority-queue-docs] |
  83. | [@js-sdsl/vector][vector-package] | [![NPM Package][vector-npm-version]][vector-npm-link] | [![GZIP Size][vector-umd-size]][vector-umd-link] | [link][vector-docs] |
  84. | [@js-sdsl/link-list][link-list-package] | [![NPM Package][link-list-npm-version]][link-list-npm-link] | [![GZIP Size][link-list-umd-size]][link-list-umd-link] | [link][link-list-docs] |
  85. | [@js-sdsl/deque][deque-package] | [![NPM Package][deque-npm-version]][deque-npm-link] | [![GZIP Size][deque-umd-size]][deque-umd-link] | [link][deque-docs] |
  86. | [@js-sdsl/ordered-set][ordered-set-package] | [![NPM Package][ordered-set-npm-version]][ordered-set-npm-link] | [![GZIP Size][ordered-set-umd-size]][ordered-set-umd-link] | [link][ordered-set-docs] |
  87. | [@js-sdsl/ordered-map][ordered-map-package] | [![NPM Package][ordered-map-npm-version]][ordered-map-npm-link] | [![GZIP Size][ordered-map-umd-size]][ordered-map-umd-link] | [link][ordered-map-docs] |
  88. | [@js-sdsl/hash-set][hash-set-package] | [![NPM Package][hash-set-npm-version]][hash-set-npm-link] | [![GZIP Size][hash-set-umd-size]][hash-set-umd-link] | [link][hash-set-docs] |
  89. | [@js-sdsl/hash-map][hash-map-package] | [![NPM Package][hash-map-npm-version]][hash-map-npm-link] | [![GZIP Size][hash-map-umd-size]][hash-map-umd-link] | [link][hash-map-docs] |
  90. ## 🪒 Usage
  91. You can visit our [official website](https://js-sdsl.org/) to get more information.
  92. To help you have a better use, we also provide this [API document](https://js-sdsl.org/js-sdsl/index.html).
  93. For previous versions of the documentation, please visit:
  94. `https://js-sdsl.org/js-sdsl/previous/v${version}/index.html`
  95. E.g.
  96. [https://js-sdsl.org/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.org/js-sdsl/previous/v4.1.5/index.html)
  97. ### For browser
  98. ```html
  99. <script src="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"></script>
  100. <script>
  101. const {
  102. Vector,
  103. Stack,
  104. Queue,
  105. LinkList,
  106. Deque,
  107. PriorityQueue,
  108. OrderedSet,
  109. OrderedMap,
  110. HashSet,
  111. HashMap
  112. } = sdsl;
  113. const myOrderedMap = new OrderedMap();
  114. myOrderedMap.setElement(1, 2);
  115. console.log(myOrderedMap.getElementByKey(1)); // 2
  116. </script>
  117. ```
  118. ### For npm
  119. ```javascript
  120. // esModule
  121. import { OrderedMap } from 'js-sdsl';
  122. // commonJs
  123. const { OrderedMap } = require('js-sdsl');
  124. const myOrderedMap = new OrderedMap();
  125. myOrderedMap.setElement(1, 2);
  126. console.log(myOrderedMap.getElementByKey(1)); // 2
  127. ```
  128. ## 🛠 Test
  129. ### Unit test
  130. We use [karma](https://karma-runner.github.io/) and [mocha](https://mochajs.org/) frame to do unit tests and synchronize to [coveralls](https://coveralls.io/github/js-sdsl/js-sdsl). You can run `yarn test:unit` command to reproduce it.
  131. ### For performance
  132. We tested most of the functions for efficiency. You can go to [`gh-pages/performance.md`](https://github.com/js-sdsl/js-sdsl/blob/gh-pages/performance.md) to see our running results or reproduce it with `yarn test:performance` command.
  133. You can also visit [here](https://js-sdsl.org/#/test/performance-test) to get the result.
  134. ## ⌨️ Development
  135. Use Gitpod, a free online dev environment for GitHub.
  136. [![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl)
  137. Or clone locally:
  138. ```bash
  139. $ git clone https://github.com/js-sdsl/js-sdsl.git
  140. $ cd js-sdsl
  141. $ npm install
  142. $ npm run dev # development mode
  143. ```
  144. Then you can see the output in `dist/cjs` folder.
  145. ## 🤝 Contributing
  146. 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).
  147. ### Contributors
  148. Thanks goes to these wonderful people:
  149. <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
  150. <!-- prettier-ignore-start -->
  151. <!-- markdownlint-disable -->
  152. <table>
  153. <tbody>
  154. <tr>
  155. <td align="center"><a href="https://www.linkedin.com/in/takatoshi-kondo-02a91410/"><img src="https://avatars.githubusercontent.com/u/275959?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Takatoshi Kondo</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Code">💻</a> <a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Tests">⚠️</a></td>
  156. <td align="center"><a href="https://www.youtube.com/c/noname0310"><img src="https://avatars.githubusercontent.com/u/48761044?v=4?s=100" width="100px;" alt=""/><br /><sub><b>noname</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=noname0310" title="Code">💻</a></td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. <!-- markdownlint-restore -->
  161. <!-- prettier-ignore-end -->
  162. <!-- ALL-CONTRIBUTORS-LIST:END -->
  163. This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
  164. ## ❤️ Sponsors and Backers
  165. The special thanks to these sponsors or backers because they provided support at a very early stage:
  166. <a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/image/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a>
  167. Thanks also give to these sponsors or backers:
  168. [![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
  169. [![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
  170. ## 🪪 License
  171. [MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201)
  172. [stack-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Stack.ts
  173. [stack-npm-version]: https://img.shields.io/npm/v/@js-sdsl/stack
  174. [stack-npm-link]: https://www.npmjs.com/package/@js-sdsl/stack
  175. [stack-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js?compression=gzip&style=flat-square/
  176. [stack-umd-link]: https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js
  177. [stack-docs]: https://js-sdsl.org/js-sdsl/classes/Stack.html
  178. [queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Queue.ts
  179. [queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/queue
  180. [queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/queue
  181. [queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js?compression=gzip&style=flat-square/
  182. [queue-umd-link]: https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js
  183. [queue-docs]: https://js-sdsl.org/js-sdsl/classes/Queue.html
  184. [priority-queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/PriorityQueue.ts
  185. [priority-queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/priority-queue
  186. [priority-queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/priority-queue
  187. [priority-queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js?compression=gzip&style=flat-square/
  188. [priority-queue-umd-link]: https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js
  189. [priority-queue-docs]: https://js-sdsl.org/js-sdsl/classes/PriorityQueue.html
  190. [vector-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Vector.ts
  191. [vector-npm-version]: https://img.shields.io/npm/v/@js-sdsl/vector
  192. [vector-npm-link]: https://www.npmjs.com/package/@js-sdsl/vector
  193. [vector-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js?compression=gzip&style=flat-square/
  194. [vector-umd-link]: https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js
  195. [vector-docs]: https://js-sdsl.org/js-sdsl/classes/Vector.html
  196. [link-list-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/LinkList.ts
  197. [link-list-npm-version]: https://img.shields.io/npm/v/@js-sdsl/link-list
  198. [link-list-npm-link]: https://www.npmjs.com/package/@js-sdsl/link-list
  199. [link-list-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js?compression=gzip&style=flat-square/
  200. [link-list-umd-link]: https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js
  201. [link-list-docs]: https://js-sdsl.org/js-sdsl/classes/LinkList.html
  202. [deque-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Deque.ts
  203. [deque-npm-version]: https://img.shields.io/npm/v/@js-sdsl/deque
  204. [deque-npm-link]: https://www.npmjs.com/package/@js-sdsl/deque
  205. [deque-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js?compression=gzip&style=flat-square/
  206. [deque-umd-link]: https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js
  207. [deque-docs]: https://js-sdsl.org/js-sdsl/classes/Deque.html
  208. [ordered-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedSet.ts
  209. [ordered-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-set
  210. [ordered-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-set
  211. [ordered-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js?compression=gzip&style=flat-square/
  212. [ordered-set-umd-link]: https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js
  213. [ordered-set-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedSet.html
  214. [ordered-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedMap.ts
  215. [ordered-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-map
  216. [ordered-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-map
  217. [ordered-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js?compression=gzip&style=flat-square/
  218. [ordered-map-umd-link]: https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js
  219. [ordered-map-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedMap.html
  220. [hash-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashSet.ts
  221. [hash-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-set
  222. [hash-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-set
  223. [hash-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js?compression=gzip&style=flat-square/
  224. [hash-set-umd-link]: https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js
  225. [hash-set-docs]: https://js-sdsl.org/js-sdsl/classes/HashSet.html
  226. [hash-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashMap.ts
  227. [hash-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-map
  228. [hash-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-map
  229. [hash-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js?compression=gzip&style=flat-square/
  230. [hash-map-umd-link]: https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js
  231. [hash-map-docs]: https://js-sdsl.org/js-sdsl/classes/HashMap.html