package cap19.tabellahash;

import IngressoUscita.Console;

class A
{ int i;
  A(int i)
  { this.i = i;
  }
  public String toString()
  { return "A(" + i + ")";
  }
  public boolean equals(Object o)
  { if (!(o instanceof A))
      return false;
    A a = (A) o;
    return i == a.i;
  }
  public int hashCode()
  { return i ^ (i << 16);
  }
}

class B
{ int i;
  B(int i)
  { this.i = i;
  }
  public String toString()
  { return "B(" + i + ")";
  }
}

class Test
{ public static void main(String[] args)
  { TabellaHashList t = new TabellaHashList(10);
    for (int i = 0; i < 50; i++)
    { if (t.insert(new A(i), new B(i)))
        Console.scriviStringa("OK " + i);
    }
    Console.scriviStringa(t.toString());
    for (int i = 0; i < 100; i += 3)
    { A a = new A(i);
      B b = (B) t.find(a);
      B b1;
      if (b != null)
      { Console.scriviStringa("found: " + b);
        if ((b1 = (B) t.extract(a)) != null)
          Console.scriviStringa("\tremoved " + b1);
      }
      else
        Console.scriviStringa("" + i + " not found");
    }
    Console.scriviStringa(t.toString());
  }
}
