npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

common-data-structure

v0.12.0

Published

一些javaScript常用数据结构

Readme

common-data-structure

Help you more convenient to use some common JavaScript data structure

Table of Contents

Installing

npm install --save common-data-structure

Example

const { Stack } = require('common-data-structure')

const stack = new Stack() // create an instance
stack.push(5) // add an element
stack.push(6)
stack.peek() // peek top of stack element
stack.push(8)
stack.isEmpty() // Is the stack empty
stack.size() // stack length

Require

// import your required classes
const {
  Queue,
  Deque,
  Stack,
  LinkedList,
  DoublyLinkedList,
  Set,
  HashMap,
  BinarySearchTree,
  MinHead,
  MaxHead
} = require('common-data-structure')

API

Queue

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | enqueue(element) | element: 元素 | 向队列尾部添加一个(或多个)新的项 | | dequeue() | | 移除队列的第一项(即排在队列最前面的项)并返回被移除的元素 | | peek() | | 返回队列中第一个元素——最先被添加,也将是最先被移除的元素 | | isEmpty() | | 如果队列中不包含任何元素,返回 true,否则返回 false | | size() | | 返回队列包含的元素个数,与数组的 length 属性类似 | | clear() | | 清空队列中所有的元素 | | toString() | | 返回字符串 |

Deque

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | addFront(element) | element: 元素 | 在双端队列前添加新的元素 | | addBack(element) | element: 元素 | 在双端队列后端添加新元素 | | removeFront() | | 在双端队列前端移除第一个元素 | | removeBack() | | 在双端队列后端移除第一个元素 | | peekFront() | | 返回双端队列前端的一个元素 | | peekBack() | | 返回双端队列后端的第一个元素 | | isEmpty() | | 如果队列中不包含任何元素,返回 true,否则返回 false | | size() | | 返回队列包含的元素个数,与数组的 length 属性类似 | | clear() | | 清空队列中所有的元素 | | toString() | | 返回字符串 |

Stack

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | push(element) | element: 元素 | 向栈添加元素 | | pop() | | 从栈移除元素 | | peek() | | 查看栈顶元素 | | isEmpty() | | 检查栈是否为空 | | size() | | 移除栈里的所有元素 | | toString() | | 返回对象的字符串表示形式 |

LinkedList

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | push(element) | element: 元素 | 向链表尾部添加一个新元素 | | insert(element) | element: 元素; index: 插入元素的位置 | 向链表的特定位置插入一个新元素 | | getElementAt(index) | index: 元素的位置 | 在双端队列前端移除第一个元素 | | removeBack(index) | index: 元素的位置 | 返回链表中特定位置的元素。如果链表中不存在这样的元素,则返回 undefined | | remove(element) | element: 元素 | 从链表中移除一个元素 | | indexOf(element) | element: 元素 | 返回元素在链表中的索引。如果链表中没有改元素则返回 -1 | | removeAt(index) | index: 元素的位置 | 从链表的特定位置移除一个元素 | | isEmpty() | | 判断链表是否为空 | | getHead() | | 获取链表的头节点 | | toString() | | 返回表示整个链表的字符串 |

DoublyLinkedList

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | push(element) | element: 元素 | 向链表尾部添加一个新元素 | | insert(element) | element: 元素; index: 插入元素的位置 | 向链表的特定位置插入一个新元素 | | getElementAt(index) | index: 元素的位置 | 在双端队列前端移除第一个元素 | | removeBack(index) | index: 元素的位置 | 返回链表中特定位置的元素。如果链表中不存在这样的元素,则返回 undefined | | remove(element) | element: 元素 | 从链表中移除一个元素 | | indexOf(element) | element: 元素 | 返回元素在链表中的索引。如果链表中没有改元素则返回 -1 | | removeAt(index) | index: 元素的位置 | 从链表的特定位置移除一个元素 | | isEmpty() | | 判断链表是否为空 | | getHead() | | 获取链表的头节点 | | toString() | | 返回表示整个链表的字符串 |

Set

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | add(element) | element: 元素 | 向集合添加一个新元素 | | delete(element) | element: 元素 | 从集合中移除一个元素 | | has(element) | element: 元素 | 判断元素是否在集合中,存在则返回true,否则返回false | | clear() | | 移除集合中的所有元素 | | size() | | 返回集合所包含元素的数量 | | values() | | 返回一个包含集合中所有元素的数组 |

HashMap

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | set(key, value) | key: 键; value: 值 | 向散列表增加一个新的项 | | delete(key) | key: 键 | 根据键值移除值 | | get(key) | key: 键 | 根据键值返回特定的值 | | hasKey() | key: 键 | 判断某键值是否存在散列表中 | | clear() | | 删除字典中所有值 | | size() | | 返回字典包含的数量 | | isEmpty() | | 字典是否为空 | | keys() | | 将字典所包含的所有键名以数组形式返回 | | values() | | 将字典所包含的所有数值以数组形式返回 | | keyValues() | | 将字典中所有[{键,值}]对返回 | | forEach() | | 迭代字典中所有的键值对 | | toString() | | 返回 hashmap 的字符串 |

BinarySearchTree

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | insert(key) | key: 键 | 向树中插入一个新的键 | | search(key) | key: 键 | 在树中查找一个键 | | inOrderTraverse(callback) | callback: 回调函数 | 中序遍历所有节点 | | preOrderTraverse(callback) | callback: 回调函数 | 先序遍历所有节点 | | postOrderTraverse(callback) | callback: 回调函数 | 后序遍历所有节点 | | min() | | 返回树中最小的值/键 | | max() | | 返回树中最大的值/键 | | remove(key) | key: 键 | 从树中移除某个键 |

MinHead

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | insert(value) | value: 值 | 向堆中插入一个新的值 | | extract() | | 移除最小值 | | size() | | 堆的大小 | | isEmpty() | | 是否为空 | | clear() | | 清除数据 | | findMinimum() | | 查找最小的值 |

MaxHead

| 方法名称 | 参数 | 描述 | | --- | --- | --- | | insert(value) | value: 值 | 向堆中插入一个新的值 | | extract() | | 移除最大值 | | size() | | 堆的大小 | | isEmpty() | | 是否为空 | | clear() | | 清除数据 | | findMaxmum() | | 查找最大的值 |