lundi 1 juin 2015

hashtable with dynamic values

I am trying to create a hashtable that is updated dynamically as a given algorithm runs. My code is:

#include <stdio.h>
#include <unordered_map>

int main()
{
    std::unordered_map<int, int> hashtable;
    hashtable.emplace(0,0);

    if(hashtable[0]==0) 
    {
        hashtable.emplace(0,1);
    }

    for (auto itr = hashtable.begin(); itr != hashtable.end(); itr++)
    {
         printf("%d : %d", (*itr).first, (*itr).second);
    }

    return 0;
} 

The strange part is that after trying to overwrite the value of hashtable[0] it stays the same. Is there any way to make a hashtable with ovewritable ie. mutable values?

Aucun commentaire:

Enregistrer un commentaire