Does JavaScript have an implementation of a set data structure?(JavaScript 是否有一个集合数据结构的实现?)
问题描述
我正在寻找一个用 JavaScript 实现的集合数据结构的体面实现.它应该能够支持纯 JavaScript 对象的元素.
I'm looking for a decent implementation of a set data structure in JavaScript. It should be able to support elements that are plain JavaScript objects.
到目前为止,我只找到了 Closure Library 的 structs.Set,但是我不喜欢它修改我的数据这一事实.
So far I only found Closure Library's structs.Set, but I don't like the fact that it modifies my data.
推荐答案
您可以围绕我的 jshashtable.我在某个地方敲了一个,稍后我会挖出来.
You could build a simple wrapper around the keys of a hash table provided by my jshashtable. I have one knocking around somewhere that I will dig out later.
更新
我已经完成并测试了 HashSet 的实现,并将其上传到 GitHub 上的 jshashtable 项目.你可以下载或者查看源码.
I have completed and tested an implementation of HashSet and uploaded it to the jshashtable project on GitHub. You can download it or view the source.
var s = new HashSet();
var o1 = {name: "One"}, o2 = {name: "Two"};
s.add(o1);
s.add(o2);
s.values(); // Array containing o1 and o2
这篇关于JavaScript 是否有一个集合数据结构的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JavaScript 是否有一个集合数据结构的实现?


基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01