1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org> 2 3 #ifndef DICT_H 4 #define DICT_H 5 6 #include "patriciatree.h" 7 #include "ustring.h" 8 #include "estring.h" 9 10 11 template<class T> 12 class Dict: public PatriciaTree<T> { 13 public: Dict()14 Dict(): PatriciaTree<T>() {} 15 find(const EString & s)16 T * find( const EString & s ) const { 17 return PatriciaTree<T>::find( s.data(), s.length() * 8 ); 18 } insert(const EString & s,T * r)19 void insert( const EString & s, T* r ) { 20 PatriciaTree<T>::insert( s.data(), s.length() * 8, r ); 21 } remove(const EString & s)22 T* remove( const EString & s ) { 23 return PatriciaTree<T>::remove( s.data(), s.length() * 8 ); 24 } contains(const EString & s)25 bool contains( const EString & s ) const { 26 return find( s ) != 0; 27 } 28 29 private: 30 // operators explicitly undefined because there is no single 31 // correct way to implement them. 32 Dict< T > &operator =( const Dict< T > & ) { return *this; } 33 bool operator ==( const Dict< T > & ) const { return false; } 34 bool operator !=( const Dict< T > & ) const { return false; } 35 }; 36 37 38 template<class T> 39 class UDict: public PatriciaTree<T> { 40 public: UDict()41 UDict(): PatriciaTree<T>() {} 42 find(const UString & s)43 T * find( const UString & s ) const { 44 return PatriciaTree<T>::find( (const char *)s.data(), s.length() * 8 * sizeof( uint ) ); 45 } insert(const UString & s,T * r)46 void insert( const UString & s, T* r ) { 47 PatriciaTree<T>::insert( (const char *)s.data(), s.length() * 8 * sizeof( uint ), r ); 48 } remove(const UString & s)49 T* remove( const UString & s ) { 50 return PatriciaTree<T>::remove( (const char *)s.data(), s.length() * 8 * sizeof( uint ) ); 51 } contains(const UString & s)52 bool contains( const UString & s ) const { 53 return find( s ) != 0; 54 } 55 56 private: 57 // operators explicitly undefined because there is no single 58 // correct way to implement them. 59 UDict< T > &operator =( const UDict< T > & ) { return *this; } 60 bool operator ==( const UDict< T > & ) const { return false; } 61 bool operator !=( const UDict< T > & ) const { return false; } 62 }; 63 64 65 #endif 66