diff --git a/src/resonantinduction/base/SetUtil.java b/src/resonantinduction/base/SetUtil.java index 724fc554..a635c33b 100644 --- a/src/resonantinduction/base/SetUtil.java +++ b/src/resonantinduction/base/SetUtil.java @@ -48,4 +48,44 @@ public class SetUtil return toReturn; } + + public static Set[] split(Set set, int divide) + { + int remain = set.size()%divide; + int size = (set.size()/divide)-remain; + + Set[] toReturn = new HashSet[divide]; + + for(Set iterSet : toReturn) + { + Set removed = new HashSet(); + + int toAdd = size; + + if(remain > 0) + { + remain--; + toAdd++; + } + + for(V obj : set) + { + if(toAdd == 0) + { + break; + } + + iterSet.add(obj); + removed.add(obj); + toAdd--; + } + + for(V obj : removed) + { + set.remove(obj); + } + } + + return toReturn; + } }