![JAR search and dependency download from the Maven repository](/logo.png)
com.github.grignaak.collections.CowMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cow-collections Show documentation
Show all versions of cow-collections Show documentation
Copy-on-write collections for easy, thread-safe, immutability
package com.github.grignaak.collections;
import java.util.Map;
/**
* A Copy-On-Write map (or a persistent data structure in the literature.
*
* A Copy-On-Write map has a cheap {@link #fork()} method which will return a new instance of the map,
* but likely sharing the underlying data structure. Even when the data structure is shared, writes to either of the
* forks are not reflected in the other fork. Forking can happen any number of times.
*
* The major purpose of a copy-on-write map is thread safety. A common idiom is to make updates to the collection in
* one thread and then publish its fork to any number of reader threads. These reader threads can safely read their copy
* of the fork while concurrent updates are happening.
*/
public interface CowMap extends Map, Forkable {
/**
* Create an independent copy of this map, where mutations on the returned instance do not affect this instance
* and vice versa. Typically uses structural sharing on larger maps.
*/
CowMap fork();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy