c++ - Why retrieving elements from CMap is not ordered -


In my application, I have CMP of CString values. After adding the elements in the map, if I If I retrieve the elements, then the element is not getting in the order of the inclusion. Suppose I get the third element again, I get the fifth in this way. Is it the behavior of CMAP? Why this happens?

If you asked "why", then it goes here:

A map Provides an effective way of obtaining value by the key, using a clever figure structure which is faster than the list or will be an array (where you should know if there is an element or not). There are trade-offs, such as the increase in memory usage, and the inability of some other things (such as knowing what things were included).

There are two common methods of applying it

  • A hashp, which puts the keys in the bucket with the hash value.
  • A treemap, which organizes the keys in the binary tree, is sorted accordingly

    You can do it again on the map, but according to them That's how they are internally stored, either in the key sequence (treemap) or completely unexpected (hashpap) your sympe seems a hashish.

    In any way, the order of entry is not preserved if you want you to require an additional dataset (such as the list).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -