import java.util.Map;

/**
 * This provides a skeletal example of how resizing might work in a hash
 * table implementation.  <em>NOTE!</em> this is not a fully functional
 * implementation, it won't compile, and it doesn't take into account many
 * issues (like support for chaining).
 *
 * @author Terran Lane
 * @version 1.0
 */
public class ResizeHashTable implements Map {

  public ResizeHashTable(int initSz) {
    if (initSz<=0) {
      throw new IllegalArgumentException("Initial HashTable size must " +
					 "be >0");
    }
    _size=initSz;
    _table=new _element[_size];
    _loadFactor=0;
  }

  public Object put(Object key, Object value) {
    if (key==null) {
      throw new NullPointerException("Keys must be non-null");
    }
    // actually put key in table here...
    if (_loadFactor>_loadThresh) {
      _resizeTable();
    }
    return oldValue;
  }

  /* ******************** end of public interface ******************** */

  private int _size;
  private double _loadFactor;
  private double _loadThresh=0.5;
  private _element[] _table;

  private void _resizeTable() {
    int newSz=2*_size;
    _element[] newTab=new _element[newSz];
    // copy every key/val pair from old table to new
    _table=newTab;
    _size=newSz;
  }

}
