{"id":24586881,"url":"https://github.com/autonomys/rendezvous-hash","last_synced_at":"2025-03-17T19:16:00.476Z","repository":{"id":57163365,"uuid":"149006957","full_name":"autonomys/rendezvous-hash","owner":"autonomys","description":null,"archived":false,"fork":false,"pushed_at":"2019-05-28T18:37:27.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-04T14:49:29.443Z","etag":null,"topics":["hashing","rendezvous"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/autonomys.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}},"created_at":"2018-09-16T15:06:50.000Z","updated_at":"2020-08-05T23:34:54.000Z","dependencies_parsed_at":"2022-09-01T03:11:50.382Z","dependency_job_id":null,"html_url":"https://github.com/autonomys/rendezvous-hash","commit_stats":null,"previous_names":["subspace/rendezvous-hash"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomys%2Frendezvous-hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomys%2Frendezvous-hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomys%2Frendezvous-hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomys%2Frendezvous-hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autonomys","download_url":"https://codeload.github.com/autonomys/rendezvous-hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244094275,"owners_count":20397020,"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":["hashing","rendezvous"],"created_at":"2025-01-24T06:15:25.399Z","updated_at":"2025-03-17T19:16:00.448Z","avatar_url":"https://github.com/autonomys.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rendezvous hash implementation\nRead https://en.wikipedia.org/wiki/Rendezvous_hashing for details, this package works with 64-bit/8-byte inputs in form of `Uint8Array`s.\n\n## How to install\n```\nnpm install @subspace/rendezvous-hash\n```\n\n## How to use\nTypeScript:\n```typescript\nimport {randomBytes} from 'crypto';\nimport {Destination, pickDestinations} from '@subspace/rendezvous-hash';\n\nconst destinations: Destination[] = [\n    new Destination(randomBytes(8)),\n    new Destination(randomBytes(8)),\n];\nconst keys: Uint8Array[] = [\n    randomBytes(8),\n    randomBytes(8),\n    randomBytes(8),\n    randomBytes(8),\n    randomBytes(8),\n];\n\nfor (const key of keys) {\n    const destination = pickDestinations(key, destinations)[0];\n    console.log(destination.id)\n}\n\n```\n\n## API\n### rendezvousHash.pickDestinations(keyHash: Uint8Array, destinations: Destination[], k: number = 1): Uint8Array[]\nTakes a key and an array of potential destinations and returns `k` closest destinations to that key.\n\n* `keyHash` - 8 bytes hash of the key\n* `destinations` - an array of destination objects that are potential candidates\n* `k` - how many closest destinations for specified key to return\n\nReturns an array of IDs of keys (first argument to `Destination` object below).\n\n### rendezvousHash.Destination(readonly id: Uint8Array, readonly weight: number = 1)\nClass that encapsulates information about particular destination.\n\n`id` and `weight` are pubic readonly properties of resulting object\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautonomys%2Frendezvous-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautonomys%2Frendezvous-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautonomys%2Frendezvous-hash/lists"}