{"id":17398439,"url":"https://github.com/vweevers/keyspace","last_synced_at":"2026-01-03T14:51:29.062Z","repository":{"id":56202972,"uuid":"189876570","full_name":"vweevers/keyspace","owner":"vweevers","description":"Get keys and values based on a probability distribution and seed.","archived":false,"fork":false,"pushed_at":"2020-11-20T17:59:00.000Z","size":412,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-27T04:39:04.496Z","etag":null,"topics":["benchmarking","key-value-store","keys","level","nodejs","random","values","zipfian"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vweevers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-02T17:38:30.000Z","updated_at":"2023-12-10T14:52:21.000Z","dependencies_parsed_at":"2022-08-15T14:40:14.670Z","dependency_job_id":null,"html_url":"https://github.com/vweevers/keyspace","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vweevers/keyspace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fkeyspace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fkeyspace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fkeyspace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fkeyspace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vweevers","download_url":"https://codeload.github.com/vweevers/keyspace/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fkeyspace/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281397336,"owners_count":26493908,"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-10-28T02:00:06.022Z","response_time":60,"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":["benchmarking","key-value-store","keys","level","nodejs","random","values","zipfian"],"created_at":"2024-10-16T14:56:28.772Z","updated_at":"2025-10-28T06:30:46.055Z","avatar_url":"https://github.com/vweevers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# keyspace\n\n\u003e **Get keys and values based on a probability distribution and seed.**  \n\u003e For deterministic input to benchmarks.\n\n[![npm status](http://img.shields.io/npm/v/keyspace.svg)](https://www.npmjs.org/package/keyspace)\n[![node](https://img.shields.io/node/v/keyspace.svg)](https://www.npmjs.org/package/keyspace)\n[![Travis build status](https://img.shields.io/travis/vweevers/keyspace.svg?label=travis)](http://travis-ci.org/vweevers/keyspace)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Usage\n\n```js\nconst keyspace = require('keyspace')\nconst db = mydb()\n\n// To prepare the database, we'll write 1M sequential\n// keys, with random values of 100 bytes\nconst writer = keyspace(1e6, {\n  keys: 'seq',\n  values: 'random',\n  valueSize: 100,\n\n  // Always generate the same keys and values\n  seed: 'a seed'\n})\n\nfor (let i = 0; i \u003c 1e6; i++) {\n  db.put(writer.key(i), writer.value())\n}\n\n// Get a random key based on a Zipfian distribution\nconst reader = keyspace(1e6, {\n  keys: 'random',\n  distribution: 'zipfian',\n  seed: 'a seed',\n\n  // Favor latest keys\n  skew: -1\n})\n\ndb.get(reader.key())\ndb.get(reader.key())\n```\n\n## Visual Example\n\n![Visual example](example.png)\n\n## API\n\n_**Stability:** experimental. API may change or split up._\n\n### `generator = keyspace(n, [options])`\n\nCreate a key and value generator for a keyspace of size N (aka cardinality). Uses xorshift128+ internally to be fast and random _enough_. Keys are encoded with `lexicographic-integer` to preserve order.\n\nOptions:\n\n- `keys` (string): one of:\n  - `random` (default): generate pseudo-random numeric keys with a certain probability `distribution`\n  - `seq`: non-random, sequential numeric keys (0-N)\n  - `seqReverse`: same keys but in reverse (N-0)\n- `values` (string): one of:\n  - `random` (default): generate pseudo-random values\n  - `empty`: zero-length values or zero-filled if `valueSize` is set\n- `seed` (string or Buffer): if not provided one will be generated.\n- `distribution` (string): one of [`zipfian`](https://github.com/vweevers/zipfian-integer), `uniform` (default)\n- `skew` (floating-point number): Zipfian skew (default 0)\n- `offset` (number): offset keys (for example to simulate timestamps)\n- `valueSize` (number): size of values in bytes\n- `keyAsBuffer`, `valueAsBuffer`, `keyAsNumber` (boolean): if not set, keys and values are returned as strings (hex encoded).\n\n### `key = generator.key([index])`\n\nGet a key. The `index` argument is required for `seq` and `seqReverse`.\n\n### `value = generator.value()`\n\nGet a value.\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install keyspace\n```\n\n## License\n\n[MIT](LICENSE.md) © 2019-present Vincent Weevers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fkeyspace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvweevers%2Fkeyspace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fkeyspace/lists"}