Efficient, immutable, and thread-safe persistent data structures for Ruby, including Hash, Vector, Set, SortedSet, List, and Deque.
Hamster is a Ruby library providing efficient, immutable, and thread-safe collection classes. It solves the problem of safely sharing data across threads by offering persistent data structures that preserve original versions when modified. The library includes Hash, Vector, Set, SortedSet, List, and Deque implementations with memory-efficient structural sharing.
Ruby developers building concurrent applications, functional programming enthusiasts, and those needing thread-safe data structures without locking mechanisms.
Developers choose Hamster for its immutable, thread-safe collections that eliminate data race concerns, offer performance through structural sharing, and maintain compatibility with Ruby's standard interfaces for easy integration.
Efficient, Immutable, Thread-Safe Collection classes for Ruby
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
All collections are immutable, eliminating data races without locks, as the README states: 'Hamster collections are immutable... inherently thread-safe and shareable.'
Uses persistent data structures to share memory between versions, optimizing performance; highlighted by 'CPU and memory-efficient by sharing between copies.'
Designed to align with Ruby's built-in Hash, Array, and Enumerable, easing migration; the README notes 'interfaces align... for easier migration.'
Lists enable lazy processing for large or infinite sequences, allowing efficient handling as shown in the lazy prime number example with Hamster.interval.
Methods return instances of the same class, unlike Ruby's array conversions, providing consistency; 'Hamster collections are almost always closed under a given operation.'
While collections are immutable, stored objects can be mutated, placing the burden of thread-safety on developers; the README warns: 'you are responsible for making sure that the objects stored in them are used in a thread-safe manner.'
Requires adoption of new methods like put instead of []=, which can be a barrier for teams accustomed to Ruby's mutable syntax, adding friction in migration.
Operations return new copies, which, despite sharing, may introduce overhead compared to destructive updates in performance-critical loops, especially for write-heavy scenarios.