package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.AbstractMap; import java.util.Arrays; import java.util.Map; import java.util.Objects; /* loaded from: classes3.dex */ public final class RegularImmutableMap extends ImmutableMap { public static final ImmutableMap EMPTY = new RegularImmutableMap(null, new Object[0], 0); private static final long serialVersionUID = 0; public final transient Object[] alternatingKeysAndValues; public final transient Object hashTable; public final transient int size; @Override // java.util.Map public int size() { return this.size; } public static RegularImmutableMap create(int i, Object[] objArr, ImmutableMap.Builder builder) { if (i == 0) { return (RegularImmutableMap) EMPTY; } if (i == 1) { Object obj = objArr[0]; Objects.requireNonNull(obj); Object obj2 = objArr[1]; Objects.requireNonNull(obj2); CollectPreconditions.checkEntryNotNull(obj, obj2); return new RegularImmutableMap(null, objArr, 1); } Preconditions.checkPositionIndex(i, objArr.length >> 1); Object createHashTable = createHashTable(objArr, i, ImmutableSet.chooseTableSize(i), 0); if (createHashTable instanceof Object[]) { Object[] objArr2 = (Object[]) createHashTable; ImmutableMap.Builder.DuplicateKey duplicateKey = (ImmutableMap.Builder.DuplicateKey) objArr2[2]; if (builder == null) { throw duplicateKey.exception(); } builder.duplicateKey = duplicateKey; Object obj3 = objArr2[0]; int intValue = ((Integer) objArr2[1]).intValue(); objArr = Arrays.copyOf(objArr, intValue * 2); createHashTable = obj3; i = intValue; } return new RegularImmutableMap(createHashTable, objArr, i); } public static Object createHashTable(Object[] objArr, int i, int i2, int i3) { ImmutableMap.Builder.DuplicateKey duplicateKey = null; if (i == 1) { Object obj = objArr[i3]; Objects.requireNonNull(obj); Object obj2 = objArr[i3 ^ 1]; Objects.requireNonNull(obj2); CollectPreconditions.checkEntryNotNull(obj, obj2); return null; } int i4 = i2 - 1; int i5 = 0; if (i2 <= 128) { byte[] bArr = new byte[i2]; Arrays.fill(bArr, (byte) -1); int i6 = 0; while (i5 < i) { int i7 = (i5 * 2) + i3; int i8 = (i6 * 2) + i3; Object obj3 = objArr[i7]; Objects.requireNonNull(obj3); Object obj4 = objArr[i7 ^ 1]; Objects.requireNonNull(obj4); CollectPreconditions.checkEntryNotNull(obj3, obj4); int smear = Hashing.smear(obj3.hashCode()); while (true) { int i9 = smear & i4; int i10 = bArr[i9] & 255; if (i10 == 255) { bArr[i9] = (byte) i8; if (i6 < i5) { objArr[i8] = obj3; objArr[i8 ^ 1] = obj4; } i6++; } else { if (obj3.equals(objArr[i10])) { int i11 = i10 ^ 1; Object obj5 = objArr[i11]; Objects.requireNonNull(obj5); duplicateKey = new ImmutableMap.Builder.DuplicateKey(obj3, obj4, obj5); objArr[i11] = obj4; break; } smear = i9 + 1; } } i5++; } return i6 == i ? bArr : new Object[]{bArr, Integer.valueOf(i6), duplicateKey}; } if (i2 <= 32768) { short[] sArr = new short[i2]; Arrays.fill(sArr, (short) -1); int i12 = 0; while (i5 < i) { int i13 = (i5 * 2) + i3; int i14 = (i12 * 2) + i3; Object obj6 = objArr[i13]; Objects.requireNonNull(obj6); Object obj7 = objArr[i13 ^ 1]; Objects.requireNonNull(obj7); CollectPreconditions.checkEntryNotNull(obj6, obj7); int smear2 = Hashing.smear(obj6.hashCode()); while (true) { int i15 = smear2 & i4; int i16 = sArr[i15] & 65535; if (i16 == 65535) { sArr[i15] = (short) i14; if (i12 < i5) { objArr[i14] = obj6; objArr[i14 ^ 1] = obj7; } i12++; } else { if (obj6.equals(objArr[i16])) { int i17 = i16 ^ 1; Object obj8 = objArr[i17]; Objects.requireNonNull(obj8); duplicateKey = new ImmutableMap.Builder.DuplicateKey(obj6, obj7, obj8); objArr[i17] = obj7; break; } smear2 = i15 + 1; } } i5++; } return i12 == i ? sArr : new Object[]{sArr, Integer.valueOf(i12), duplicateKey}; } int[] iArr = new int[i2]; Arrays.fill(iArr, -1); int i18 = 0; while (i5 < i) { int i19 = (i5 * 2) + i3; int i20 = (i18 * 2) + i3; Object obj9 = objArr[i19]; Objects.requireNonNull(obj9); Object obj10 = objArr[i19 ^ 1]; Objects.requireNonNull(obj10); CollectPreconditions.checkEntryNotNull(obj9, obj10); int smear3 = Hashing.smear(obj9.hashCode()); while (true) { int i21 = smear3 & i4; int i22 = iArr[i21]; if (i22 == -1) { iArr[i21] = i20; if (i18 < i5) { objArr[i20] = obj9; objArr[i20 ^ 1] = obj10; } i18++; } else { if (obj9.equals(objArr[i22])) { int i23 = i22 ^ 1; Object obj11 = objArr[i23]; Objects.requireNonNull(obj11); duplicateKey = new ImmutableMap.Builder.DuplicateKey(obj9, obj10, obj11); objArr[i23] = obj10; break; } smear3 = i21 + 1; } } i5++; } return i18 == i ? iArr : new Object[]{iArr, Integer.valueOf(i18), duplicateKey}; } public RegularImmutableMap(Object obj, Object[] objArr, int i) { this.hashTable = obj; this.alternatingKeysAndValues = objArr; this.size = i; } @Override // com.google.common.collect.ImmutableMap, java.util.Map public Object get(Object obj) { Object obj2 = get(this.hashTable, this.alternatingKeysAndValues, this.size, 0, obj); if (obj2 == null) { return null; } return obj2; } public static Object get(Object obj, Object[] objArr, int i, int i2, Object obj2) { if (obj2 == null) { return null; } if (i == 1) { Object obj3 = objArr[i2]; Objects.requireNonNull(obj3); if (!obj3.equals(obj2)) { return null; } Object obj4 = objArr[i2 ^ 1]; Objects.requireNonNull(obj4); return obj4; } if (obj == null) { return null; } if (obj instanceof byte[]) { byte[] bArr = (byte[]) obj; int length = bArr.length - 1; int smear = Hashing.smear(obj2.hashCode()); while (true) { int i3 = smear & length; int i4 = bArr[i3] & 255; if (i4 == 255) { return null; } if (obj2.equals(objArr[i4])) { return objArr[i4 ^ 1]; } smear = i3 + 1; } } else if (obj instanceof short[]) { short[] sArr = (short[]) obj; int length2 = sArr.length - 1; int smear2 = Hashing.smear(obj2.hashCode()); while (true) { int i5 = smear2 & length2; int i6 = sArr[i5] & 65535; if (i6 == 65535) { return null; } if (obj2.equals(objArr[i6])) { return objArr[i6 ^ 1]; } smear2 = i5 + 1; } } else { int[] iArr = (int[]) obj; int length3 = iArr.length - 1; int smear3 = Hashing.smear(obj2.hashCode()); while (true) { int i7 = smear3 & length3; int i8 = iArr[i7]; if (i8 == -1) { return null; } if (obj2.equals(objArr[i8])) { return objArr[i8 ^ 1]; } smear3 = i7 + 1; } } } @Override // com.google.common.collect.ImmutableMap public ImmutableSet createEntrySet() { return new EntrySet(this, this.alternatingKeysAndValues, 0, this.size); } public static class EntrySet extends ImmutableSet { public final transient Object[] alternatingKeysAndValues; public final transient int keyOffset; public final transient ImmutableMap map; public final transient int size; @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return this.size; } public EntrySet(ImmutableMap immutableMap, Object[] objArr, int i, int i2) { this.map = immutableMap; this.alternatingKeysAndValues = objArr; this.keyOffset = i; this.size = i2; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public UnmodifiableIterator iterator() { return asList().iterator(); } @Override // com.google.common.collect.ImmutableCollection public int copyIntoArray(Object[] objArr, int i) { return asList().copyIntoArray(objArr, i); } @Override // com.google.common.collect.ImmutableSet public ImmutableList createAsList() { return new ImmutableList() { // from class: com.google.common.collect.RegularImmutableMap.EntrySet.1 @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } @Override // java.util.List public Map.Entry get(int i) { Preconditions.checkElementIndex(i, EntrySet.this.size); int i2 = i * 2; Object obj = EntrySet.this.alternatingKeysAndValues[EntrySet.this.keyOffset + i2]; Objects.requireNonNull(obj); Object obj2 = EntrySet.this.alternatingKeysAndValues[i2 + (EntrySet.this.keyOffset ^ 1)]; Objects.requireNonNull(obj2); return new AbstractMap.SimpleImmutableEntry(obj, obj2); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return EntrySet.this.size; } }; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; Object key = entry.getKey(); Object value = entry.getValue(); return value != null && value.equals(this.map.get(key)); } } @Override // com.google.common.collect.ImmutableMap public ImmutableSet createKeySet() { return new KeySet(this, new KeysOrValuesAsList(this.alternatingKeysAndValues, 0, this.size)); } public static final class KeysOrValuesAsList extends ImmutableList { public final transient Object[] alternatingKeysAndValues; public final transient int offset; public final transient int size; @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.size; } public KeysOrValuesAsList(Object[] objArr, int i, int i2) { this.alternatingKeysAndValues = objArr; this.offset = i; this.size = i2; } @Override // java.util.List public Object get(int i) { Preconditions.checkElementIndex(i, this.size); Object obj = this.alternatingKeysAndValues[(i * 2) + this.offset]; Objects.requireNonNull(obj); return obj; } } public static final class KeySet extends ImmutableSet { public final transient ImmutableList list; public final transient ImmutableMap map; @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection public ImmutableList asList() { return this.list; } @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } public KeySet(ImmutableMap immutableMap, ImmutableList immutableList) { this.map = immutableMap; this.list = immutableList; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public UnmodifiableIterator iterator() { return asList().iterator(); } @Override // com.google.common.collect.ImmutableCollection public int copyIntoArray(Object[] objArr, int i) { return asList().copyIntoArray(objArr, i); } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection public boolean contains(Object obj) { return this.map.get(obj) != null; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return this.map.size(); } } @Override // com.google.common.collect.ImmutableMap public ImmutableCollection createValues() { return new KeysOrValuesAsList(this.alternatingKeysAndValues, 1, this.size); } }