Esempio n. 1
0
  @Override
  public E getRandom() {
    // long random = Math.round(Math.random() * setList.size());
    setList.goToFirst();

    // for(long i = 1; i < random; i++) {
    // setList.goToNext();
    // }

    return setList.retrieve();
  }
Esempio n. 2
0
  @Override
  public V getValue(K key) {
    Mapping map = new Mapping(key);

    if (this.containsKey(key)) {
      table.find(map);
      map = table.retrieve();
      return map.value;
    }
    return null;
  }
Esempio n. 3
0
  @Override
  public boolean subset(Set<E> S) {
    if (setList.isEmpty()) {
      return true;
    }

    do {
      if (!S.setList.find(setList.retrieve())) {
        return false;
      }
    } while (setList.goToNext());

    return true;
  }
Esempio n. 4
0
  @Override
  public Set<E> intersection(Set<E> S) {
    Set<E> intersection = new Set<E>();
    if (!setList.goToFirst()) return intersection;
    if (S.setList.isEmpty()) return intersection;

    do {
      E el = setList.retrieve();
      if (S.setList.find(el)) {
        intersection.addElement(el);
      }
    } while (setList.goToNext());

    return intersection;
  }
Esempio n. 5
0
  @Override
  public Set<E> difference(Set<E> S) {
    if (!setList.goToFirst()) return this;
    if (S.isEmpty()) return this;

    Set<E> difference = new Set<E>();

    do {
      E el = setList.retrieve();
      if (!S.setList.find(el)) {
        difference.addElement(el);
      }
    } while (setList.goToNext());

    return difference;
  }
Esempio n. 6
0
  @Override
  public Table<K, V> clone() {
    Table copy;

    try {
      copy = (Table) super.clone();
    } catch (CloneNotSupportedException e) {
      throw new Error("");
    }

    copy.table = new List<Mapping>();

    Mapping map;
    for (int i = 0; i < this.size(); i++) {
      map = table.retrieve();
      copy.addEntry(map.key, map.value);
      table.goToNext();
    }

    return copy;
  }