Java Code Examples for gnu.trove.set.hash.THashSet#removeAll()

The following examples show how to use gnu.trove.set.hash.THashSet#removeAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DFDMiner.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private Stack<Seed> nextSeeds(int currentRHSIndex) {
//		System.out.println("Find holes");
		THashSet<ColumnCollection> deps = new THashSet<>();
		ArrayList<ColumnCollection> currentMaximalNonDependencies = maximalNonDependencies.getLHSForRHS(currentRHSIndex);
		HashSet<ColumnCollection> currentMinimalDependencies = new HashSet<>(minimalDependencies.getLHSForRHS(currentRHSIndex));
		ArrayList<ColumnCollection> newDeps = new ArrayList<>(numberOfColumns * deps.size());
//		Holes holes = new Holes();
		
//		int i = 0;
//		for (ColumnCollection maximalNonDependency : currentMaximalNonDependencies) {
//			ColumnCollection complement = maximalNonDependency.setCopy(currentRHSIndex).complement();
//			if (deps.isEmpty()) {
//				ColumnCollection emptyColumnIndices = new ColumnCollection(numberOfColumns);
//				for (Integer complementColumnIndex : complement.getSetBits()) {
//					deps.add(emptyColumnIndices.setCopy(complementColumnIndex));
//				}
//			} else {
//				for (ColumnCollection dep : deps) {
//					int[] setBits = complement.getSetBits();
//					for (int setBit = 0; setBit < setBits.length; setBit++) {
//						holes.add(dep.setCopy(setBits[setBit]));
////						System.out.println("Dep:\t" + dep.setCopy(setBits[setBit]));
//					}
//				}
//				// minimize newDeps
//				System.out.println(i++ + "\t" + currentMaximalNonDependencies.size());
//				System.out.println("total deps:\t" + deps.size());
//				System.out.println("before minimizing:\t" + holes.size());
////				ArrayList<ColumnCollection> minimizedNewDeps = minimizeSeeds(newDeps);
//				holes.minimize();
//				System.out.println("after minimizing:\t" + holes.size());
//				deps.clear();
//				deps.addAll(holes);
//				holes.clear();
//			}
//		}

		for (ColumnCollection maximalNonDependency : currentMaximalNonDependencies) {
			ColumnCollection complement = maximalNonDependency.setCopy(currentRHSIndex).complement();
			if (deps.isEmpty()) {
				ColumnCollection emptyColumnIndices = new ColumnCollection(numberOfColumns);
				for (int complementColumnIndex : complement.getSetBits()) {
					deps.add(emptyColumnIndices.setCopy(complementColumnIndex));
				}
			} else {
				for (ColumnCollection dep : deps) {
					int[] setBits = complement.getSetBits();
					for (int setBit = 0; setBit < setBits.length; setBit++) {
						newDeps.add(dep.setCopy(setBits[setBit]));
					}
				}
				// minimize newDeps
				ArrayList<ColumnCollection> minimizedNewDeps = minimizeSeeds(newDeps);
				deps.clear();
				deps.addAll(minimizedNewDeps);
				newDeps.clear();
			}
		}
		
		// return only elements that aren't already covered by the minimal
		// dependencies
		Stack<Seed> remainingSeeds = new Stack<>();
		deps.removeAll(currentMinimalDependencies);
		for (ColumnCollection remainingSeed : deps) {
			remainingSeeds.push(new Seed(remainingSeed));
		}

		return remainingSeeds;
	}
 
Example 2
Source File: DFDMiner.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private Seed randomWalkStep(Seed currentSeed, int currentRHSIndex) {
	Observation observationOfSeed = this.observations.get(currentSeed.getIndices());

	if (observationOfSeed == Observation.CANDIDATE_MINIMAL_DEPENDENCY) {
		THashSet<ColumnCollection> uncheckedSubsets = this.observations.getUncheckedMaximalSubsets(currentSeed.getIndices(), columnOrder);
		THashSet<ColumnCollection> prunedNonDependencySubsets = nonDependencies.getPrunedSupersets(uncheckedSubsets);
		for (ColumnCollection prunedNonDependencySubset : prunedNonDependencySubsets) {
			observations.put(prunedNonDependencySubset, Observation.NON_DEPENDENCY);
		}
		uncheckedSubsets.removeAll(prunedNonDependencySubsets);
		if (uncheckedSubsets.isEmpty() && prunedNonDependencySubsets.isEmpty()) {
			observations.put(currentSeed.getIndices(), Observation.MINIMAL_DEPENDENCY);
			minimalDependencies.addRHSColumn(currentSeed.getIndices(), currentRHSIndex);
		} else if (!uncheckedSubsets.isEmpty()) {
			ColumnCollection notRepresentedUncheckedSubset = uncheckedSubsets.iterator().next();
			if (notRepresentedUncheckedSubset != null) {
				trace.push(currentSeed);
				return new Seed(notRepresentedUncheckedSubset);
			}
		}
	} else if (observationOfSeed == Observation.CANDIDATE_MAXIMAL_NON_DEPENDENCY) {
		THashSet<ColumnCollection> uncheckedSupersets = this.observations.getUncheckedMinimalSupersets(currentSeed.getIndices(), currentRHSIndex, columnOrder);
		THashSet<ColumnCollection> prunedNonDependencySupersets = nonDependencies.getPrunedSupersets(uncheckedSupersets);
		THashSet<ColumnCollection> prunedDependencySupersets = dependencies.getPrunedSubsets(uncheckedSupersets);
		for (ColumnCollection prunedNonDependencySuperset : prunedNonDependencySupersets) {
			observations.put(prunedNonDependencySuperset, Observation.NON_DEPENDENCY);
		}
		for (ColumnCollection prunedDependencySuperset : prunedDependencySupersets) {
			observations.put(prunedDependencySuperset, Observation.DEPENDENCY);
		}
		uncheckedSupersets.removeAll(prunedDependencySupersets);
		uncheckedSupersets.removeAll(prunedNonDependencySupersets);
		if (uncheckedSupersets.isEmpty() && prunedNonDependencySupersets.isEmpty()) {
			observations.put(currentSeed.getIndices(), Observation.MAXIMAL_NON_DEPENDENCY);
			maximalNonDependencies.addRHSColumn(currentSeed.getIndices(), currentRHSIndex);
		} else if (!uncheckedSupersets.isEmpty()) {
			ColumnCollection notRepresentedUncheckedSuperset = uncheckedSupersets.iterator().next();
			if (notRepresentedUncheckedSuperset != null) {
				trace.push(currentSeed);
				int additionalColumn = notRepresentedUncheckedSuperset.removeCopy(currentSeed.getIndices()).nextSetBit(0);
				return new Seed(notRepresentedUncheckedSuperset, additionalColumn);
			}
		}
	}
	if (!this.trace.isEmpty()) {
		Seed nextSeed = this.trace.pop();
		return nextSeed;
	}
	return null;
}