Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unordered_set rehash breaks insert_commit_data #81

Closed
paul203948 opened this issue Mar 10, 2023 · 1 comment
Closed

unordered_set rehash breaks insert_commit_data #81

paul203948 opened this issue Mar 10, 2023 · 1 comment

Comments

@paul203948
Copy link

Since boost 1.80.0 there is an issue performing insert_check, rehash and then insert_commit. The bucket_idx in insert_commit_data can become invalid. This was changed in commit 3c5c8ce.

The documentation explicitly states that this is allowed:

After a successful rehashing insert_commit_data remains valid.

This worked in Boost 1.79.0.

Example program:

#include <boost/intrusive/unordered_set.hpp>

struct MyClass : boost::intrusive::unordered_set_base_hook<>
{
    int n_;

    MyClass(int n) : n_(n) { }

    friend bool operator==(const MyClass &a, const MyClass &b)
        { return a.n_ == b.n_; }
    friend std::size_t hash_value(const MyClass &value)
        { return std::size_t(value.n_); }
};

int main()
{
    using Set = boost::intrusive::unordered_set<MyClass>;

    MyClass value(101);
    Set::bucket_type buckets100[100];
    Set::bucket_type buckets200[200];

    Set set(Set::bucket_traits(buckets100, 100));

    Set::insert_commit_data commitData;
    set.insert_check(value, commitData);

    set.rehash(Set::bucket_traits(buckets200, 200));

    set.insert_commit(value, commitData);

    assert(1 == set.count(101));

    return 0;
}
@igaztanaga
Copy link
Member

This was clearly a regression. To support the faster commit version, a new operation that does not support commit after rehashing is added insert_fast_commit(), and insert_commit is again compatible with rehashing. Many thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants