ObjectIdSubclassMap: Fix non-standard naming conventions
obj_hash doesn't match our naming conventions, camelCaseNames are the preferred format. Change-Id: I72da199daccb60a98d17b6af1e498189bf149515 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
c68aba2a48
commit
ff6ac0aaef
|
@ -65,17 +65,17 @@
|
||||||
public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
|
public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
private V[] obj_hash;
|
private V[] table;
|
||||||
|
|
||||||
/** Create an empty map. */
|
/** Create an empty map. */
|
||||||
public ObjectIdSubclassMap() {
|
public ObjectIdSubclassMap() {
|
||||||
obj_hash = createArray(32);
|
table = createArray(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove all entries from this map. */
|
/** Remove all entries from this map. */
|
||||||
public void clear() {
|
public void clear() {
|
||||||
size = 0;
|
size = 0;
|
||||||
obj_hash = createArray(32);
|
table = createArray(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,10 +89,10 @@ public V get(final AnyObjectId toFind) {
|
||||||
int i = index(toFind);
|
int i = index(toFind);
|
||||||
V obj;
|
V obj;
|
||||||
|
|
||||||
while ((obj = obj_hash[i]) != null) {
|
while ((obj = table[i]) != null) {
|
||||||
if (AnyObjectId.equals(obj, toFind))
|
if (AnyObjectId.equals(obj, toFind))
|
||||||
return obj;
|
return obj;
|
||||||
if (++i == obj_hash.length)
|
if (++i == table.length)
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -123,7 +123,7 @@ public boolean contains(final AnyObjectId toFind) {
|
||||||
* type of instance to store.
|
* type of instance to store.
|
||||||
*/
|
*/
|
||||||
public <Q extends V> void add(final Q newValue) {
|
public <Q extends V> void add(final Q newValue) {
|
||||||
if (obj_hash.length - 1 <= size * 2)
|
if (table.length - 1 <= size * 2)
|
||||||
grow();
|
grow();
|
||||||
insert(newValue);
|
insert(newValue);
|
||||||
size++;
|
size++;
|
||||||
|
@ -153,18 +153,18 @@ public <Q extends V> V addIfAbsent(final Q newValue) {
|
||||||
int i = index(newValue);
|
int i = index(newValue);
|
||||||
V obj;
|
V obj;
|
||||||
|
|
||||||
while ((obj = obj_hash[i]) != null) {
|
while ((obj = table[i]) != null) {
|
||||||
if (AnyObjectId.equals(obj, newValue))
|
if (AnyObjectId.equals(obj, newValue))
|
||||||
return obj;
|
return obj;
|
||||||
if (++i == obj_hash.length)
|
if (++i == table.length)
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj_hash.length - 1 <= size * 2) {
|
if (table.length - 1 <= size * 2) {
|
||||||
grow();
|
grow();
|
||||||
insert(newValue);
|
insert(newValue);
|
||||||
} else {
|
} else {
|
||||||
obj_hash[i] = newValue;
|
table[i] = newValue;
|
||||||
}
|
}
|
||||||
size++;
|
size++;
|
||||||
return newValue;
|
return newValue;
|
||||||
|
@ -193,8 +193,8 @@ public boolean hasNext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public V next() {
|
public V next() {
|
||||||
while (i < obj_hash.length) {
|
while (i < table.length) {
|
||||||
final V v = obj_hash[i++];
|
final V v = table[i++];
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
found++;
|
found++;
|
||||||
return v;
|
return v;
|
||||||
|
@ -210,25 +210,25 @@ public void remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int index(final AnyObjectId id) {
|
private final int index(final AnyObjectId id) {
|
||||||
return (id.w1 >>> 1) % obj_hash.length;
|
return (id.w1 >>> 1) % table.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insert(final V newValue) {
|
private void insert(final V newValue) {
|
||||||
int j = index(newValue);
|
int j = index(newValue);
|
||||||
while (obj_hash[j] != null) {
|
while (table[j] != null) {
|
||||||
if (++j >= obj_hash.length)
|
if (++j >= table.length)
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
obj_hash[j] = newValue;
|
table[j] = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void grow() {
|
private void grow() {
|
||||||
final V[] old_hash = obj_hash;
|
final V[] oldTable = table;
|
||||||
final int old_hash_size = obj_hash.length;
|
final int oldSize = table.length;
|
||||||
|
|
||||||
obj_hash = createArray(2 * old_hash_size);
|
table = createArray(2 * oldSize);
|
||||||
for (int i = 0; i < old_hash_size; i++) {
|
for (int i = 0; i < oldSize; i++) {
|
||||||
final V obj = old_hash[i];
|
final V obj = oldTable[i];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
insert(obj);
|
insert(obj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue