MCPcopy Create free account
hub / github.com/boostorg/json / testCollisions

Method testCollisions

test/object.cpp:1560–1645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1558 }
1559
1560 void
1561 testCollisions()
1562 {
1563 int constexpr buckets =
1564 detail::small_object_size_ + 1;
1565 int constexpr collisions = 3;
1566
1567 //DECLARE_INIT_LISTS;
1568
1569 // find a set of keys that collide
1570 std::vector<std::string> v;
1571 object o;
1572 o.reserve(buckets);
1573 {
1574 BOOST_TEST(
1575 o.capacity() == buckets);
1576 char buf[26];
1577 auto const match =
1578 o.t_->digest("0") % buckets;
1579 v.push_back("0");
1580 std::size_t i = 1;
1581 for(;;)
1582 {
1583 auto s = make_key(i, buf);
1584 if((o.t_->digest(s) %
1585 buckets) == match)
1586 {
1587 v.push_back(std::string(
1588 s.data(), s.size()));
1589 if(v.size() >= collisions)
1590 break;
1591 }
1592 ++i;
1593 }
1594 }
1595
1596 // ensure collisions are distinguishable
1597 {
1598 o.clear();
1599 BOOST_TEST(
1600 (o.t_->digest(v[0]) % buckets) ==
1601 (o.t_->digest(v[1]) % buckets));
1602 BOOST_TEST(
1603 (o.t_->digest(v[1]) % buckets) ==
1604 (o.t_->digest(v[2]) % buckets));
1605 o.emplace(v[0], 1);
1606 o.emplace(v[1], 2);
1607 o.emplace(v[2], 3);
1608 BOOST_TEST(o.at(v[0]).to_number<int>() == 1);
1609 BOOST_TEST(o.at(v[1]).to_number<int>() == 2);
1610 BOOST_TEST(o.at(v[2]).to_number<int>() == 3);
1611 }
1612
1613 // erase k1
1614 {
1615 o.clear();
1616 o.emplace(v[0], 1);
1617 o.emplace(v[1], 2);

Callers

nothing calls this directly

Calls 8

emplaceMethod · 0.80
stringClass · 0.50
reserveMethod · 0.45
capacityMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected