/** Creates the power set of the items in elements.
*
* This version of the method will modify the elements list
* as the power set is built.
*
* @param <ElementType> Type of elements.
* @param elements Items to create power set over.
* @return Returns power set of elements.
*/
private static <ElementType> Set<Set<ElementType>> getPowerSetDestructive(Set<ElementType> elements) {
if ( elements.isEmpty() ) {
return Collections.EMPTY_SET;
}
else if ( elements.size() == 1 ) {
HashSet<Set<ElementType>> s = new HashSet<Set<ElementType>>();
s.add(Collections.EMPTY_SET);
s.add(Collections.singleton(elements.iterator().next()));
return s;
}
else {
ElementType e = elements.iterator().next(); // Next is gaurantee to work, since we check isEmpty
elements.remove(e);
Set<Set<ElementType>> pT = getPowerSetDestructive(elements);
Set<Set<ElementType>> cross = getCrossProduct(pT, e);
pT.addAll(cross);
return pT;
}
}
Utils.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:BoostSRL
作者:
评论列表
文章目录