Javascript 数据结构库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5909452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:28:00  来源:igfitidea点击:

Javascript data structures library

algorithmdata-structuresjavascript

提问by julx

I'd like to ask for recommendation of JavaScript library/libraries that supply an implementation of some basic data structures such as a priority queue, map with arbitrary keys, tries, graphs, etc. along with some algorithms that operate on them.

我想征求 JavaScript 库/库的推荐,这些库/库提供一些基本数据结构的实现,例如优先级队列、具有任意键的映射、尝试、图形等,以及一些对它们进行操作的算法。

I'm mostly interested in:

我最感兴趣的是:

  • The set of features covered,
  • Flexibility of the solution - this mostly applies to graphs. For example do I have to use a supplied graph implementation,
  • Use of functional features of the language - again it sometimes gives greater flexibility,
  • Performance of the implementation
  • 涵盖的功能集,
  • 解决方案的灵活性 - 这主要适用于图形。例如,我是否必须使用提供的图形实现,
  • 使用语言的功能特性 - 有时它再次提供更大的灵活性,
  • 执行情况

I'd like to point out that I'm aware that it's possible to implement using JavaScript the following data structures:

我想指出的是,我知道可以使用 JavaScript 实现以下数据结构:

  • A map, if key values are either strings or numbers,
  • A set, (using a map implementation),
  • A queue, although as was pointed out below, it's inefficient on some browsers,
  • 映射,如果键值是字符串或数字,
  • 一组,(使用地图实现),
  • 队列,尽管正如下面所指出的,它在某些浏览器上效率低下,

At the moment I'm mostly interested in priority queues (not to confuse with regular queues), graph implementations that aren't very intrusive as to the format of the input graph. For example they could use callbacks to traverse the structure of the graph rather than access some concrete properties with fixed names.

目前我最感兴趣的是优先级队列(不要与常规队列混淆),对输入图的格式不太具有侵入性的图实现。例如,他们可以使用回调来遍历图的结构,而不是访问一些具有固定名称的具体属性。

采纳答案by Pawe? Szczur

I recommend to use Closure Library (especially with closure compiler).

我建议使用闭包库(尤其是使用闭包编译器)。

Here you have a library with data structures goog.structs. The library contains:

这里有一个包含数据结构goog.structs的库。该库包含:

goog.structs.AvlTree
goog.structs.CircularBuffer
goog.structs.Heap
goog.structs.InversionMap
goog.structs.LinkedMap
goog.structs.Map
goog.structs.PriorityQueue
goog.structs.Set

As example you can use unit test: goog.structs.PriorityQueueTest.

例如,您可以使用单元测试:goog.structs.PriorityQueueTest

If you need to work on arrays, there's also an array lib: goog.array.

如果您需要处理数组,还有一个数组库:goog.array

As noted in comments, the source has moved to github.com/google/closureand the documentation's new location is: google.github.io/closure-library.

如评论中所述,源已移至github.com/google/closure,文档的新位置为:google.github.io/closure-library

回答by Daniel

You can try Bucketsis a very complete JavaScript data structure library that includes:

你可以试试Buckets是一个非常完整的 JavaScript 数据结构库,它包括:

  • Linked List
  • Dictionary
  • Multi Dictionary
  • Binary Search Tree
  • Stack
  • Queue
  • Set
  • Bag
  • Binary Heap
  • Priority Queue
  • 链表
  • 字典
  • 多词典
  • 二叉搜索树
  • 队列
  • 二叉堆
  • 优先队列

回答by probabilityzero

Probably most of what you want is built-in to Javascript in one way or another, or easy to put together with built-in functionality (native Javascript data structures are incredibly flexible). You might like JSClass.

可能您想要的大部分内容都以一种或另一种方式内置到 Javascript 中,或者很容易与内置功能组合在一起(原生 Javascript 数据结构非常灵活)。你可能喜欢 JSClass

As for the functional features of the language, underscore.jsis where it's at..

至于语言的功能特性,underscore.js就是它的所在。

回答by Tim Down

I can help you with the maps with arbitrary keys: my jshashtabledoes this, and there is also a hash set implementation built on top of it.

我可以帮助您使用任意键的映射:我的jshashtable 会这样做,并且还有一个构建在它之上的哈希集实现。

回答by Juho Veps?l?inen

Efficient queue.

高效的队列

If you find more of these, could you please add them to jswiki. Thanks. :)

如果您发现更多这些,请您将它们添加到jswiki。谢谢。:)

回答by Colonel Panic

Is your javascript in an application, or a web page? If it's for an application, why not outsource the data structures to Redis? There's a client for nodejs

您的 javascript 是在应用程序中还是网页中?如果是用于应用程序,为什么不将数据结构外包给Redis呢?nodejs有一个客户端

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Redis 是一个开源的高级键值存储。它通常被称为数据结构服务器,因为键可以包含字符串、散列、列表、集合和排序集合。

回答by factotum

Adding a link to a custom javascript library which provides Priority Queues, Tries, Basic Graph processing and other implementation, for future reference of the visitors to this thread . Check out dsjslib

添加指向自定义 javascript 库的链接,该库提供优先队列、尝试、基本图形处理和其他实现,供此线程的访问者将来参考。查看dsjslib

回答by AndreLung

Especially for graph-like structures, i find graphlib very convenient:

特别是对于类似图形的结构,我发现 graphlib 非常方便:

https://github.com/cpettitt/graphlib/wiki/API-Reference

https://github.com/cpettitt/graphlib/wiki/API-Reference

It is very straight-forward, faster than other implementations I tried, has all the basic features, popular graph-algorithms and a JSON data export.

它非常直接,比我尝试过的其他实现更快,具有所有基本功能、流行的图形算法和 JSON 数据导出。

回答by Raynos

data.js.

数据.js

I don't believe it's as feature rich as you want but it has graphs, hashes and collections.

我不相信它有你想要的那么丰富的功能,但它有图表、散列和集合。

I would take this a lightweight start that you can extend on.

我认为这是一个轻量级的开始,你可以继续扩展。

As for what it does offer, it's well written, efficient and documented.

至于它提供的功能,它写得很好,效率高并且有文档。