public static <E> PSet<E> set() { return HashTreePSet.empty(); }
public void testSet() { PSet<String> a = HashTreePSet.empty(), b = HashTreePSet.empty(); assertEqualsAndHash("empty sets not equal",a,b); assertTrue("adding element should change empty set",!a.equals(a.plus("one"))); a = a.plus("one"); assertEqualsAndHash("adding duplicate should not change set",a,a.plus("one")); a = a.plus("two").plus(""); b = b.plus("two").plus("").plus("one").plus("two"); assertEqualsAndHash(a,b); b = b.plus("three"); assertTrue(!a.equals(b)); int n = b.size(); for(@SuppressWarnings("unused") String s : b) n--; assertTrue("iterator() should return size() elements", n==0); assertEqualsAndHash("adding a set to itself should do nothing",b,b.plusAll(b)); assertEqualsAndHash("adding a set to the empty set should be identity", b, MapPSet.from(HashTreePMap.<String,Object>empty(), b)); // bug Mike found: assertEqualsAndHash(HashTreePSet.from(Arrays.asList(2)), HashTreePSet.empty().plus(1).plus(2).minus(1)); }
public static <T> PSet<T> singleton(T value){ return new PSetXImpl<>(HashTreePSet.singleton(value)); } public static<T> PSet<T> fromCollection(Collection<T> stream){
public static<T> PSet<T> fromCollection(Collection<T> stream){ if(stream instanceof PSet) return (PSet)(stream); return HashTreePSet.from(stream); } public static<T> PSet<T> fromStream(Stream<T> stream){
/** * <pre> * {@code * PSet<Integer> q = Reducers.<Integer>toPSet() .mapReduce(Stream.of(1,2,3,4)); * * } * </pre> * @return Reducer for PSet */ public static <T> Reducer<PSet<T>> toPSet() { return Reducer.<PSet<T>> of(HashTreePSet.empty(), (final PSet<T> a) -> b -> a.plusAll(b), (final T x) -> HashTreePSet.singleton(x)); } /**
void release(Class type,ProxyWrapper proxy){ mergeProxies(type,HashTreePSet.singleton(proxy)); } }
public static <T> PSet<T> of(T...values){ return HashTreePSet.from(Arrays.asList(values)); } public static <T> PSet<T> empty(){
public static <E> PSet<E> set() { return HashTreePSet.empty(); }
void release(Class type,ProxyWrapper proxy){ mergeProxies(type,HashTreePSet.singleton(proxy)); } }
public static <T> PSetX<T> of(T...values){ return new PSetXImpl<>(HashTreePSet.from(Arrays.asList(values))); } public static <T> PSetX<T> empty(){
/** * @param <E> * @param list * @return empty().plusAll(map) */ public static <E> MapPSet<E> from(final Collection<? extends E> list) { return HashTreePSet.<E>empty().plusAll(list); } }
void release(Class type,ProxyWrapper proxy){ mergeProxies(type,HashTreePSet.singleton(proxy)); } }
@SuppressWarnings("unchecked") private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { try { Field contentsField = getClass().getDeclaredField("contents"); contentsField.setAccessible(true); contentsField.set(this, TreePVector.from((List<E>) in.readObject())); Field markField = getClass().getDeclaredField("mark"); markField.setAccessible(true); markField.set(this, HashTreePSet.from((Set<E>) in.readObject())); } catch (IllegalAccessException | NoSuchFieldException e) { throw new IOException(e); } }
/** * @param <E> * @param e * @return empty().plus(e) */ public static <E> MapPSet<E> singleton(final E e) { return HashTreePSet.<E>empty().plus(e); }
public static <T> PSetX<T> singleton(T value){ return new PSetXImpl<>(HashTreePSet.singleton(value)); } public static<T> PSetX<T> fromCollection(Collection<T> stream){
public static<T> PSetX<T> fromCollection(Collection<T> stream){ if(stream instanceof PSetX) return (PSetX)(stream); if(stream instanceof PSet) return new PSetXImpl<>((PSet)(stream)); return new PSetXImpl<>(HashTreePSet.from(stream)); } public static<T> PSetX<T> fromStream(Stream<T> stream){
/** * @param <E> * @param e * @return empty().plus(e) */ public static <E> MapPSet<E> singleton(final E e) { return HashTreePSet.<E>empty().plus(e); }
public static <T> PersistentSetX<T> singleton(final T value) { return new LazyPSetX<>( HashTreePSet.singleton(value),null,Reducers.toPSet(), LAZY); } PersistentSetX<T> type(Reducer<? extends PSet<T>> reducer);
@Override public PersistentUniqueList<E> subList(int start, int end) { return new PersistentUniqueList<>( contents.subList(start, end), HashTreePSet.from(contents.subList(start, end))); }