{"id":21402851,"url":"https://github.com/mfherbst/ctx","last_synced_at":"2025-04-16T02:52:16.286Z","repository":{"id":56187301,"uuid":"163624261","full_name":"mfherbst/ctx","owner":"mfherbst","description":"Key-value C++ datastructures for organised hierarchical storage","archived":false,"fork":false,"pushed_at":"2020-11-21T19:57:14.000Z","size":281,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T04:25:26.774Z","etag":null,"topics":["cplusplus","datastructure","hierachical","storage","tree"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfherbst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-30T23:18:51.000Z","updated_at":"2023-03-07T19:22:34.000Z","dependencies_parsed_at":"2022-08-15T14:20:24.437Z","dependency_job_id":null,"html_url":"https://github.com/mfherbst/ctx","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfherbst%2Fctx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfherbst%2Fctx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfherbst%2Fctx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfherbst%2Fctx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfherbst","download_url":"https://codeload.github.com/mfherbst/ctx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249187236,"owners_count":21226877,"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":["cplusplus","datastructure","hierachical","storage","tree"],"created_at":"2024-11-22T15:41:31.289Z","updated_at":"2025-04-16T02:52:16.256Z","avatar_url":"https://github.com/mfherbst.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ``ctx``: Key-value `C++` datastructures for organised hierarchical storage\n[![Build Status](https://github.com/mfherbst/ctx/workflows/CI/badge.svg?branch=master\u0026event=push)](https://github.com/mfherbst/ctx/actions)\n[![Licence](https://img.shields.io/github/license/mfherbst/ctx.svg)](LICENSE)\n\nA common pattern in numerical computation is that input parameters or\ncomputed simulation data should be stored in a tree-like, hierarchical fashion.\nThis is no surprise, since different steps of a simulation algorithm\noften deal with larger numbers of parameters or data,\nwhere only a subset is of concern for any other part of the\ncomplete simulation procedure.\nThus it makes sense to keep the data, which deals with\none step of the simulation, well-separated from\nthe data of any other step.\nA tree-like structure, where different steps\nassociate with different subtrees\nis a very intuitive approach to achieve that,\neffectively shielding the context of objects\nrelated to one step from the objects of others.\nAt the same time this naturally allows to represent the structure\nof the simulation framework in the storage scheme as well.\n\nThis library offers a `C++` implementation of\nof such a tree-like string-to-value mapping, the `CtxMap`.\nWhile the key in such a mapping is taken to be a path-like\nstring such as `/this/is/a/path/to/a/value`,\nthe value can be of arbitrary type.\nMy means of rich functionality, such as views into subtrees\nor iterators over ranges of keys,\nnavigating and accessing such a hierarchical data storage\nfrom different parts of a code is greatly facilitated.\n\nOther key features include:\n  - **Based on `shared_ptr`**: All data is stored as `std::shared_ptr`\n    integrating well into the `C++` standard library and modern\n    `C++` codes.\n  - **Type safety**: Even though arbitrary types may be stored\n    inside a `CtxMap`, an explicit checking mechanism makes sure\n    that the type is kept consistent.\n  - **Thread-safety**: Access to the `CtxMap` *should* be thread-safe,\n    even though this has not been properly tested.\n\n## Obtaining and building ``ctx``\nCheck out the ``ctx`` git repository.\nAll compilers starting from ``clang-3.5`` and ``gcc-4.8`` should\nbe able to build the code. ``C++11`` support is required.\n\nTo build and test:\n```\nmkdir build \u0026\u0026 cd build\ncmake ..\ncmake --build .\nctest\n```\n\n## Motivation\nThe driving force behind `ctx` was to provide a more modern approach\nto the concept of a `context` storage as it was implemented\nin the `libctx` library of the\nquantum-chemistry package [Q-Chem](https://q-chem.com).\nFor this the design of data structures such as the\n[PamMap](https://github.com/mfherbst/pammap),\nand the\n[GenMap](https://github.com/lazyten/krims#genmap-a-hierachical-dictionary-for-managing-data-of-arbitrary-type)\nwas expanded to support all functionality of `libctx`,\nleading to the `CtxMap`.\nBased on the `CtxMap` back-end, `ctx` provides\na compatibility layer,\nwhich offers (almost) the same interface as the original `libctx`\nby E. Epifanovsky *et. al.*.\nUnder the hood the more flexible `CtxMap` interface\nis always accessible, allowing new take to make\nuse of it in a backwards-compatible way.\nAs of March 2019, `ctx` has fully replaced `libctx`\ninside the [Q-Chem](https://q-chem.com) source tree.\n\n## Differences between Q-Chem's ``libctx`` and ``ctx``\nAs mentioned above ``ctx`` and ``libctx`` largely have the same interface,\nbut in order to simplify the implementation with the\n``CtxMap`` support for a few features were dropped.\nMost notable deviations from ``libctx``:\n\n- **Support** for the deprecated ``std::auto_ptr`` class **has been dropped**.\n  The last `ctx` version with ``std::auto_ptr`` is v2.4.1.\n- [``params``](src/ctx/params.h) has no support for iterators\n- Keys inside [``params``](src/ctx/params.h) objects may not\n  contain the character `\"/\"`.\n\nImprovements over ``libctx`` include:\n- The ``libctx::root_storage`` of ``libctx::context`` objects is a ``CtxMap``.\n  In other words, ``libctx::context`` is really only a wrapper\n  around ``CtxMap``.\n  Since all changes done by either acting on the ``root_storage`` or\n  the ``libctx::context`` wrapper effect the same underlying object\n  in memory, both interfaces can be used simultaneously, e.g.\n  \n  ```cpp\n  ctx::CtxMap stor{{\"bla\", 5}};\n  libctx::context ctx(stor);\n\n  ctx.update(\"bla\", rc_ptr\u003cint\u003e(new int(6)));\n  stor.update(\"bla\", 7);\n\n  std::cout \u003c\u003c *ctx.get\u003cint\u003e(\"bla\");\n  ```\n  \n  will print the value ``7`` which has been set via the ``stor`` object,\n  i.e. the ``CtxMap`` interface.\n- From a ``ctx::context`` the wrapped ``CtxMap`` object,\n  with its richer functionality can be accessed using the ``map()`` function.\n- ``libctx::params`` objects contain a ``CtxMap`` to store their data.\n  It can be referenced (and altered) using the ``map()`` function as well.\n- Thanks to the ``CtxMap``, ``libctx::context`` objects can now be printed,\n  including the data types of the stored data and (for some data types)\n  even the values. This is implemented via the usual ``operator\u003c\u003c``\n  functionality.\n\n## Citation [![DOI](https://zenodo.org/badge/163624261.svg)](https://zenodo.org/badge/latestdoi/163624261) [![bibtex](https://img.shields.io/badge/bibtex-download_citation-red.svg)](https://michael-herbst.com/publications/2019.03.14_ctx.bib)\nYou can cite `ctx` using this\n[`bibtex` entry](https://michael-herbst.com/publications/2019.03.14_ctx.bib)\nor simply as  \n\nMichael F. Herbst. *ctx: Key-value C++ datastructures for organised hierachical storage* (2019). DOI [10.5281/zenodo.2590706](https://doi.org/10.5281/zenodo.2590706).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfherbst%2Fctx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfherbst%2Fctx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfherbst%2Fctx/lists"}