JavaScript是否具有集合数据结构的实现? [英] Does JavaScript have an implementation of a set data structure?

查看:199
本文介绍了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.

UPDATE

我已经完成并测试了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是否具有集合数据结构的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆