Tessil / ordered-map

C++ hash map and hash set which preserve the order of insertion
MIT License
512 stars 66 forks source link

ordered_set: clear() causes erros #5

Closed Mark-Joy closed 7 years ago

Mark-Joy commented 7 years ago

After clear() is called, nothing behave as it should be. My program even crashes sometimes. Not sure if it also happens to ordered_map

tsl::ordered_set<int> test2;

        test2.insert(6);
        test2.clear();
        test2.insert(104);
        test2.insert(1099);
        test2.insert(302);
        test2.insert(208);
        test2.insert(301);

        test2.erase(301);

        std::cout << "ordered_set: ";
        for (auto & i : test2)
        {
            std::cout << i << " ";
        }
        std::cout <<"\n\n";

        test2.erase(302);
        test2.insert(302);

        std::cout << "ordered_set: ";
        for (auto & i : test2)
        {
            std::cout << i << " ";
        }
        std::cout <<"\n\n";

        test2.erase(302);
        test2.insert(302);

        std::cout << "ordered_set: ";
        for (auto & i : test2)
        {
            std::cout << i << " ";
        }
        std::cout <<"\n\n";

output: ordered_set: 104 1099 302 208 ordered_set: 104 1099 302 208 ordered_set: 104 1099 302 208 ordered_set: 104 1099 302 208 301

should be: ordered_set: 104 1099 302 208 ordered_set: 104 1099 208 302 ordered_set: 104 1099 208 302 ordered_set: 104 1099 208 301

Tessil commented 7 years ago

Thank you. There was effectively a bug in clear(), made the correction.

I get the following results now (some code seems to be missing in your example, there is only three printed lines):

ordered_set: 104 1099 302 208 

ordered_set: 104 1099 208 302 

ordered_set: 104 1099 208 302
Mark-Joy commented 7 years ago

I download latest commit and it's working fine now. Thank you for your good work and fast response!