/** * Clears the map of all entries. */ public void clear() { for (int i = 0; i < buckets.Length; i++) { LockJ lockj = locks[i]; lock (lockj) { buckets[i] = null; lockj.size = 0; } } }
/** * Initializes the map with a specified number of buckets. The number * of buckets is never below 17, and is always an odd number (StaticBucketMap * ensures this). The number of buckets is inversely proportional to the * chances for thread contention. The fewer buckets, the more chances for * thread contention. The more buckets the fewer chances for thread * contention. * * @param numBuckets the number of buckets for this map */ public StaticBucketMap(int numBuckets) { int size = java.lang.Math.max(17, numBuckets); // Ensure that bucketSize is never a power of 2 (to ensure maximal distribution) if (size % 2 == 0) { size--; } buckets = new Node[size]; locks = new LockJ[size]; for (int i = 0; i < size; i++) { locks[i] = new LockJ(); } }