1 22 23 package com.sosnoski.util.hashset; 24 25 36 37 public class StringHashSet extends ObjectSetBase 38 { 39 40 protected String [] m_keyTable; 41 42 43 protected boolean m_identHash; 44 45 46 protected boolean m_identCompare; 47 48 57 58 public StringHashSet(int count, double fill, Object tech) { 59 super(count, fill, String .class, tech); 60 } 61 62 69 70 public StringHashSet(int count, double fill) { 71 this(count, fill, STANDARD_HASH); 72 } 73 74 83 84 public StringHashSet(int count, Object tech) { 85 this(count, DEFAULT_FILL, tech); 86 } 87 88 94 95 public StringHashSet(int count) { 96 this(count, DEFAULT_FILL, STANDARD_HASH); 97 } 98 99 107 108 public StringHashSet(Object tech) { 109 this(0, DEFAULT_FILL, tech); 110 } 111 112 115 116 public StringHashSet() { 117 this(0, DEFAULT_FILL, STANDARD_HASH); 118 } 119 120 125 126 public StringHashSet(StringHashSet base) { 127 super(base); 128 } 129 130 137 138 protected Object [] getKeyArray() { 139 return m_keyTable; 140 } 141 142 149 150 protected void setKeyArray(Object array) { 151 m_keyTable = (String [])array; 152 } 153 154 164 165 protected boolean reinsert(int slot) { 166 String key = m_keyTable[slot]; 167 m_keyTable[slot] = null; 168 return assignSlot(key) != slot; 169 } 170 171 180 181 protected void restructure(Object karray) { 182 String [] keys = (String [])karray; 183 for (int i = 0; i < keys.length; i++) { 184 if (keys[i] != null) { 185 assignSlot(keys[i]); 186 } 187 } 188 } 189 190 200 201 protected int assignSlot(String key) { 202 int offset = freeSlot(standardSlot(key)); 203 m_keyTable[offset] = key; 204 return offset; 205 } 206 207 214 215 public boolean add(String key) { 216 ensureCapacity(m_entryCount+1); 217 int offset = -standardFind(key) - 1; 218 if (offset >= 0) { 219 m_entryCount++; 220 m_keyTable[offset] = key; 221 return true; 222 } else { 223 return false; 224 } 225 } 226 227 234 235 public boolean contains(String key) { 236 return standardFind(key) >= 0; 237 } 238 239 246 247 public boolean remove(String key) { 248 int slot = standardFind(key); 249 if (slot >= 0) { 250 internalRemove(slot); 251 return true; 252 } else { 253 return false; 254 } 255 } 256 257 262 263 public Object clone() { 264 return new StringHashSet(this); 265 } 266 } 267 | Popular Tags |