Comepletata la ListPartion aggiungendo alcuni metodi a OrderedListset
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
package partition;
|
||||
|
||||
import map.HashTableMap;
|
||||
import position.NodePositionList;
|
||||
import position.PositionList;
|
||||
import set.OrderedListSet;
|
||||
import set.Set;
|
||||
import utility.DefaultComparator;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
@@ -10,30 +18,91 @@ import set.Set;
|
||||
*/
|
||||
public class ListPartition <E> implements Partition<E> {
|
||||
|
||||
private HashTableMap<E,Set<E>> elementi;
|
||||
private PositionList<Set<E>> partizione;
|
||||
|
||||
public ListPartition () {
|
||||
elementi = new HashTableMap<E, Set<E>>();
|
||||
partizione = new NodePositionList<Set<E>>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
return elementi.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
return (size() == 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> makeSet(E x) {
|
||||
try {
|
||||
OrderedListSet<E> o = new OrderedListSet<E>(x, new DefaultComparator<E>());
|
||||
elementi.put(x, o);
|
||||
partizione.addLast(o);
|
||||
o.setLocation(partizione.last());
|
||||
return o;
|
||||
}
|
||||
catch (InvalidKeyException e){
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> union(Set<E> A, Set<E> B) {
|
||||
try {
|
||||
if (A.size() > B.size()){
|
||||
OrderedListSet<E> AA = (OrderedListSet<E>) A;
|
||||
OrderedListSet<E> BB = (OrderedListSet<E>) B;
|
||||
AA.fastUnion(BB);
|
||||
partizione.remove(BB.location());
|
||||
BB.setLocation(null);
|
||||
Iterator<E> it = BB.list().iterator();
|
||||
for (;it.hasNext();)
|
||||
elementi.put(it.next(),AA);
|
||||
return AA;
|
||||
|
||||
} else {
|
||||
|
||||
OrderedListSet<E> AA = (OrderedListSet<E>) B;
|
||||
OrderedListSet<E> BB = (OrderedListSet<E>) A;
|
||||
AA.fastUnion(BB);
|
||||
partizione.remove(BB.location());
|
||||
BB.setLocation(null);
|
||||
Iterator<E> it = BB.list().iterator();
|
||||
for (;it.hasNext();)
|
||||
elementi.put(it.next(),AA);
|
||||
return AA;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (InvalidKeyException e){
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> find(E x) {
|
||||
try {
|
||||
return elementi.get(x);
|
||||
}
|
||||
catch (InvalidKeyException e){
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return partizione.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user