1 | /*
|
2 | Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
|
3 |
|
4 | Redistribution and use in source and binary forms, with or without
|
5 | modification, are permitted provided that the following conditions are met:
|
6 |
|
7 | * Redistributions of source code must retain the above copyright
|
8 | notice, this list of conditions and the following disclaimer.
|
9 | * Redistributions in binary form must reproduce the above copyright
|
10 | notice, this list of conditions and the following disclaimer in the
|
11 | documentation and/or other materials provided with the distribution.
|
12 |
|
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 | */
|
24 |
|
25 | /*global module:true*/
|
26 | (function () {
|
27 | ;
|
28 |
|
29 | var Set, Map;
|
30 |
|
31 | Map = require('./map');
|
32 |
|
33 | if (typeof global.Set !== 'undefined') {
|
34 | // ES6 Set
|
35 | Set = global.Set;
|
36 | } else {
|
37 | Set = function Set() {
|
38 | this.__map = new Map();
|
39 | };
|
40 |
|
41 | Set.prototype.has = function SetHas(key) {
|
42 | return this.__map.has(key);
|
43 | };
|
44 |
|
45 | Set.prototype.add = function SetAdd(key) {
|
46 | return this.__map.set(key, true);
|
47 | };
|
48 |
|
49 | Set.prototype['delete'] = function SetDelete(key) {
|
50 | return this.__map['delete'](key);
|
51 | };
|
52 |
|
53 | Set.prototype.clear = function SetClear() {
|
54 | return this.__map.clear();
|
55 | };
|
56 |
|
57 | Set.prototype.forEach = function SetForEach(callback, thisArg) {
|
58 | var that = this;
|
59 | this.__map.forEach(function (value, key) {
|
60 | callback.call(thisArg, key, that);
|
61 | });
|
62 | };
|
63 |
|
64 | Set.prototype.values = function SetValues() {
|
65 | return this.__map.keys();
|
66 | };
|
67 |
|
68 | Set.prototype.keys = Set.prototype.values;
|
69 | }
|
70 |
|
71 | module.exports = Set;
|
72 | }());
|
73 | /* vim: set sw=4 ts=4 et tw=80 : */
|