1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org> 2 3 #ifndef MAP_H 4 #define MAP_H 5 6 #include "global.h" 7 #include "patriciatree.h" 8 9 10 extern uint uintInNetworkOrder( uint ); 11 12 13 template<class T> 14 class Map 15 : public PatriciaTree<T> 16 { 17 public: Map()18 Map() {} // more? 19 find(uint i)20 T * find( uint i ) { 21 uint x=k(i); 22 return PatriciaTree<T>::find( (char*)&x, l() ); 23 } insert(uint i,T * r)24 void insert( uint i, T * r ) { 25 uint x=k(i); 26 PatriciaTree<T>::insert( (char*)&x,l(),r ); 27 } remove(uint i)28 void remove( uint i ) { 29 uint x=k(i); 30 PatriciaTree<T>::remove( (char*)&x, l() ); 31 } contains(uint i)32 bool contains( uint i ) { return find( i ) != 0; } 33 34 private: k(uint i)35 static uint k( uint i ) { return ::uintInNetworkOrder( i ); } l()36 static uint l() { return 8 * sizeof( uint ); } 37 38 private: 39 // operators explicitly undefined because there is no single 40 // correct way to implement them. 41 Map< T > &operator =( const Map< T > & ) { return *this; } 42 bool operator ==( const Map< T > & ) const { return false; } 43 bool operator !=( const Map< T > & ) const { return false; } 44 }; 45 46 47 #endif 48