| | | | | |

AssociativeArray as Set<Entry>

class AssociativeArray
{
public:
  void Put (const KeyType& k, const DataType& d)
  {
    Entry e(k,d);
    table_.Insert(e);      // assumes Set is unimodal
  }
  DataType& Get (const KeyType& k)
  {
    Entry e(k,DataType());
    Set::Iterator i = table_.Includes(e);
    if (i == table_.End()) // search failed
    {
      table_.Insert(k,d);
      i = table_.Includes(e);
    }
    return *i.data_;       // ref to table entry data
  }
  void Erase (const KeyType& k)
  {
    table_.Remove(Entry(k,DataType()));
  }

private:
  Set < Entry >  table_;
};

| | Top of Page | 10. Introduction to Maps - 10 of 11