package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSDualNode;
import net.runelite.rs.api.RSEvictingDualNodeHashTable;
import net.runelite.rs.api.RSIterableDualNodeQueue;
import net.runelite.rs.api.RSIterableNodeHashTable;

@ObfuscatedName("lk")
public final class EvictingDualNodeHashTable implements RSEvictingDualNodeHashTable {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lsn;"
   )
   DualNode dualNode;
   @ObfuscatedName("ah")
   int capacity;
   @ObfuscatedName("ar")
   int remainingCapacity;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Ltz;"
   )
   IterableNodeHashTable hashTable;
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Lpo;"
   )
   IterableDualNodeQueue deque;
   public float threshold;
   public int tmpCapacity;

   public EvictingDualNodeHashTable(int var1) {
      this.dualNode = new DualNode();
      this.deque = new IterableDualNodeQueue();
      this.capacity = var1;
      this.remainingCapacity = var1;

      int var2;
      for(var2 = 1; var2 + var2 < var1; var2 += var2) {
         ;
      }

      this.hashTable = new IterableNodeHashTable(var2);
      this.rl$$init();
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(J)Lsn;"
   )
   public DualNode get(long var1) {
      DualNode var3 = (DualNode)this.hashTable.get(var1);
      if(var3 != null) {
         this.deque.method7382(var3);
      }

      return var3;
   }

   @ObfuscatedName("ah")
   public void remove_base(long var1) {
      DualNode var3 = (DualNode)this.hashTable.get(var1);
      if(var3 != null) {
         var3.remove_base();
         var3.removeDual_base();
         ++this.remainingCapacity;
      }

   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Lsn;J)V"
   )
   public void put(DualNode var1, long var2) {
      if(this.remainingCapacity == 0) {
         DualNode var4 = this.deque.method7384();
         var4.remove_base();
         var4.removeDual_base();
         if(var4 == this.dualNode) {
            var4 = this.deque.method7384();
            var4.remove_base();
            var4.removeDual_base();
         }
      } else {
         --this.remainingCapacity;
      }

      this.hashTable.put(var1, var2);
      this.deque.method7382(var1);
   }

   public void put(RSDualNode var1, long var2) {
      this.put((DualNode)var1, var2);
   }

   @ObfuscatedName("ao")
   public void clear_base() {
      this.deque.clear_base();
      this.hashTable.clear_base();
      this.dualNode = new DualNode();
      this.remainingCapacity = this.capacity;
   }

   public void increaseCapacity(int var1) {
      if(var1 > this.getCapacity()) {
         int var2;
         for(var2 = 1; var2 < var1; var2 += var2) {
            ;
         }

         this.setCapacity(var2);
         this.reset();
         RSIterableNodeHashTable var3 = SpriteMask.client.createIterableNodeHashTable(var2);
         this.setHashTable(var3);
      }

   }

   public int getRemainingCapacity() {
      return this.remainingCapacity;
   }

   public int getCapacity() {
      return this.capacity;
   }

   public void setTmpCapacity(int var1) {
      this.tmpCapacity = var1;
   }

   public RSDualNode getDualNode() {
      return this.dualNode;
   }

   public void setCapacity(int var1) {
      this.capacity = var1;
   }

   public void reset() {
      this.clear_base();
   }

   public void setHashTable(RSIterableNodeHashTable var1) {
      this.hashTable = (IterableNodeHashTable)var1;
   }

   private void rl$$init() {
      this.setTmpCapacity(this.getCapacity());
   }

   public float getThreshold() {
      return this.threshold;
   }

   public void setThreshold(float var1) {
      this.threshold = var1;
   }

   public int getTmpCapacity() {
      return this.tmpCapacity;
   }

   public boolean isTrashing() {
      return this.getRemainingCapacity() <= 0 && this.getDualNode().previousDual() == null;
   }

   public void resize(int var1) {
      this.increaseCapacity(var1);
      this.tmpCapacity = this.getCapacity();
   }

   public void setRemainingCapacity(int var1) {
      this.remainingCapacity = var1;
   }

   public RSIterableDualNodeQueue getDeque() {
      return this.deque;
   }
}
