/////////////////////////////////////////////////////////////////////////////// // // // This file is part of ModelBlocks. Copyright 2009, ModelBlocks developers. // // // // ModelBlocks 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 3 of the License, or // // (at your option) any later version. // // // // ModelBlocks 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. // // // // You should have received a copy of the GNU General Public License // // along with ModelBlocks. If not, see . // // // // ModelBlocks developers designate this particular file as subject to // // the "Moses" exception as provided by ModelBlocks developers in // // the LICENSE file that accompanies this code. // // // /////////////////////////////////////////////////////////////////////////////// #ifndef __NL_HASH_H_ #define __NL_HASH_H_ #include //#include #include using namespace __gnu_cxx; /////////////////////////////////////////////////////////////////////////////// template class SimpleHashFn { public: size_t operator() ( const T& t ) const { return t.getHashKey(); } }; template class SimpleHashEqual { public: bool operator() ( const T& t1, const T& t2 ) const { return (t1 == t2); } }; template class SimpleHash : public hash_map,SimpleHashEqual > /*public tr1::unordered_map,SimpleHashEqual >*/ { private: typedef hash_map,SimpleHashEqual > OrigHash; // typedef tr1::unordered_map,SimpleHashEqual > OrigHash; // tr1::unordered_map,SimpleHashEqual > mxy; static const Y yDummy; //static Y yNonconstDummy; public: // typedef typename OrigHash::const_iterator const_iterator; // typedef typename OrigHash::iterator iterator; // static const const_iterator iDummy; // Constructor / destructor methods... SimpleHash ( ) : OrigHash() { } SimpleHash ( int i ) : OrigHash(i) { } SimpleHash (const SimpleHash& s) : OrigHash(s) { } // Specification methods... Y& set ( const X& x ) { return OrigHash::operator[](x); } // Extraction methods... const Y& get ( const X& x ) const { return (OrigHash::end()!=OrigHash::find(x)) ? OrigHash::find(x)->second : yDummy; } bool contains ( const X& x ) const { return (OrigHash::end()!=OrigHash::find(x)); } // const Y& get ( const X& x ) const { return (mxy.end()!=mxy.find(x)) ? mxy.find(x)->second : yDummy; } // Y& set ( const X& x ) { return mxy[x]; } friend ostream& operator<< ( ostream& os, const SimpleHash& h ) { for ( typename SimpleHash::const_iterator it=h.begin(); it!=h.end(); it++ ) os<<((it==h.begin())?"":",")<first<<":"<second; return os; } }; template const Y SimpleHash::yDummy = Y(); //template Y SimpleHash::yNonconstDummy; // = Y(); /* template class SimpleMultiHash : public tr1::unordered_multimap,SimpleHashEqual > { private: typedef tr1::unordered_multimap,SimpleHashEqual > OrigHash; public: typedef pair const_iterator_pair; // Constructor / destructor methods... SimpleMultiHash ( ) : OrigHash() { } SimpleMultiHash ( int i ) : OrigHash(i) { } // Specification methods... Y& add ( const X& x ) { return insert(typename OrigHash::value_type(x,Y()))->second; } // Extraction methods... bool contains ( const X& x ) const { return (OrigHash::end()!=OrigHash::find(x)); } bool contains ( const X& x, const Y& y ) const { if (OrigHash::end()==OrigHash::find(x)) return false; for ( const_iterator_pair ii=OrigHash::equal_range(x); ii.first!=ii.second; ii.first++ ) if ( y == ii.first->second ) return true; return false; } }; */ #endif // __NL_HASH_H_