// $Id: Bucket.java,v 1.1 1999/12/07 06:34:48 golem Exp $

package IR2;

import java.util.*;

public class Bucket extends Hashtable {

  private class BucketKey {
    public Bucket bucket;
    public Object obj;

    public BucketKey(Bucket b, Object o) { bucket = b; obj = o; }
    public int hashCode()                { return bucket.hashCode(obj); }
    public boolean equals(Object other) {
      if (other instanceof BucketKey)
        return bucket.equals(obj, ((BucketKey) other).obj);
      return bucket.equals(obj, other);
    }
    public String toString() { return obj.toString(); }
  }

  public synchronized Object put(Object key, Object value) {
    return super.put(new BucketKey(this, key), value);
  }

  public synchronized Enumeration keys() {
    final Enumeration e = super.keys();
    return new Enumeration() {
      public boolean hasMoreElements() {
        return e.hasMoreElements();
      }

      public Object nextElement() {
        return ((BucketKey) e.nextElement()).obj;
      }
    };
  }


  /* Overridable methods */
  public int hashCode(Object obj) { return obj.hashCode(); }
  public boolean equals(Object a, Object b) { return a == b; }

}
