Beispiel #1
0
  /**
   * Tests to see if the Person is in the HashTable.
   *
   * @param p a Person Object
   * @return true if Person is in the HashTable, false if not
   */
  @Override
  public boolean contains(PersonInterface p) {

    int num = p.hashCode() % 10;

    for (int i = 0; i < peop.get(num).size(); i++) {
      if (peop.get(num).get(i).hashCode() == p.hashCode()) {
        return true;
      }
    }

    return false;
  }
Beispiel #2
0
  /**
   * Adds an element to this set. Adds to the appropriate LinkedList by taking the Person HashCode()
   * and mod (%) by the table size.
   *
   * @param p a Person to add to the HashTable
   * @return the number of People currently in HashTable
   */
  @Override
  public int add(PersonInterface p) {

    int place = p.hashCode() % 10;

    peop.get(place).add(p);

    return numpep++;
  }