# Atomic-Dict: A library for lock-free shared 64-bit dictionaries
Atomic-Dict provides a shared Map[Int, Int] for 64-bit integer values.
Create an AtomicDict(), fork, then update keyed values using atomic operations.
Supported operations include compare-and-swap, exchange, increment, etc.
## Limitations
This is not a general purpose dictionary implementation.
It is designed to be used as a synchronization primitive.
Key limitations include:
* The key must be a non-zero 64-bit value.
* The value for freshly allocated keys are always initialized as 0.
* Keys allocated into the dictionary can never be removed.
* The maximum size of the dictionary must be specified upfront.
To support more complex types, build shared a list[XYZ] before fork(),
then use indexes into those lists as the keys and values of the AtomicDict.
## Performance
While bare bones, AtomicDict is fast.
Operations never lock, never wait, and leverage cache locality.
It is hard to imagine a faster shared dictionary implementation.
## Example use
```python
from atomic_dict import AtomicDict
import multiprocessing
if __name__ == "__main__":
dict = AtomicDict(1024*1024)
context = multiprocessing.get_context("fork")
def worker(id: int) -> None:
for _ in range(32*1024):
idx = dict[1].add(1) # also: sub, bor, bxor, band, swap, cas(expected, replacement)
dict[100 + idx] = id
with context.Pool(8) as p:
p.map(worker, range(16))
```
Raw data
{
"_id": null,
"home_page": "https://github.com/terpstra/atomic-dict",
"name": "atomic_dict",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Wesley W. Terpstra",
"author_email": "wesley@sifive.com",
"download_url": "https://files.pythonhosted.org/packages/80/8d/473b6829d5adfb237431c4ac2d6a6f02a7cb6294030dcbbc620613055061/atomic_dict-0.5.0.tar.gz",
"platform": null,
"description": "# Atomic-Dict: A library for lock-free shared 64-bit dictionaries\n\nAtomic-Dict provides a shared Map[Int, Int] for 64-bit integer values.\nCreate an AtomicDict(), fork, then update keyed values using atomic operations.\nSupported operations include compare-and-swap, exchange, increment, etc.\n\n## Limitations\n\nThis is not a general purpose dictionary implementation.\nIt is designed to be used as a synchronization primitive.\nKey limitations include:\n\n* The key must be a non-zero 64-bit value.\n* The value for freshly allocated keys are always initialized as 0.\n* Keys allocated into the dictionary can never be removed.\n* The maximum size of the dictionary must be specified upfront.\n\nTo support more complex types, build shared a list[XYZ] before fork(),\nthen use indexes into those lists as the keys and values of the AtomicDict.\n\n## Performance\n\nWhile bare bones, AtomicDict is fast.\nOperations never lock, never wait, and leverage cache locality.\nIt is hard to imagine a faster shared dictionary implementation.\n\n## Example use\n\n```python\nfrom atomic_dict import AtomicDict\nimport multiprocessing\n\nif __name__ == \"__main__\":\n dict = AtomicDict(1024*1024)\n context = multiprocessing.get_context(\"fork\")\n def worker(id: int) -> None:\n for _ in range(32*1024):\n idx = dict[1].add(1) # also: sub, bor, bxor, band, swap, cas(expected, replacement)\n dict[100 + idx] = id\n with context.Pool(8) as p:\n p.map(worker, range(16))\n```\n\n",
"bugtrack_url": null,
"license": "BSD-3",
"summary": "A library for lock-free shared 64-bit dictionaries",
"version": "0.5.0",
"project_urls": {
"Homepage": "https://github.com/terpstra/atomic-dict",
"Repository": "https://github.com/terpstra/atomic-dict"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "358d4491515cc120c48d8999e9a83bf65800479cf9a23a7561dc95b65d4170ba",
"md5": "74ecbadb93b4ed2ef2e76cecb9642bc4",
"sha256": "3190da3aeb4e689729f05256b7eb21b69186a462e9af7dd5a1e1e9fbaf2264dd"
},
"downloads": -1,
"filename": "atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl",
"has_sig": false,
"md5_digest": "74ecbadb93b4ed2ef2e76cecb9642bc4",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": "<4.0,>=3.10",
"size": 41887,
"upload_time": "2024-08-17T03:31:02",
"upload_time_iso_8601": "2024-08-17T03:31:02.778005Z",
"url": "https://files.pythonhosted.org/packages/35/8d/4491515cc120c48d8999e9a83bf65800479cf9a23a7561dc95b65d4170ba/atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "808d473b6829d5adfb237431c4ac2d6a6f02a7cb6294030dcbbc620613055061",
"md5": "4aec5cbece1b69e01b012ba9af0f1d9c",
"sha256": "9eefe28c4acf5a96aa4555ac177f684685cd43ec0932bf30a317f73edc5846b4"
},
"downloads": -1,
"filename": "atomic_dict-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "4aec5cbece1b69e01b012ba9af0f1d9c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 9918,
"upload_time": "2024-08-17T03:31:04",
"upload_time_iso_8601": "2024-08-17T03:31:04.177810Z",
"url": "https://files.pythonhosted.org/packages/80/8d/473b6829d5adfb237431c4ac2d6a6f02a7cb6294030dcbbc620613055061/atomic_dict-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-17 03:31:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "terpstra",
"github_project": "atomic-dict",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "atomic_dict"
}