{"id":21565309,"url":"https://github.com/sandeepkv93/consistent-hashing","last_synced_at":"2025-03-18T05:17:55.008Z","repository":{"id":75506087,"uuid":"592621388","full_name":"sandeepkv93/consistent-hashing","owner":"sandeepkv93","description":"Consistent Hashing is a distributed hash table algorithm that allows for more efficient remapping of keys to nodes in a distributed system when nodes are added or removed. This implementation is written in Go and provides a basic implementation of consistent hashing.","archived":false,"fork":false,"pushed_at":"2023-01-24T07:03:00.000Z","size":1110,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-24T11:44:49.298Z","etag":null,"topics":["consistent-hash-algorithm","consistent-hashing","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandeepkv93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-24T06:20:04.000Z","updated_at":"2023-01-24T06:58:52.000Z","dependencies_parsed_at":"2023-06-06T16:45:34.595Z","dependency_job_id":null,"html_url":"https://github.com/sandeepkv93/consistent-hashing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepkv93%2Fconsistent-hashing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepkv93%2Fconsistent-hashing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepkv93%2Fconsistent-hashing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepkv93%2Fconsistent-hashing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandeepkv93","download_url":"https://codeload.github.com/sandeepkv93/consistent-hashing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244160056,"owners_count":20408021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consistent-hash-algorithm","consistent-hashing","golang"],"created_at":"2024-11-24T10:19:10.267Z","updated_at":"2025-03-18T05:17:54.987Z","avatar_url":"https://github.com/sandeepkv93.png","language":"Go","readme":"# Consistent Hashing\n\nConsistent Hashing is a distributed hash table algorithm that allows for more efficient remapping of keys to nodes in a distributed system when nodes are added or removed. This implementation is written in Go and it provides a basic implementation of consistent hashing.\n\n### Installation\n\nTo use this package, you can simply go get it:\n\n```sh\ngo get github.com/sandeepkv93/consistent-hashing\n```\n\n### Usage\n\nHere is an example of how to use the `ConsistentHash` struct:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/yourusername/consistent-hashing\"\n)\n\nfunc main() {\n    consistentHash := consistent_hashing.NewConsistentHash()\n    consistentHash.AddNode(\"node1\")\n    consistentHash.AddNode(\"node2\")\n    consistentHash.AddNode(\"node3\")\n\n    // Add some keys and test which node they map to\n    keys := []string{\"key1\", \"key2\", \"key3\", \"key4\", \"key5\"}\n    for _, key := range keys {\n        fmt.Printf(\"Key '%s' maps to node: %s\\n\", key, consistentHash.GetNode(key))\n    }\n\n    // Remove a node and test again\n    fmt.Println(\"\\nRemoving node 'node2'...\")\n    consistentHash.RemoveNode(\"node2\")\n    for _, key := range keys {\n        fmt.Printf(\"Key '%s' maps to node: %s\\n\", key, consistentHash.GetNode(key))\n    }\n\n    // Add a node and test again\n    fmt.Println(\"\\nAdding node 'node4'...\")\n    consistentHash.AddNode(\"node4\")\n    for _, key := range keys {\n        fmt.Printf(\"Key '%s' maps to node: %s\\n\", key, consistentHash.GetNode(key))\n    }\n}\n```\n\nIn this example, the main method creates a new ConsistentHash object, adds three nodes to it, then adds some keys and tests which node they map to. Then it removes a node and tests again, and adds a node and tests again. This way you can see how the keys are distributed among the nodes and how the distribution changes when nodes are added or removed.\n\n### Methods\n\n`NewConsistentHash()` : This function creates and returns a new instance of the ConsistentHash struct.\n\n`AddNode(node string)` : This method is used to add a new node to the consistent hash.\n\n`RemoveNode(node string)` : This method is used to remove an existing node from the consistent hash.\n\n`GetNode(key string)` : This method returns the appropriate node for a given key.\n\n### Properties\n\n`nodes` : A map that stores the nodes.\n\n`circle` : A map that stores the circle, where the keys are the generated hash points and the values are the corresponding nodes.\n\n### Note\n\nYou can adjust the number of replicas in the `generateCircle()` method to increase the number of points in the circle, which can help to distribute keys more evenly among the nodes.\n\n### References\n\n-   [Consistent Hashing - Wikipedia](https://en.wikipedia.org/wiki/Consistent_hashing)\n\n### Additional Information\n\nConsistent Hashing is a technique that is used to distribute keys across multiple nodes in a distributed system. It is particularly useful when the number of nodes in the system is subject to change, as it allows for the remapping of keys to nodes with minimal disruption to the overall system. This implementation is a basic implementation of consistent hashing and can be used as a starting point for more complex and sophisticated distributed systems.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeepkv93%2Fconsistent-hashing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandeepkv93%2Fconsistent-hashing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeepkv93%2Fconsistent-hashing/lists"}