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

查看:24
本文介绍了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 是否有一组数据结构的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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