1 dojo.provide("calitha.collections.HashSet"); 2 dojo.require("calitha.collections.AbstractSet"); 3 dojo.require("calitha.collections.HashMap"); 4 5 dojo.declare("calitha.collections.HashSet", calitha.collections.AbstractSet, 6 /** @lends calitha.collections.HashSet#*/ 7 { 8 /** 9 * @constructs 10 * @extends calitha.collections.AbstractMap 11 * @param initialCapacity optional initial capacity 12 * @param loadFactor optional load factor 13 * @description This class implements the Set interface, backed by a hash table (actually a HashMap instance). 14 * <p>This class is similar to the 15 * <a href="http://java.sun.com/javase/6/docs/api/java/util/HashSet.html">Java HashSet class</a> 16 * <p>Each object must have an equals and hashCode method. This is also true for numbers and strings. 17 * However you can use the {@link calitha.collections.makeNumberHashCompatible} and 18 * {@link calitha.collections.makeStringHashCompatible} to use those directly. 19 */ 20 constructor: function(/**Number?*/ initialCapacity, /**Number?*/ loadFactor) 21 { 22 this._map = new calitha.collections.HashMap(initialCapacity, loadFactor); 23 } 24 , 25 add: function(/**Object*/ element) 26 { 27 return this._map.put(element, this.constants.PRESENT) === null; 28 } 29 , 30 clear: function() 31 { 32 this._map.clear(); 33 } 34 , 35 contains: function(/**Object*/ o) 36 { 37 return this._map.containsKey(o); 38 } 39 , 40 isEmpty: function() 41 { 42 return this._map.isEmpty(); 43 } 44 , 45 iterator: function() 46 { 47 return this._map.keySet().iterator(); 48 } 49 , 50 remove: function(/**Object*/ o) 51 { 52 return this._map.remove(o) === this.constants.PRESENT; 53 } 54 , 55 size: function() 56 { 57 return this._map.size(); 58 } 59 , 60 constants: 61 { 62 PRESENT: {} 63 } 64 }); 65