package b5; import java.io.Serializable; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes2.dex */ public final class h extends AbstractMap implements Serializable { /* renamed from: h, reason: collision with root package name */ private static final Comparator f3189h = new a(); /* renamed from: a, reason: collision with root package name */ Comparator f3190a; /* renamed from: b, reason: collision with root package name */ e f3191b; /* renamed from: c, reason: collision with root package name */ int f3192c; /* renamed from: d, reason: collision with root package name */ int f3193d; /* renamed from: e, reason: collision with root package name */ final e f3194e; /* renamed from: f, reason: collision with root package name */ private b f3195f; /* renamed from: g, reason: collision with root package name */ private c f3196g; class a implements Comparator { a() { } @Override // java.util.Comparator /* renamed from: a, reason: merged with bridge method [inline-methods] */ public int compare(Comparable comparable, Comparable comparable2) { return comparable.compareTo(comparable2); } } class b extends AbstractSet { class a extends d { a() { super(); } @Override // java.util.Iterator /* renamed from: b, reason: merged with bridge method [inline-methods] */ public Map.Entry next() { return a(); } } b() { } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { h.this.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return (obj instanceof Map.Entry) && h.this.c((Map.Entry) obj) != null; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return new a(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { e c10; if (!(obj instanceof Map.Entry) || (c10 = h.this.c((Map.Entry) obj)) == null) { return false; } h.this.f(c10, true); return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return h.this.f3192c; } } final class c extends AbstractSet { class a extends d { a() { super(); } @Override // java.util.Iterator public Object next() { return a().f3210f; } } c() { } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { h.this.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return h.this.containsKey(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return new a(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { return h.this.g(obj) != null; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return h.this.f3192c; } } private abstract class d implements Iterator { /* renamed from: a, reason: collision with root package name */ e f3201a; /* renamed from: b, reason: collision with root package name */ e f3202b = null; /* renamed from: c, reason: collision with root package name */ int f3203c; d() { this.f3201a = h.this.f3194e.f3208d; this.f3203c = h.this.f3193d; } final e a() { e eVar = this.f3201a; h hVar = h.this; if (eVar == hVar.f3194e) { throw new NoSuchElementException(); } if (hVar.f3193d != this.f3203c) { throw new ConcurrentModificationException(); } this.f3201a = eVar.f3208d; this.f3202b = eVar; return eVar; } @Override // java.util.Iterator public final boolean hasNext() { return this.f3201a != h.this.f3194e; } @Override // java.util.Iterator public final void remove() { e eVar = this.f3202b; if (eVar == null) { throw new IllegalStateException(); } h.this.f(eVar, true); this.f3202b = null; this.f3203c = h.this.f3193d; } } public h() { this(f3189h); } private boolean a(Object obj, Object obj2) { return obj == obj2 || (obj != null && obj.equals(obj2)); } private void e(e eVar, boolean z10) { while (eVar != null) { e eVar2 = eVar.f3206b; e eVar3 = eVar.f3207c; int i10 = eVar2 != null ? eVar2.f3212h : 0; int i11 = eVar3 != null ? eVar3.f3212h : 0; int i12 = i10 - i11; if (i12 == -2) { e eVar4 = eVar3.f3206b; e eVar5 = eVar3.f3207c; int i13 = (eVar4 != null ? eVar4.f3212h : 0) - (eVar5 != null ? eVar5.f3212h : 0); if (i13 == -1 || (i13 == 0 && !z10)) { i(eVar); } else { j(eVar3); i(eVar); } if (z10) { return; } } else if (i12 == 2) { e eVar6 = eVar2.f3206b; e eVar7 = eVar2.f3207c; int i14 = (eVar6 != null ? eVar6.f3212h : 0) - (eVar7 != null ? eVar7.f3212h : 0); if (i14 == 1 || (i14 == 0 && !z10)) { j(eVar); } else { i(eVar2); j(eVar); } if (z10) { return; } } else if (i12 == 0) { eVar.f3212h = i10 + 1; if (z10) { return; } } else { eVar.f3212h = Math.max(i10, i11) + 1; if (!z10) { return; } } eVar = eVar.f3205a; } } private void h(e eVar, e eVar2) { e eVar3 = eVar.f3205a; eVar.f3205a = null; if (eVar2 != null) { eVar2.f3205a = eVar3; } if (eVar3 == null) { this.f3191b = eVar2; } else if (eVar3.f3206b == eVar) { eVar3.f3206b = eVar2; } else { eVar3.f3207c = eVar2; } } private void i(e eVar) { e eVar2 = eVar.f3206b; e eVar3 = eVar.f3207c; e eVar4 = eVar3.f3206b; e eVar5 = eVar3.f3207c; eVar.f3207c = eVar4; if (eVar4 != null) { eVar4.f3205a = eVar; } h(eVar, eVar3); eVar3.f3206b = eVar; eVar.f3205a = eVar3; int max = Math.max(eVar2 != null ? eVar2.f3212h : 0, eVar4 != null ? eVar4.f3212h : 0) + 1; eVar.f3212h = max; eVar3.f3212h = Math.max(max, eVar5 != null ? eVar5.f3212h : 0) + 1; } private void j(e eVar) { e eVar2 = eVar.f3206b; e eVar3 = eVar.f3207c; e eVar4 = eVar2.f3206b; e eVar5 = eVar2.f3207c; eVar.f3206b = eVar5; if (eVar5 != null) { eVar5.f3205a = eVar; } h(eVar, eVar2); eVar2.f3207c = eVar; eVar.f3205a = eVar2; int max = Math.max(eVar3 != null ? eVar3.f3212h : 0, eVar5 != null ? eVar5.f3212h : 0) + 1; eVar.f3212h = max; eVar2.f3212h = Math.max(max, eVar4 != null ? eVar4.f3212h : 0) + 1; } e b(Object obj, boolean z10) { int i10; e eVar; Comparator comparator = this.f3190a; e eVar2 = this.f3191b; if (eVar2 != null) { Comparable comparable = comparator == f3189h ? (Comparable) obj : null; while (true) { i10 = comparable != null ? comparable.compareTo(eVar2.f3210f) : comparator.compare(obj, eVar2.f3210f); if (i10 == 0) { return eVar2; } e eVar3 = i10 < 0 ? eVar2.f3206b : eVar2.f3207c; if (eVar3 == null) { break; } eVar2 = eVar3; } } else { i10 = 0; } if (!z10) { return null; } e eVar4 = this.f3194e; if (eVar2 != null) { eVar = new e(eVar2, obj, eVar4, eVar4.f3209e); if (i10 < 0) { eVar2.f3206b = eVar; } else { eVar2.f3207c = eVar; } e(eVar2, true); } else { if (comparator == f3189h && !(obj instanceof Comparable)) { throw new ClassCastException(obj.getClass().getName() + " is not Comparable"); } eVar = new e(eVar2, obj, eVar4, eVar4.f3209e); this.f3191b = eVar; } this.f3192c++; this.f3193d++; return eVar; } e c(Map.Entry entry) { e d10 = d(entry.getKey()); if (d10 != null && a(d10.f3211g, entry.getValue())) { return d10; } return null; } @Override // java.util.AbstractMap, java.util.Map public void clear() { this.f3191b = null; this.f3192c = 0; this.f3193d++; e eVar = this.f3194e; eVar.f3209e = eVar; eVar.f3208d = eVar; } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return d(obj) != null; } e d(Object obj) { if (obj == null) { return null; } try { return b(obj, false); } catch (ClassCastException unused) { return null; } } @Override // java.util.AbstractMap, java.util.Map public Set entrySet() { b bVar = this.f3195f; if (bVar != null) { return bVar; } b bVar2 = new b(); this.f3195f = bVar2; return bVar2; } void f(e eVar, boolean z10) { int i10; if (z10) { e eVar2 = eVar.f3209e; eVar2.f3208d = eVar.f3208d; eVar.f3208d.f3209e = eVar2; } e eVar3 = eVar.f3206b; e eVar4 = eVar.f3207c; e eVar5 = eVar.f3205a; int i11 = 0; if (eVar3 == null || eVar4 == null) { if (eVar3 != null) { h(eVar, eVar3); eVar.f3206b = null; } else if (eVar4 != null) { h(eVar, eVar4); eVar.f3207c = null; } else { h(eVar, null); } e(eVar5, false); this.f3192c--; this.f3193d++; return; } e b10 = eVar3.f3212h > eVar4.f3212h ? eVar3.b() : eVar4.a(); f(b10, false); e eVar6 = eVar.f3206b; if (eVar6 != null) { i10 = eVar6.f3212h; b10.f3206b = eVar6; eVar6.f3205a = b10; eVar.f3206b = null; } else { i10 = 0; } e eVar7 = eVar.f3207c; if (eVar7 != null) { i11 = eVar7.f3212h; b10.f3207c = eVar7; eVar7.f3205a = b10; eVar.f3207c = null; } b10.f3212h = Math.max(i10, i11) + 1; h(eVar, b10); } e g(Object obj) { e d10 = d(obj); if (d10 != null) { f(d10, true); } return d10; } @Override // java.util.AbstractMap, java.util.Map public Object get(Object obj) { e d10 = d(obj); if (d10 != null) { return d10.f3211g; } return null; } @Override // java.util.AbstractMap, java.util.Map public Set keySet() { c cVar = this.f3196g; if (cVar != null) { return cVar; } c cVar2 = new c(); this.f3196g = cVar2; return cVar2; } @Override // java.util.AbstractMap, java.util.Map public Object put(Object obj, Object obj2) { if (obj == null) { throw new NullPointerException("key == null"); } e b10 = b(obj, true); Object obj3 = b10.f3211g; b10.f3211g = obj2; return obj3; } @Override // java.util.AbstractMap, java.util.Map public Object remove(Object obj) { e g10 = g(obj); if (g10 != null) { return g10.f3211g; } return null; } @Override // java.util.AbstractMap, java.util.Map public int size() { return this.f3192c; } public h(Comparator comparator) { this.f3192c = 0; this.f3193d = 0; this.f3194e = new e(); this.f3190a = comparator == null ? f3189h : comparator; } static final class e implements Map.Entry { /* renamed from: a, reason: collision with root package name */ e f3205a; /* renamed from: b, reason: collision with root package name */ e f3206b; /* renamed from: c, reason: collision with root package name */ e f3207c; /* renamed from: d, reason: collision with root package name */ e f3208d; /* renamed from: e, reason: collision with root package name */ e f3209e; /* renamed from: f, reason: collision with root package name */ final Object f3210f; /* renamed from: g, reason: collision with root package name */ Object f3211g; /* renamed from: h, reason: collision with root package name */ int f3212h; e() { this.f3210f = null; this.f3209e = this; this.f3208d = this; } public e a() { e eVar = this; for (e eVar2 = this.f3206b; eVar2 != null; eVar2 = eVar2.f3206b) { eVar = eVar2; } return eVar; } public e b() { e eVar = this; for (e eVar2 = this.f3207c; eVar2 != null; eVar2 = eVar2.f3207c) { eVar = eVar2; } return eVar; } @Override // java.util.Map.Entry public boolean equals(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; Object obj2 = this.f3210f; if (obj2 == null) { if (entry.getKey() != null) { return false; } } else if (!obj2.equals(entry.getKey())) { return false; } Object obj3 = this.f3211g; if (obj3 == null) { if (entry.getValue() != null) { return false; } } else if (!obj3.equals(entry.getValue())) { return false; } return true; } @Override // java.util.Map.Entry public Object getKey() { return this.f3210f; } @Override // java.util.Map.Entry public Object getValue() { return this.f3211g; } @Override // java.util.Map.Entry public int hashCode() { Object obj = this.f3210f; int hashCode = obj == null ? 0 : obj.hashCode(); Object obj2 = this.f3211g; return hashCode ^ (obj2 != null ? obj2.hashCode() : 0); } @Override // java.util.Map.Entry public Object setValue(Object obj) { Object obj2 = this.f3211g; this.f3211g = obj; return obj2; } public String toString() { return this.f3210f + "=" + this.f3211g; } e(e eVar, Object obj, e eVar2, e eVar3) { this.f3205a = eVar; this.f3210f = obj; this.f3212h = 1; this.f3208d = eVar2; this.f3209e = eVar3; eVar3.f3208d = this; eVar2.f3209e = this; } } }