map


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

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

  typedef mapIterator<K,T> iterator;

  typedef constMapIterator<K,T> const_iterator;

  map(keyCompare C=compare);

  map(const map<K,T>& copy);

  ~map();

  map<K,T>& operator=(const map<K,T>& copy);

  operator keyCompare() const;

  void* operator new(size_t s);

  void operator delete(void* p);

  iterator after(K Key) const;

  iterator afterEquals(K Key) const;

  iterator before(K Key) const;

  iterator beforeEquals(K Key) const;

  iterator begin();

  const_iterator begin() const;

  Unsigned depth() const; 

  iterator end();

  const_iterator end() const;

  void erase();

  void erase(K Key);

  iterator find(K Key) const;

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

  iterator last();

  const_iterator last() const;

  Unsigned length() const;

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

  class reference
  {
   public:

   reference(map<K,T>& MapSet, 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();
   }

   map<K,T>* Map;
   K Key;
  };

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

  map<K,T>& operator>>(const K& key);

  void sort(int (*Compare)(const T&,const T&)=compare);
};