1 9 package prefuse.util.collections; 10 11 23 public abstract class AbstractHashMap { 24 25 28 protected int distinct; 29 30 40 protected int lowWaterMark; 41 42 protected int highWaterMark; 43 44 47 protected double minLoadFactor; 48 49 52 protected double maxLoadFactor; 53 54 protected static final int defaultCapacity = 277; 55 56 protected static final double defaultMinLoadFactor = 0.2; 57 58 protected static final double defaultMaxLoadFactor = 0.5; 59 60 64 protected AbstractHashMap() { 65 } 66 67 73 protected int chooseGrowCapacity(int size, double minLoad, double maxLoad) { 74 return nextPrime(Math.max(size + 1, 75 (int) ((4 * size / (3 * minLoad + maxLoad))))); 76 } 77 78 84 protected int chooseHighWaterMark(int capacity, double maxLoad) { 85 return Math.min(capacity - 2, (int) (capacity * maxLoad)); } 92 93 99 protected int chooseLowWaterMark(int capacity, double minLoad) { 100 return (int) (capacity * minLoad); 101 } 102 103 109 protected int chooseMeanCapacity(int size, double minLoad, double maxLoad) { 110 return nextPrime(Math.max(size + 1, 111 (int) ((2 * size / (minLoad + maxLoad))))); 112 } 113 114 120 protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad) { 121 return nextPrime(Math.max(size + 1, 122 (int) ((4 * size / (minLoad + 3 * maxLoad))))); 123 } 124 125 128 public abstract void clear(); 129 130 146 public void ensureCapacity(int minCapacity) { 147 } 148 149 156 public boolean isEmpty() { 157 return distinct == 0; 158 } 159 160 169 protected int nextPrime(int desiredCapacity) { 170 return PrimeFinder.nextPrime(desiredCapacity); 171 } 172 173 187 protected void setUp(int initialCapacity, double minLoadFactor, 188 double maxLoadFactor) { 189 if (initialCapacity < 0) 190 throw new IllegalArgumentException ( 191 "Initial Capacity must not be less than zero: " 192 + initialCapacity); 193 if (minLoadFactor < 0.0 || minLoadFactor >= 1.0) 194 throw new IllegalArgumentException ("Illegal minLoadFactor: " 195 + minLoadFactor); 196 if (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) 197 throw new IllegalArgumentException ("Illegal maxLoadFactor: " 198 + maxLoadFactor); 199 if (minLoadFactor >= maxLoadFactor) 200 throw new IllegalArgumentException ("Illegal minLoadFactor: " 201 + minLoadFactor + " and maxLoadFactor: " + maxLoadFactor); 202 } 203 204 209 public int size() { 210 return distinct; 211 } 212 213 220 public void trimToSize() { 221 } 222 223 } | Popular Tags |