/**
* Constructor for RegularImmutableMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableMap(int size, TerminalEntry<?, ?>[] theEntries) {
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? entry
: new NonTerminalMapEntry<K, V>(entry, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
java类com.google.common.collect.ImmutableMapEntry.TerminalEntry的实例源码
RegularImmutableMap.java 文件源码
项目:bts
阅读 24
收藏 0
点赞 0
评论 0
RegularImmutableMap.java 文件源码
项目:bts
阅读 27
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that makes no assumptions about the input entries.
*/
RegularImmutableMap(Entry<?, ?>[] theEntries) {
int size = theEntries.length;
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked") // all our callers carefully put in only Entry<K, V>s
Entry<K, V> entry = (Entry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalMapEntry<K, V>(key, value, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:guava-libraries
阅读 30
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableMap(int size, TerminalEntry<?, ?>[] theEntries) {
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? entry
: new NonTerminalMapEntry<K, V>(entry, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInKeyBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:guava-libraries
阅读 25
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that makes no assumptions about the input entries.
*/
RegularImmutableMap(Entry<?, ?>[] theEntries) {
int size = theEntries.length;
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked") // all our callers carefully put in only Entry<K, V>s
Entry<K, V> entry = (Entry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalMapEntry<K, V>(key, value, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInKeyBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:cnGuava
阅读 26
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableMap(int size, TerminalEntry<?, ?>[] theEntries) {
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? entry
: new NonTerminalMapEntry<K, V>(entry, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:cnGuava
阅读 25
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that makes no assumptions about the input entries.
*/
RegularImmutableMap(Entry<?, ?>[] theEntries) {
int size = theEntries.length;
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked") // all our callers carefully put in only Entry<K, V>s
Entry<K, V> entry = (Entry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalMapEntry<K, V>(key, value, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:org.openntf.domino
阅读 23
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableMap(int size, TerminalEntry<?, ?>[] theEntries) {
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? entry
: new NonTerminalMapEntry<K, V>(entry, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
RegularImmutableMap.java 文件源码
项目:org.openntf.domino
阅读 26
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableMap that makes no assumptions about the input entries.
*/
RegularImmutableMap(Entry<?, ?>[] theEntries) {
int size = theEntries.length;
entries = createEntryArray(size);
int tableSize = Hashing.closedTableSize(size, MAX_LOAD_FACTOR);
table = createEntryArray(tableSize);
mask = tableSize - 1;
for (int entryIndex = 0; entryIndex < size; entryIndex++) {
@SuppressWarnings("unchecked") // all our callers carefully put in only Entry<K, V>s
Entry<K, V> entry = (Entry<K, V>) theEntries[entryIndex];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int tableIndex = Hashing.smear(key.hashCode()) & mask;
@Nullable ImmutableMapEntry<K, V> existing = table[tableIndex];
// prepend, not append, so the entries can be immutable
ImmutableMapEntry<K, V> newEntry = (existing == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalMapEntry<K, V>(key, value, existing);
table[tableIndex] = newEntry;
entries[entryIndex] = newEntry;
checkNoConflictInBucket(key, newEntry, existing);
}
}
ImmutableMap.java 文件源码
项目:bts
阅读 25
收藏 0
点赞 0
评论 0
/**
* Associates {@code key} with {@code value} in the built map. Duplicate
* keys are not allowed, and will cause {@link #build} to fail.
*/
public Builder<K, V> put(K key, V value) {
ensureCapacity(size + 1);
TerminalEntry<K, V> entry = entryOf(key, value);
// don't inline this: we want to fail atomically if key or value is null
entries[size++] = entry;
return this;
}
RegularImmutableBiMap.java 文件源码
项目:guava-libraries
阅读 30
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableBiMap(int n, TerminalEntry<?, ?>[] entriesToAdd) {
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
checkNoConflictInKeyBucket(key, entry, nextInKeyBucket);
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
checkNoConflictInValueBucket(value, entry, nextInValueBucket);
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? entry
: new NonTerminalBiMapEntry<K, V>(entry, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
RegularImmutableBiMap.java 文件源码
项目:guava-libraries
阅读 26
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that makes no assumptions about the input entries.
*/
RegularImmutableBiMap(Entry<?, ?>[] entriesToAdd) {
int n = entriesToAdd.length;
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
Entry<K, V> entry = (Entry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
checkNoConflictInKeyBucket(key, entry, nextInKeyBucket);
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
checkNoConflictInValueBucket(value, entry, nextInValueBucket);
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalBiMapEntry<K, V>(key, value, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
ImmutableMap.java 文件源码
项目:guava-libraries
阅读 22
收藏 0
点赞 0
评论 0
/**
* Associates {@code key} with {@code value} in the built map. Duplicate
* keys are not allowed, and will cause {@link #build} to fail.
*/
public Builder<K, V> put(K key, V value) {
ensureCapacity(size + 1);
TerminalEntry<K, V> entry = entryOf(key, value);
// don't inline this: we want to fail atomically if key or value is null
entries[size++] = entry;
return this;
}
ImmutableMap.java 文件源码
项目:cnGuava
阅读 24
收藏 0
点赞 0
评论 0
/**
* Associates {@code key} with {@code value} in the built map. Duplicate
* keys are not allowed, and will cause {@link #build} to fail.
*/
public Builder<K, V> put(K key, V value) {
ensureCapacity(size + 1);
TerminalEntry<K, V> entry = entryOf(key, value);
// don't inline this: we want to fail atomically if key or value is null
entries[size++] = entry;
return this;
}
ImmutableMap.java 文件源码
项目:org.openntf.domino
阅读 24
收藏 0
点赞 0
评论 0
/**
* Associates {@code key} with {@code value} in the built map. Duplicate
* keys are not allowed, and will cause {@link #build} to fail.
*/
public Builder<K, V> put(K key, V value) {
ensureCapacity(size + 1);
TerminalEntry<K, V> entry = entryOf(key, value);
// don't inline this: we want to fail atomically if key or value is null
entries[size++] = entry;
return this;
}
RegularImmutableBiMap.java 文件源码
项目:bts
阅读 24
收藏 0
点赞 0
评论 0
RegularImmutableBiMap(TerminalEntry<?, ?>... entriesToAdd) {
this(entriesToAdd.length, entriesToAdd);
}
RegularImmutableBiMap.java 文件源码
项目:bts
阅读 33
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableBiMap(int n, TerminalEntry<?, ?>[] entriesToAdd) {
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
for (ImmutableMapEntry<K, V> keyEntry = nextInKeyBucket; keyEntry != null;
keyEntry = keyEntry.getNextInKeyBucket()) {
checkNoConflict(!key.equals(keyEntry.getKey()), "key", entry, keyEntry);
}
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
for (ImmutableMapEntry<K, V> valueEntry = nextInValueBucket; valueEntry != null;
valueEntry = valueEntry.getNextInValueBucket()) {
checkNoConflict(!value.equals(valueEntry.getValue()), "value", entry, valueEntry);
}
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? entry
: new NonTerminalBiMapEntry<K, V>(entry, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
RegularImmutableBiMap.java 文件源码
项目:bts
阅读 31
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that makes no assumptions about the input entries.
*/
RegularImmutableBiMap(Entry<?, ?>[] entriesToAdd) {
int n = entriesToAdd.length;
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
Entry<K, V> entry = (Entry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
for (ImmutableMapEntry<K, V> keyEntry = nextInKeyBucket; keyEntry != null;
keyEntry = keyEntry.getNextInKeyBucket()) {
checkNoConflict(!key.equals(keyEntry.getKey()), "key", entry, keyEntry);
}
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
for (ImmutableMapEntry<K, V> valueEntry = nextInValueBucket; valueEntry != null;
valueEntry = valueEntry.getNextInValueBucket()) {
checkNoConflict(!value.equals(valueEntry.getValue()), "value", entry, valueEntry);
}
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalBiMapEntry<K, V>(key, value, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
ImmutableMap.java 文件源码
项目:bts
阅读 28
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
Builder(int initialCapacity) {
this.entries = new TerminalEntry[initialCapacity];
this.size = 0;
}
RegularImmutableMap.java 文件源码
项目:bts
阅读 22
收藏 0
点赞 0
评论 0
RegularImmutableMap(TerminalEntry<?, ?>... theEntries) {
this(theEntries.length, theEntries);
}
RegularImmutableBiMap.java 文件源码
项目:guava-libraries
阅读 29
收藏 0
点赞 0
评论 0
RegularImmutableBiMap(TerminalEntry<?, ?>... entriesToAdd) {
this(entriesToAdd.length, entriesToAdd);
}
ImmutableSortedMap.java 文件源码
项目:guava-libraries
阅读 78
收藏 0
点赞 0
评论 0
private static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
ofEntries(TerminalEntry<K, V>... entries) {
return fromEntries(Ordering.natural(), false, entries, entries.length);
}
ImmutableMap.java 文件源码
项目:guava-libraries
阅读 32
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
Builder(int initialCapacity) {
this.entries = new TerminalEntry[initialCapacity];
this.size = 0;
}
RegularImmutableMap.java 文件源码
项目:guava-libraries
阅读 20
收藏 0
点赞 0
评论 0
RegularImmutableMap(TerminalEntry<?, ?>... theEntries) {
this(theEntries.length, theEntries);
}
RegularImmutableBiMap.java 文件源码
项目:cnGuava
阅读 25
收藏 0
点赞 0
评论 0
RegularImmutableBiMap(TerminalEntry<?, ?>... entriesToAdd) {
this(entriesToAdd.length, entriesToAdd);
}
RegularImmutableBiMap.java 文件源码
项目:cnGuava
阅读 22
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableBiMap(int n, TerminalEntry<?, ?>[] entriesToAdd) {
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
for (ImmutableMapEntry<K, V> keyEntry = nextInKeyBucket; keyEntry != null;
keyEntry = keyEntry.getNextInKeyBucket()) {
checkNoConflict(!key.equals(keyEntry.getKey()), "key", entry, keyEntry);
}
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
for (ImmutableMapEntry<K, V> valueEntry = nextInValueBucket; valueEntry != null;
valueEntry = valueEntry.getNextInValueBucket()) {
checkNoConflict(!value.equals(valueEntry.getValue()), "value", entry, valueEntry);
}
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? entry
: new NonTerminalBiMapEntry<K, V>(entry, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
RegularImmutableBiMap.java 文件源码
项目:cnGuava
阅读 20
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that makes no assumptions about the input entries.
*/
RegularImmutableBiMap(Entry<?, ?>[] entriesToAdd) {
int n = entriesToAdd.length;
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
Entry<K, V> entry = (Entry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
checkEntryNotNull(key, value);
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
for (ImmutableMapEntry<K, V> keyEntry = nextInKeyBucket; keyEntry != null;
keyEntry = keyEntry.getNextInKeyBucket()) {
checkNoConflict(!key.equals(keyEntry.getKey()), "key", entry, keyEntry);
}
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
for (ImmutableMapEntry<K, V> valueEntry = nextInValueBucket; valueEntry != null;
valueEntry = valueEntry.getNextInValueBucket()) {
checkNoConflict(!value.equals(valueEntry.getValue()), "value", entry, valueEntry);
}
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? new TerminalEntry<K, V>(key, value)
: new NonTerminalBiMapEntry<K, V>(key, value, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}
ImmutableMap.java 文件源码
项目:cnGuava
阅读 30
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
Builder(int initialCapacity) {
this.entries = new TerminalEntry[initialCapacity];
this.size = 0;
}
RegularImmutableMap.java 文件源码
项目:cnGuava
阅读 21
收藏 0
点赞 0
评论 0
RegularImmutableMap(TerminalEntry<?, ?>... theEntries) {
this(theEntries.length, theEntries);
}
RegularImmutableBiMap.java 文件源码
项目:org.openntf.domino
阅读 34
收藏 0
点赞 0
评论 0
RegularImmutableBiMap(TerminalEntry<?, ?>... entriesToAdd) {
this(entriesToAdd.length, entriesToAdd);
}
RegularImmutableBiMap.java 文件源码
项目:org.openntf.domino
阅读 22
收藏 0
点赞 0
评论 0
/**
* Constructor for RegularImmutableBiMap that takes as input an array of {@code TerminalEntry}
* entries. Assumes that these entries have already been checked for null.
*
* <p>This allows reuse of the entry objects from the array in the actual implementation.
*/
RegularImmutableBiMap(int n, TerminalEntry<?, ?>[] entriesToAdd) {
int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR);
this.mask = tableSize - 1;
ImmutableMapEntry<K, V>[] keyTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] valueTable = createEntryArray(tableSize);
ImmutableMapEntry<K, V>[] entries = createEntryArray(n);
int hashCode = 0;
for (int i = 0; i < n; i++) {
@SuppressWarnings("unchecked")
TerminalEntry<K, V> entry = (TerminalEntry<K, V>) entriesToAdd[i];
K key = entry.getKey();
V value = entry.getValue();
int keyHash = key.hashCode();
int valueHash = value.hashCode();
int keyBucket = Hashing.smear(keyHash) & mask;
int valueBucket = Hashing.smear(valueHash) & mask;
ImmutableMapEntry<K, V> nextInKeyBucket = keyTable[keyBucket];
for (ImmutableMapEntry<K, V> keyEntry = nextInKeyBucket; keyEntry != null;
keyEntry = keyEntry.getNextInKeyBucket()) {
checkNoConflict(!key.equals(keyEntry.getKey()), "key", entry, keyEntry);
}
ImmutableMapEntry<K, V> nextInValueBucket = valueTable[valueBucket];
for (ImmutableMapEntry<K, V> valueEntry = nextInValueBucket; valueEntry != null;
valueEntry = valueEntry.getNextInValueBucket()) {
checkNoConflict(!value.equals(valueEntry.getValue()), "value", entry, valueEntry);
}
ImmutableMapEntry<K, V> newEntry =
(nextInKeyBucket == null && nextInValueBucket == null)
? entry
: new NonTerminalBiMapEntry<K, V>(entry, nextInKeyBucket, nextInValueBucket);
keyTable[keyBucket] = newEntry;
valueTable[valueBucket] = newEntry;
entries[i] = newEntry;
hashCode += keyHash ^ valueHash;
}
this.keyTable = keyTable;
this.valueTable = valueTable;
this.entries = entries;
this.hashCode = hashCode;
}