STL std::unordered_set (std::algorithm generate_n for creation of sets) | Modern Cpp Series Ep. 122

Поділитися
Вставка
  • Опубліковано 17 лис 2024

КОМЕНТАРІ • 10

  • @MightyMoveSemantics
    @MightyMoveSemantics Рік тому +1

    @7:39
    Bucket Count (e.g., std::unordered_set s(5);) This is about organizing the internal storage with a specified number of buckets. Elements are distributed among these buckets based on their hash values. Suppose you insert an integer 14. The hash function calculates a hash value, let's say h(14) = 14 for simplicity. The bucket index is then 14 % 5 = 4, so 14 is placed into bucket 4.
    reserve(5);: This is about optimizing performance by minimizing the number of rehashes when inserting elements. It does so by ensuring there's enough space allocated to hold the specified number of elements without needing to rehash. Am I right?

    • @MikeShah
      @MikeShah  Рік тому

      That sounds about right to me!

  • @tanveerasif5978
    @tanveerasif5978 4 місяці тому +1

    Thank you so much for wonderful underneath concept.

    • @MikeShah
      @MikeShah  4 місяці тому

      Cheers, you are most welcome!

  • @thestarinthesky_
    @thestarinthesky_ Рік тому +1

    Thanks Mike for this great video 🤩! I have a question why @23:36 we got that error? I didn't get it quite why.

    • @MikeShah
      @MikeShah  Рік тому +2

      I think I just had the wrong type -- needed an iterator that can insert.

  • @shrek1412
    @shrek1412 Рік тому +2

    may I know difference between unordered_set and unordered_map?

    • @MikeShah
      @MikeShah  Рік тому +2

      Unordered set only contains keys, whereas unordered map is a key/value pair. (I.e. stores the keys, same as map, but those keys are used to index and return a value)

  • @AyushAnand-oj1kl
    @AyushAnand-oj1kl Рік тому +1

    can you provide me your vim step file and commands to use it.

    • @MikeShah
      @MikeShah  Рік тому +1

      I use a vanilla vim and occasionally code completion: ua-cam.com/video/IR6pfkqjbw8/v-deo.html