JavaScript 数据结构库

发布于 2024-11-05 14:15:30 字数 1539 浏览 0 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

毁虫ゝ 2024-11-12 14:15:30

编辑

截至 2024 年 8 月,Closure 库已被废弃,因为它“不再满足现代 Javascript 开发的需求,请参阅 弃用通知和建议的替代方案,但与此问题相关:

  • 对于库的许多部分(goog.arraygoog.domgoog.eventsgoog.json< /code> 等),JavaScript 的内置解决方案应该足够了。
  • 对于许多特殊用途的软件包(数学、数据结构、其他算法)来说,小型的专用库通常比 Closure 的整体方法更好。



原始答案

我建议使用闭包库(特别是使用闭包编译器)。

这里有一个包含数据结构 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

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

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

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

Edit

As of August 2024, the Closure Library has been sunsetted as it's "no longer meeting the needs of modern Javascript Development, see the deprecation notice and suggested alternatives, but relevant to this question:

  • For many parts of the library (goog.array, goog.dom, goog.events, goog.json, etc), JavaScript's built-in solutions should be sufficient.
  • For many special-purpose packages (math, data structures, other algorithms), a small focused library is often better than Closure's monolithic approach.

Original answer

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.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.

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

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

怎言笑 2024-11-12 14:15:30

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

  • 链表
  • 字典
  • 多字典
  • 二叉搜索树
  • 堆栈
  • 队列
  • 包 二
  • 叉堆
  • 优先级队列

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

  • Linked List
  • Dictionary
  • Multi Dictionary
  • Binary Search Tree
  • Stack
  • Queue
  • Set
  • Bag
  • Binary Heap
  • Priority Queue
睫毛溺水了 2024-11-12 14:15:30

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

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

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.

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

谜兔 2024-11-12 14:15:30

我可以帮助您使用任意键的地图:我的 jshashtable 可以做到这一点,而且还有建立在其之上的哈希集实现。

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

冰雪梦之恋 2024-11-12 14:15:30

高效队列

如果您发现更多此类内容,请将它们添加到 jswiki 中。谢谢。 :)

Efficient queue.

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

又爬满兰若 2024-11-12 14:15:30

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

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

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

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

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.

救星 2024-11-12 14:15:30

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

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

隔纱相望 2024-11-12 14:15:30

data.js

我不认为它的功能如您想要的那么丰富,但它有图表、哈希值和集合。

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

至于它提供的功能,它写得很好,高效且有记录。

data.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.

欲拥i 2024-11-12 14:15:30

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文