**QMem** is a quantum-inspired memory simulation library written in Rust. It allows bits to exist in a state of superposition—simultaneously 0 and 1—until measured. This unique approach lets you experiment with quantum-like behavior using a simple, intuitive API.
---
- ----
---
Add QMem as a dependency in your `Cargo.toml`:
```toml
[dependencies]
qmem = "0.1.1"
Then import it in your Rust project:
use QMem;
Usage
Here's a simple example demonstrating how to use QMem:
use QMem;
API Reference
QMem::new() -> Self
Creates a new QMem instance with all 64 bits initialized in superposition.
set_bit(&mut self, index: usize, value: Option<bool>)
Sets the bit at the specified index:
Some(true)sets the bit to 1.Some(false)sets the bit to 0.Noneleaves the bit in superposition.
measure(&mut self, index: usize) -> bool
Measures the bit at the given index:
- If the bit is already in a definite state, returns that value.
- If the bit is in superposition, randomly collapses it to 0 or 1 and returns the result.
print(&self)
Prints the current state of the memory, displaying:
- The definite state of each bit (0s and 1s).
- Which bits are still in superposition.
Implementation Details
QMem manages two 64-bit integers internally:
- state: Holds the current collapsed values of the bits.
- superposition: Uses a bitmask to indicate which bits remain in superposition (a 1 means the bit is still in superposition).
The randomness during measurement is handled by the rand crate (version 0.9).
Contributing
Contributions are very welcome! If you have ideas, bug fixes, or improvements, please feel free to open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
Authors
- Aashish BishowKarma – Initial work
GitHub Profile
Enjoy exploring quantum-inspired memory simulation with QMem!