dictionary


template <class K, class T>
class dictionary : public Semaphore
{
 public:

  // *** typedefs ***

  typedef Integer (*keyHash)(const K&);

  typedef bool (*keyCompare)(const K&,const K&);

  // *** iterators ***

  typedef dictionaryIterator<K,T> iterator;

  typedef constDictionaryIterator<K,T> const_iterator;

  // *** Constructors, Destructor, Operators ***

  dictionary(keyHash Hasher=hasher,
             keyCompare Comparer=equality_compare);

  dictionary(const dictionary<K,T>& Copy);

  ~dictionary();

  dictionary<K,T>& operator=(const dictionary<K,T>& Copy);

  void* operator new(size_t s);

  void operator delete(void* p);

  operator keyCompare() const;

  operator keyHash() const;

  dictionary<K,T>& operator>>(const K& Key);

  const T& operator[](const K& Key) const;

  class reference
  {
   public:

   reference(dictionary<K,T>& MapSet, const K& KeySet)
    : Map(&MapSet), Key(&KeySet)  {}

   reference& operator=(const T& Value)
   {
    Map->insert(*Key,Value);
    return *this;
   }

   reference& operator=(const reference& Reference)
   {
    Map->insert(*Key,(T&)Reference);
    return *this;
   }

   operator T&() const
   {
    iterator i = Map->find(*Key);
    return i.value();
   }

   dictionary<K,T>* Map;
   const K* Key;
  };

  reference operator[](const K& Key) {return reference(*this, Key);}

  // *** Methods ***

  iterator begin();

  const_iterator begin() const;

  Unsigned depth() const; 

  iterator end();

  const_iterator end() const;

  void erase();

  void erase(const K& Key);

  void erase(iterator i);

  bool exists(const K& Key) const;

  iterator find(const K& Key) const;

  iterator insert(const K& Key,
                  const T& Data);

  iterator last();

  const_iterator last() const;

  Unsigned length() const;
};