c++hashmaphashtablesgi

SGI hash_map: Basic Inquiries


I am new to SGI's hash_map as well as to the C++ language, so please bear with me. I am trying to figure out how to initialize a basic hash_map and insert and remove from it.

I have declared the hash_map as such:

Sgi::hash_map<int, Process*> ProcessManager::ListProcesses;

I intend to hash by an int value and store a pointer to an object of class Process.

However, the SGI documentation is very vague and unhelpful. I'm reading through the hash_map file but also not understanding much of it. Could someone show me the proper way to insert and erase from an SGI hash_map?

To be clear: What I'm looking for is a BASIC example to learn from. Please and thank you!


Solution

  • You can do the following.

    Sgi::hash_map<int, Process*> ListProcesses;
    
    Process *p1; // Initialize these
    Process *p2;
    
    //Insertion
    ListProcesses[10] = p1;  // new element inserted
    ListProcesses[20] = p2;  // new element inserted
    
    //Erase
    ListProcesses.erase(20);  //(20,p2) deleted
    

    As ildjarn commented, you can use std::unordered_map<> instead of the SGI one.