示例#1
0
文件: Set.java 项目: rubenhelsloot/vp
  @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();
  }
示例#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;
  }
示例#3
0
文件: Set.java 项目: rubenhelsloot/vp
  @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;
  }
示例#4
0
文件: Set.java 项目: rubenhelsloot/vp
  @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;
  }
示例#5
0
文件: Set.java 项目: rubenhelsloot/vp
  @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;
  }
示例#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;
  }