This project is a simulation of consistent hashing using Zig and Raylib. The application visualizes how a hash ring distributes nodes and routes requests to these nodes based on hash values. It demonstrates the addition and removal of nodes in the ring and shows how requests are routed.
https://github.com/user-attachments/assets/5771304e-3829-4fec-8e63-b2b97a8afa6c
To build and run this project, you'll need:
Clone the Repository:
git clone https://github.com/basilysf1709/chsim.git
cd https://github.com/basilysf1709/chsim.git
Install Raylib:
Follow the instructions on the Raylib installation page. Ensure that raylib.h
is accessible for your Zig build.
Build & Run the Project:
The project uses Zig’s build system. To build the application, run:
zig build run
Once the application is running, you can interact with the simulation using the following controls:
VirtualNode
: Represents a virtual node in the hash ring with properties like id
, parent_id
, position
, name
, and ip
.HashRing
: Manages the collection of virtual nodes and provides functionality to add, remove, and find nodes. It also sorts the nodes by their position on the ring.HashRing.init
: Initializes the hash ring with an allocator and a specified number of virtual nodes per node.HashRing.addNode
: Adds a new node to the hash ring and sorts the nodes.HashRing.removeNode
: Removes nodes from the hash ring if the number exceeds the specified limit.HashRing.findNode
: Finds the appropriate node for a given key based on its hash value.HashRing.hash
: Computes a hash value for a given key.Feel free to contribute to this project by submitting issues, improvements, or pull requests. Your feedback and suggestions are welcome! Any kinds of contributions are welcome
This project is licensed under the MIT License. See the LICENSE file for details.