Skip to content

Commit

Permalink
Document that incompatible_hash_wrapper caches the container
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sparus committed Aug 29, 2024
1 parent c77ca34 commit 8c511df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/persist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,16 @@ desired new container type ``new_table_t`` in a ``immer::persist::incompatible_h

We can see that the transformation has been applied, the keys have the ``_key`` suffix.

.. note::
While different transformed containers will not have structural sharing, transforming the same container multiple times will reuse previously transformed data.
In other words, transformation will be cached on the container level but not on the nodes level.

.. literalinclude:: ../test/extra/persist/test_for_docs.cpp
:language: c++
:start-after: start-returned-transformed-container-is-the-same
:end-before: end-returned-transformed-container-is-the-same


.. _transforming-nested-containers:

Transforming nested containers
Expand Down
6 changes: 6 additions & 0 deletions test/extra/persist/test_for_docs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@ TEST_CASE("Transform table's ID type", "[docs]")
new_item{{"two_key"}, "_2_"}};
REQUIRE(new_value == expected_new);
// include:end-new_table_t-new-hash-transformation

// include:start-returned-transformed-container-is-the-same
const auto new_value_2 =
immer::persist::convert_container(pools, transformed_pools, value);
REQUIRE(new_value_2.impl().root == new_value.impl().root);
// include:end-returned-transformed-container-is-the-same
}
}

Expand Down

0 comments on commit 8c511df

Please sign in to comment.