immer – 一个用C++编写的持久且不可变数据结构库。
Immer – A library of persistent and immutable data structures written in C++

原始链接: https://github.com/arximboldi/immer

## Immer:C++的持久与不可变数据结构 Immer是一个C++14的头文件库,提供持久和不可变的数据结构,旨在简化交互式和并发程序的开发。它以性能为目标构建,利用现代C++特性提供高效且自然的API。 Immer的核心优势在于结构共享和持久性——修改会创建新版本,而不会改变原始版本,从而实现高效的变更跟踪,用于响应式编程和安全的并发访问,无需显式锁。它具有O(log(n))连接等特性,具有并行化的潜力。 该库通过模板和基于策略的设计具有高度的可定制性,可适应各种架构,甚至可以用作其他语言(如Python)中不可变数据结构的基石。它可以通过直接包含、Nix、CMake或vcpkg轻松集成。 开发受到基准测试和持续测试(Clang & GCC)的支持,该项目欢迎赞助以确保长期可持续性。Ewig(一个文本编辑器)和Lager(一个类似Redux的库)等示例展示了它的实际应用。 采用Boost软件许可证1.0。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 immer – 一个用 C++ 编写的持久且不可变数据结构库 (github.com/arximboldi) 9 分,smartmic 发表于 3 小时前 | 隐藏 | 过去 | 收藏 | 2 条评论 asa 发表于 8 分钟前 | 下一个 [–] 好东西。非常好的东西。回复 gnabgib 发表于 3 小时前 | 上一个 [–] 在以下时间流行: 2019 (102 分,56 评论) https://news.ycombinator.com/item?id=20947222 2016 (144 分,46 评论) https://news.ycombinator.com/item?id=13049843 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文
GitHub Actions Badge CodeCov Badge Sinusoidal Engineering badge Logotype

immer is a library of persistent and immutable data structures written in C++. These enable whole new kinds of architectures for interactive and concurrent programs of striking simplicity, correctness, and performance.

This library has full months of pro bono research and development invested in it. This is just the first step in a long-term vision of making interactive and concurrent C++ programs easier to write. Put your logo here and help this project's long term sustainability by buying a sponsorship package: [email protected]

#include <immer/vector.hpp>
int main()
{
    const auto v0 = immer::vector<int>{};
    const auto v1 = v0.push_back(13);
    assert(v0.size() == 0 && v1.size() == 1 && v1[0] == 13);

    const auto v2 = v1.set(0, 42);
    assert(v1[0] == 13 && v2[0] == 42);
}
For a complete example check Ewig, a simple didactic text-editor built with this library. You may also wanna check Lager, a Redux-like library for writing interactive software in C++ using a value-oriented design.

In the last few years, there has been a growing interest in immutable data structures, motivated by the horizontal scaling of our processing power and the ubiquity of highly interactive systems. Languages like Clojure and Scala provide them by default, and implementations for JavaScript like Mori and Immutable.js are widely used, specially in combination with modern UI frameworks like React.

Interactivity
Thanks to persistence and structural sharing, new values can be efficiently compared with old ones. This enables simpler ways of reasoning about change that sit at the core of modern interactive systems programming paradigms like reactive programming.
Concurrency
Passing immutable data structures by value does not need to copy any data. In the absence of mutation, data can be safely read from multiple concurrent processes, and enable concurrency patterns like share by communicating efficiently.
Parallelism
Some recent immutable data structures have interesting properties like O(log(n)) concatenation, which enable new kinds of parallelization algorithms.
Idiomatic
This library doesn't pretend that it is written in Haskell. It leverages features from recent standards to provide an API that is both efficient and natural for a C++ developer.
Performant
You use C++ because you need this. Immer implements state of the art data structures with efficient cache utilization and have been proven production ready in other languages. It also includes our own improvements over that are only possible because of the C++'s ability to abstract over memory layout. We monitor the performance impact of every change by collecting benchmark results directly from CI.
Customizable
We leverage templates and policy-based design to build data-structures that can be adapted to work efficiently for various purposes and architectures, for example, by choosing among various memory management strategies. This turns immer into a good foundation to provide immutable data structures to higher level languages with a C runtime, like Python or Guile.

This library is written in C++14 and a compliant compiler is necessary. It is continuously tested with Clang 3.8 and GCC 6, but it might work with other compilers and versions.

No external library is necessary and there are no other requirements.

This is a header only library. You can just copy the immer subfolder somewhere in your include path.

If you are using the Nix package manager (we strongly recommend it) you can just:

nix-env -if https://github.com/arximboldi/immer/archive/master.tar.gz

Alternatively, you can use CMake to install the library in your system once you have manually cloned the repository:

mkdir -p build && cd build
cmake .. && sudo make install

You can download and install immer using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install immer

The immer port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

For projects using build2, ensure your project is setup to use cppget.org as a package repository, then add immer as a dependency in your project's manifest file:

depends: libimmer ^0.8.1

Then in your buildfile, import and link against the library:

import libs = libimmer%lib{immer}

exe{hello}: {hxx cxx}{**} $libs

The immer package in build2 is kept up to date by community contributors. If the version is out of date, please create an issue or pull request on immer build2 package repository.

In order to develop the library, you will need to compile and run the examples, tests and benchmarks. These require some additional tools. The easiest way to install them is by using the Nix package manager. At the root of the repository just type:

nix-shell

This will download all required dependencies and create an isolated environment in which you can use these dependencies, without polluting your system.

Then you can proceed to generate a development project using CMake:

mkdir build && cd build
cmake ..

From then on, one may build and run all tests by doing:

make check

In order to build and run all benchmarks when running make check, run cmake again with the option -DCHECK_BENCHMARKS=1. The results of running the benchmarks will be saved to a folder reports/ in the project root.

This software is licensed under the Boost Software License 1.0.

Boost logo

The full text of the license is can be accessed via this link and is also included in the LICENSE file of this software package.

联系我们 contact @ memedata.com