{"id":30951154,"url":"https://github.com/mnutt/doublejump-node","last_synced_at":"2025-09-11T05:43:37.604Z","repository":{"id":280941226,"uuid":"943682953","full_name":"mnutt/doublejump-node","owner":"mnutt","description":"DoubleJump hash implementation","archived":false,"fork":false,"pushed_at":"2025-03-06T05:16:05.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T06:24:33.974Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/mnutt.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":"2025-03-06T05:14:36.000Z","updated_at":"2025-03-06T05:16:08.000Z","dependencies_parsed_at":"2025-03-06T06:34:40.532Z","dependency_job_id":null,"html_url":"https://github.com/mnutt/doublejump-node","commit_stats":null,"previous_names":["mnutt/doublejump-node"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mnutt/doublejump-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnutt%2Fdoublejump-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnutt%2Fdoublejump-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnutt%2Fdoublejump-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnutt%2Fdoublejump-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnutt","download_url":"https://codeload.github.com/mnutt/doublejump-node/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnutt%2Fdoublejump-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274584132,"owners_count":25311902,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-09-11T05:43:33.445Z","updated_at":"2025-09-11T05:43:37.598Z","avatar_url":"https://github.com/mnutt.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# doublejump-node\n\nA Node.js native addon implementing the Jump Consistent Hash algorithm with a dual-bucket strategy for efficient object distribution and lookup.\n\nAcknowledgements: this is just a reimplementation of https://github.com/edwingeng/doublejump as a c++ node module.\n\n## Features\n\n- Consistent hashing implementation using Jump Hash algorithm\n- Dual-bucket strategy for efficient object management:\n  - Loose bucket: Handles rapid additions/removals with minimal memory reallocation\n  - Compact bucket: Provides dense storage and efficient lookups\n- Thread-safe random object selection\n- Zero external dependencies (besides Node.js and C++ standard library)\n- Written in modern C++ with noexcept guarantees\n\n## Installation\n\n```bash\nnpm install doublejump-node\n```\n\n## Usage\n\n```javascript\nconst DoubleJump = require('doublejump-node').DoubleJump;\n\n// Create a new instance\nconst dj = new DoubleJump();\n\n// Add some objects\ndj.add(\"object1\");\ndj.add(\"object2\");\ndj.add(\"object3\");\n\n// Get an object using a key (returns consistent results for the same key)\nconst obj = dj.get(\"my-key\");  // Returns one of the added objects consistently\n\n// Get a random object\nconst randomObj = dj.random();  // Returns a random object from the collection\n\n// Remove an object\ndj.remove(\"object2\");\n\n// Get all objects\nconst allObjects = dj.all();  // Returns [\"object1\", \"object3\"]\n\n// Get counts\nconst totalCount = dj.len();      // Number of objects in compact storage\nconst looseCount = dj.looseLen(); // Number of objects in loose storage\n\n// Optimize storage (moves all objects to compact storage)\ndj.shrink();\n```\n\n## API\n\n### `new DoubleJump()`\nCreates a new DoubleJump instance.\n\n### `add(object: string): void`\nAdds an object to the collection. If the object already exists, it is not added again.\n\n### `remove(object: string): void`\nRemoves an object from the collection. If the object doesn't exist, nothing happens.\n\n### `get(key: string): string`\nReturns an object from the collection based on the hash of the key. The same key will always return the same object (as long as the collection hasn't changed).\n\n### `random(): string`\nReturns a random object from the collection. Uses a high-quality random number generator.\n\n### `all(): string[]`\nReturns an array of all objects in the collection.\n\n### `len(): number`\nReturns the total number of objects in compact storage.\n\n### `looseLen(): number`\nReturns the number of objects in loose storage.\n\n### `shrink(): void`\nOptimizes the storage by moving all objects to compact storage. This can be useful after many add/remove operations.\n\n## How it Works\n\nThe package uses a dual-bucket strategy for object storage:\n\n1. **Loose Bucket**: Handles rapid additions and removals without moving objects around. Uses a free list to track empty slots.\n2. **Compact Bucket**: Provides dense storage for efficient lookups and memory usage.\n\nWhen objects are added, they go into both buckets. When objects are removed, they're marked as removed in the loose bucket and actually removed from the compact bucket.\n\nThe `get()` operation first tries the loose bucket, falling back to the compact bucket if necessary. This ensures consistent object distribution even during rapid changes.\n\nThe `shrink()` operation consolidates both buckets into the compact form for optimal performance.\n\n## Building from Source\n\nRequirements:\n- Node.js 12+\n- node-gyp\n- C++17 compatible compiler\n\n```bash\ngit clone https://github.com/yourusername/doublejump-node.git\ncd doublejump-node\nnpm install\n```\n\n## Performance Testing\n\nTo run the benchmarks:\n\n```bash\nnpm run bench\n```\n\n## License\n\nBSD 3-Clause","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnutt%2Fdoublejump-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnutt%2Fdoublejump-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnutt%2Fdoublejump-node/lists"}