Skip to content

Commit b206fc6

Browse files
author
Glen K. Peterson
committed
Added custom serialization for PersistentHashMap. Changed PersistentHashMap.count to .size. Added ImSetTrans so we can expose as little as possible of the TransientHashSet. Made named classes for lots of things thinking that they could be serializable, but decided against supporting that forever until someone asks for it. This should still reduce some code size through reuse. Privatized some things that should never have been public. Made singletons into enums.
1 parent a3fbe4a commit b206fc6

17 files changed

+511
-329
lines changed

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ IDENTITY is now Const.IDENTITY
7272
ACCEPT is now ConstBool.ACCEPT
7373
REJECT is now ConstBool.REJECT
7474
75+
org.organicdesign.fp.collections.UnmodMap.UnEntry.entryToUnEntry(Map.Entry<K,V> entry)
76+
is now
77+
org.organicdesign.fp.collections.KeyVal.of(Map.Entry<K,V> entry)
78+
7579
Search for usages of
7680
map(tup(
7781
.toImMap(... tup(
@@ -82,12 +86,23 @@ map(kv(
8286

8387
#### Additional changes
8488
- Tuple2 no longer implements Map.Entry. Instead, a new Serializable subclass, KeyVal, was created for this purpose.
89+
- Removed UnmodMap.UnEntry.entryToUnEntry(Map.Entry<K,V> entry).
8590
- Tuple hashcodes are now the addition of the hashcodes of each item in the tuple.
8691
They used to bitwise-or the first two items (and add the rest) for compatibility with Map.Entry.
87-
88-
The function interfaces (Function0, Function1, etc.) will *not* implement Serializable.
89-
These interfaces are general and Serializable is too much for implementers to think about (and often irrelevant).
90-
However, the constants in those interfaces have been changed to implement Serializable.
92+
- PersistentHashMap.ArrayNode, .BitMapIndexNode, .HashCollisionNode, and .NodeIter are now all private (were public or package).
93+
There should never have been any reason to use or access these.
94+
- Added ImSetTrans&lt;E&gt; interface and exposed the Transient Set implementation.
95+
- Found some opportunities to use transient implementations more efficiently.
96+
97+
#### What's *NOT* Serializable?
98+
- The function interfaces (Function0, Function1, etc.) will *NOT* implement Serializable.
99+
These interfaces are general and Serializable is too much for implementers to think about (and often irrelevant).
100+
However, the *constants* and *singletons* in those interfaces have been changed to implement
101+
Serializable.
102+
- Iterators are *NOT* serializable. They aren't in java.util.Collections either.
103+
If you need an iterator to be serializable for some reason, open an issue and we'll discuss it.
104+
- Transformable is not serializable. Open an issue to discuss.
105+
- Transient-HashSet, -HashMap, and -Vector are not Serializable. Open an issue to discuss.
91106

92107
Issues? Questions? Please provide feedback on the [Serialization enhancement request](https://github.com/GlenKPeterson/UncleJim/issues/10)
93108

inheritanceHierarchy.odg

1.1 KB
Binary file not shown.

inheritanceHierarchy.pdf

-273 Bytes
Binary file not shown.

src/main/java/org/organicdesign/fp/collections/ImMapTrans.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package org.organicdesign.fp.collections;
22

33
/**
4-
Allows a map to be taken from transient to persistent. This is NOT inherently thread-safe and calls to the
5-
asTransient() and persistent() methods need to be wrapped in a thread-safe manner.
6-
This bridges that gap to let PersistentHashSet know about the asTransient() method for accessing PersistentHashMap's
7-
inner transient class, which in turn, allows this class to implement keySet for PersistentHashMap. Also allows
4+
You could think of this as a builder for a transient map. It builds a little faster than the
5+
persistent one.
6+
7+
Allows a map to be taken from transient to persistent. This is NOT inherently thread-safe.
8+
This bridges that gap to let PersistentHashSet know about the asTransient() method for accessing
9+
PersistentHashMap's inner transient class, which in turn, allows this class to implement keySet
10+
for PersistentHashMap.
811
*/
912
public interface ImMapTrans<K,V> extends ImMap<K,V> {
1013
ImMapTrans<K,V> asTransient();
1114

1215
/** Returns the Equator used by this map for equals comparisons and hashCodes */
1316
Equator<K> equator();
1417

18+
/** Returns a persistent/immutable version of this transient map. */
1519
ImMapTrans<K,V> persistent();
1620

1721
/** {@inheritDoc} */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.organicdesign.fp.collections;
2+
3+
/**
4+
You could think of this as a builder for a transient set. It builds a little faster than the
5+
persistent one. This is NOT inherently thread-safe. The goal of this is to expose as little of
6+
the TransientHashMap as possible.
7+
*/
8+
public interface ImSetTrans<E> extends ImSet<E> {
9+
10+
/** {@inheritDoc} */
11+
@Override ImSetTrans<E> put(E val);
12+
13+
/** {@inheritDoc} */
14+
@Override ImSetTrans<E> without(E key);
15+
16+
/** Returns a persistent/immutable version of this transient map. */
17+
ImSet<E> persistent();
18+
}

0 commit comments

Comments
 (0)