/* Copyright (c) 1997-2006
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*/

#ifndef _POLYMAKE_STD_HASH_ADAPTER_H
#define _POLYMAKE_STD_HASH_ADAPTER_H "$Project: polymake $$Id: hash_adapter.h 7315 2006-04-02 21:37:53Z gawrilow $"

#if defined(__INTEL_COMPILER) && !defined(__GNUC__)

#ifndef _POLYMAKE_COMPARATORS_H
#  include <comparators.h>
#endif

namespace std_ext {
   template <typename Key>
   struct hash {
      size_t operator() (const Key& k) const
      {
	 return std::hash_value(k);
      }
   };

   template <typename Key, typename HashFcn, typename EqualKey,
	     bool _reuse_cmp=pm::is_instance2_of<EqualKey,pm::operations::eq>::value>
   class hash_compare
      : public std::hash_compare<Key, EqualKey> {
      typedef std::hash_compare<Key, EqualKey> super;
   protected:
      HashFcn hf;
      pm::operations::cmp<Key> comp;
   public:
      hash_compare() { }

      hash_compare(const HashFcn& hf_arg, const EqualKey& ek_arg)
	 : super(ek_arg), hf(hf_arg) { }

      size_t operator() (const Key& key) const { return hf(key); }

      bool operator() (const Key& key1, const Key& key2) const
      {
	 return comp(key1,key2)<0;
      }
   };

   template <typename Key, typename HashFcn, typename EqualKey>
   class hash_compare<Key, HashFcn, EqualKey, false>
      : public std::hash_compare<Key, pm::operations::cmp<Key> > {
   protected:
      HashFcn hf;
      EqualKey ek;
   public:
      hash_compare() { }

      hash_compare(const HashFcn& hf_arg, const EqualKey& ek_arg)
	 : hf(hf_arg), ek(ek_arg) { }

      size_t operator() (const Key& key) const { return hf(key); }

      bool operator() (const Key& key1, const Key& key2) const
      {
	 return !ek(key1,key2) && this->comp(key1,key2)<0;
      }
   };
} // end namespace std_ext

#else // ! _POLYMAKE_ICC_ONLY

#include <string>

namespace std_ext {
   template <typename _Traits, typename _Alloc>
   struct hash< std::basic_string<char,_Traits,_Alloc> > : hash<const char*> {
      size_t operator() (const std::basic_string<char,_Traits,_Alloc>& s) const {
	 return hash<const char*>::operator() (s.c_str());
      }
   };
} // end namespace std_ext

#endif // ! _POLYMAKE_ICC_ONLY

namespace std_ext {
   template <typename T>
   struct hash<T*> {
      size_t operator() (T* x) const { return reinterpret_cast<size_t>(x); }
   };
}
#endif // _POLYMAKE_STD_HASH_ADAPTER_H

// Local Variables:
// mode:C++
// End:
