Hash Consing Library
The Hash Consing Library (hash_cons) is a Rust library that implements efficient hash consing techniques,
making it a robust choice for both single-threaded and multi-threaded Rust applications.
At its core, the library is designed to focus on type-safety, efficiency, and zero-cost abstractions.
Efficiency and Idiomatic Rust
This library is designed to be inherently idiomatic to Rust, ensuring efficient memory management and optimal performance. It utilizes Rust's unique ownership and borrowing rules to manage immutable data structures. The key feature is its automatic memory management: when a value is no longer referred to anywhere in your program, the library automatically deallocates it, preventing memory leaks and optimizing resource usage. This makes it an excellent tool for applications where duplicate data structures are common, ensuring memory efficiency.
Features
- Single-Threaded (Default Feature): Tailored for applications not requiring thread safety, this default mode uses
RcandRefCellfor efficient memory management, avoiding the overhead of synchronization mechanisms. - Thread-Safe: Designed for multi-threaded applications, it uses
ArcandRwLockto guarantee safe concurrent access, aligning with Rust's emphasis on safety.
Usage
To integrate hash_cons into your project, add it as a dependency in your Cargo.toml:
[]
= "0.1.1" # Replace with the actual version
By default, the library operates in a single-threaded environment. For multi-threaded support, enable the thread-safe feature:
# Default single-threaded
= "0.1.1"
# For multi-threaded environments
= { = "0.1.1", = ["thread-safe"] }
Examples
Single-Threaded Usage
use ;
Thread-Safe Usage
use ;
use thread;
Contributing
We welcome contributions and suggestions to make hash_cons better. If you have ideas or improvements, feel free to submit a pull request or open an issue in the repository.
License
Licensed under the MIT License. See the LICENSE file for more details.