Esempio n. 1
0
  public ISet intersect(ISet other) {
    ShareableValuesHashSet commonData = new ShareableValuesHashSet();
    Iterator<IValue> setIterator;

    ISet theOtherSet;

    if (other.size() <= size()) {
      setIterator = other.iterator();
      theOtherSet = this;
    } else {
      setIterator = iterator();
      theOtherSet = other;
    }

    Type newElementType = TypeFactory.getInstance().voidType();
    while (setIterator.hasNext()) {
      IValue value = setIterator.next();
      if (theOtherSet.contains(value)) {
        newElementType = newElementType.lub(value.getType());
        commonData.add(value);
      }
    }

    return new SetWriter(newElementType, commonData).done();
  }
Esempio n. 2
0
  public ISet insert(IValue value) {
    if (!contains(value)) {
      ShareableValuesHashSet newData = new ShareableValuesHashSet(data);
      newData.add(value);

      Type type = elementType.lub(value.getType());
      return new SetWriter(type, newData).done();
    } else {
      return this;
    }
  }
Esempio n. 3
0
  public ISet product(ISet other) {
    ShareableValuesHashSet newData = new ShareableValuesHashSet();

    Type tupleType = typeFactory.tupleType(elementType, other.getElementType());

    Iterator<IValue> thisIterator = data.iterator();
    while (thisIterator.hasNext()) {
      IValue left = thisIterator.next();

      Iterator<IValue> setIterator = other.iterator();
      while (setIterator.hasNext()) {
        IValue right = setIterator.next();

        IValue[] tuple = new IValue[] {left, right};
        newData.add(Tuple.newTuple(tupleType, tuple));
      }
    }

    return new SetWriter(tupleType, newData).done();
  }
Esempio n. 4
0
  public ISet union(ISet other) {
    ShareableValuesHashSet newData;
    Iterator<IValue> setIterator;

    Set otherSet = (Set) other;

    if (otherSet.size() <= size()) {
      newData = new ShareableValuesHashSet(data);
      setIterator = otherSet.iterator();
    } else {
      newData = new ShareableValuesHashSet(otherSet.data);
      setIterator = iterator();
    }

    while (setIterator.hasNext()) {
      newData.add(setIterator.next());
    }

    Type newElementType = elementType.lub(otherSet.elementType);
    return new SetWriter(newElementType, newData).done();
  }