#ifndef VECTORNAMESERVER_H
#define VECTORNAMESERVER_H

#include "nameserverinterface.h"
#include <vector>
#include <utility>

using std::vector;
using std::pair;

namespace cpp_lab4 {

  class VectorNameServer : public NameServerInterface
  {
  public:
    VectorNameServer();
    ~VectorNameServer();
    
    /*
     * Insert a name/address pair. Does not check if the name
     * or address already exists.
     */
    void insert(const HostName &hostname, const IPAddress &ip);

    /*
     * Remove the pair with the specified host name. Returns true
     * if the host name existed and the pair was removed, false
     * otherwise.
     */
    bool remove(const HostName &hostname);
    
    /*
     * Find the IP address for the specified host name. Returns
     * NON_EXISTING_ADDRESS if the host name wasn't in the name
     * server.
     */
    IPAddress lookup(const HostName &hostname) const;

  private:
    vector<pair<HostName, IPAddress> > store;
  };  

  struct first_equal : binary_function<pair<HostName, IPAddress>,HostName,bool> {
    bool operator() (const pair<HostName, IPAddress>& x, const HostName& y) const
    {return x.first == y;}
  };  
}

#endif
