![JAR search and dependency download from the Maven repository](/logo.png)
com.github.grignaak.collections.CowCollection 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.Collection;
/**
* A Copy-On-Write collection (or a persistent data structure in the literature.)
*
* A Copy-On-Write collection has a cheap {@link #fork()} method which will return a new instance of the collection,
* 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 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 CowCollection extends Collection, Forkable {
/**
* Create an independent copy of this collection, where mutations on the returned instance do not affect this
* instance and vice versa. Typically uses structural sharing on larger maps.
*/
CowCollection fork();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy