1 22 23 package com.sosnoski.util.hashset; 24 25 36 37 public class ObjectHashSet extends ObjectSetBase 38 { 39 40 protected Object [] m_keyTable; 41 42 51 52 public ObjectHashSet(int count, double fill, Object tech) { 53 super(count, fill, Object .class, tech); 54 } 55 56 63 64 public ObjectHashSet(int count, double fill) { 65 this(count, fill, STANDARD_HASH); 66 } 67 68 77 78 public ObjectHashSet(int count, Object tech) { 79 this(count, DEFAULT_FILL, tech); 80 } 81 82 88 89 public ObjectHashSet(int count) { 90 this(count, DEFAULT_FILL, STANDARD_HASH); 91 } 92 93 101 102 public ObjectHashSet(Object tech) { 103 this(0, DEFAULT_FILL, tech); 104 } 105 106 109 110 public ObjectHashSet() { 111 this(0, DEFAULT_FILL, STANDARD_HASH); 112 } 113 114 119 120 public ObjectHashSet(ObjectHashSet base) { 121 super(base); 122 } 123 124 131 132 protected Object [] getKeyArray() { 133 return m_keyTable; 134 } 135 136 143 144 protected void setKeyArray(Object array) { 145 m_keyTable = (Object [])array; 146 } 147 148 158 159 protected boolean reinsert(int slot) { 160 Object key = m_keyTable[slot]; 161 m_keyTable[slot] = null; 162 return assignSlot(key) != slot; 163 } 164 165 174 175 protected void restructure(Object karray) { 176 Object [] keys = (Object [])karray; 177 for (int i = 0; i < keys.length; i++) { 178 if (keys[i] != null) { 179 assignSlot(keys[i]); 180 } 181 } 182 } 183 184 194 195 protected int assignSlot(Object key) { 196 int offset = freeSlot(standardSlot(key)); 197 m_keyTable[offset] = key; 198 return offset; 199 } 200 201 208 209 public boolean add(Object key) { 210 ensureCapacity(m_entryCount+1); 211 int offset = -standardFind(key) - 1; 212 if (offset >= 0) { 213 m_entryCount++; 214 m_keyTable[offset] = key; 215 return true; 216 } else { 217 return false; 218 } 219 } 220 221 228 229 public boolean contains(Object key) { 230 return standardFind(key) >= 0; 231 } 232 233 240 241 public boolean remove(Object key) { 242 int slot = standardFind(key); 243 if (slot >= 0) { 244 internalRemove(slot); 245 return true; 246 } else { 247 return false; 248 } 249 } 250 251 256 257 public Object clone() { 258 return new ObjectHashSet(this); 259 } 260 } 261 | Popular Tags |