MCPcopy Create free account
hub / github.com/catboost/catboost / TestHMMap1

Method TestHMMap1

util/generic/hash_ut.cpp:374–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374void THashTest::TestHMMap1() {
375 using mmap = THashMultiMap<char, int, THash<char>, TEqualTo<char>>;
376 mmap m;
377
378 UNIT_ASSERT(m.count('X') == 0);
379 m.insert(std::pair<const char, int>('X', 10)); // Standard way.
380 UNIT_ASSERT(m.count('X') == 1);
381
382 m.insert(std::pair<const char, int>('X', 20)); // jbuck: standard way
383 UNIT_ASSERT(m.count('X') == 2);
384
385 m.insert(std::pair<const char, int>('Y', 32)); // jbuck: standard way
386 mmap::iterator i = m.find('X'); // Find first match.
387
388 UNIT_ASSERT((*i).first == 'X');
389 UNIT_ASSERT((*i).second == 10);
390 ++i;
391 UNIT_ASSERT((*i).first == 'X');
392 UNIT_ASSERT((*i).second == 20);
393
394 i = m.find('Y');
395 UNIT_ASSERT((*i).first == 'Y');
396 UNIT_ASSERT((*i).second == 32);
397
398 i = m.find('Z');
399 UNIT_ASSERT(i == m.end());
400
401 size_t count = m.erase('X');
402 UNIT_ASSERT(count == 2);
403
404 // Some iterators compare check, really compile time checks
405 mmap::iterator ite(m.begin());
406 mmap::const_iterator cite(m.begin());
407
408 UNIT_ASSERT((mmap::const_iterator)ite == cite);
409 UNIT_ASSERT(!((mmap::const_iterator)ite != cite));
410 UNIT_ASSERT(cite == (mmap::const_iterator)ite);
411 UNIT_ASSERT(!(cite != (mmap::const_iterator)ite));
412
413 using HMapType = THashMultiMap<size_t, size_t>;
414 HMapType hmap;
415
416 // We fill the map to implicitely start a rehash.
417 for (size_t counter = 0; counter < 3077; ++counter) {
418 hmap.insert(HMapType::value_type(1, counter));
419 }
420
421 hmap.insert(HMapType::value_type(12325, 1));
422 hmap.insert(HMapType::value_type(12325, 2));
423
424 UNIT_ASSERT(hmap.count(12325) == 2);
425
426 // At this point 23 goes to the same bucket as 12325, it used to reveal a bug.
427 hmap.insert(HMapType::value_type(23, 0));
428
429 UNIT_ASSERT(hmap.count(12325) == 2);
430
431 UNIT_ASSERT(hmap.bucket_count() > 3000);

Callers

nothing calls this directly

Calls 9

value_typeFunction · 0.50
countMethod · 0.45
insertMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
bucket_countMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected