package m2; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; /* loaded from: classes.dex */ public class g { /* renamed from: a, reason: collision with root package name */ private final Map f11796a = new LinkedHashMap(100, 0.75f, true); /* renamed from: b, reason: collision with root package name */ private final long f11797b; /* renamed from: c, reason: collision with root package name */ private long f11798c; /* renamed from: d, reason: collision with root package name */ private long f11799d; static final class a { /* renamed from: a, reason: collision with root package name */ final Object f11800a; /* renamed from: b, reason: collision with root package name */ final int f11801b; a(Object obj, int i10) { this.f11800a = obj; this.f11801b = i10; } } public g(long j10) { this.f11797b = j10; this.f11798c = j10; } private void f() { m(this.f11798c); } public void b() { m(0L); } public synchronized Object g(Object obj) { a aVar; aVar = (a) this.f11796a.get(obj); return aVar != null ? aVar.f11800a : null; } public synchronized long h() { return this.f11798c; } protected int i(Object obj) { return 1; } protected void j(Object obj, Object obj2) { } public synchronized Object k(Object obj, Object obj2) { int i10 = i(obj2); long j10 = i10; if (j10 >= this.f11798c) { j(obj, obj2); return null; } if (obj2 != null) { this.f11799d += j10; } a aVar = (a) this.f11796a.put(obj, obj2 == null ? null : new a(obj2, i10)); if (aVar != null) { this.f11799d -= aVar.f11801b; if (!aVar.f11800a.equals(obj2)) { j(obj, aVar.f11800a); } } f(); return aVar != null ? aVar.f11800a : null; } public synchronized Object l(Object obj) { a aVar = (a) this.f11796a.remove(obj); if (aVar == null) { return null; } this.f11799d -= aVar.f11801b; return aVar.f11800a; } protected synchronized void m(long j10) { while (this.f11799d > j10) { Iterator it = this.f11796a.entrySet().iterator(); Map.Entry entry = (Map.Entry) it.next(); a aVar = (a) entry.getValue(); this.f11799d -= aVar.f11801b; Object key = entry.getKey(); it.remove(); j(key, aVar.f11800a); } } }