diff options
Diffstat (limited to '')
| -rw-r--r-- | src/hash.h | 47 |
1 files changed, 46 insertions, 1 deletions
| @@ -7,6 +7,8 @@ | |||
| 7 | #include <iostream> | 7 | #include <iostream> |
| 8 | #include "exceptionbase.h" | 8 | #include "exceptionbase.h" |
| 9 | #include "hashable.h" | 9 | #include "hashable.h" |
| 10 | #include "serializable.h" | ||
| 11 | #include "serializer.h" | ||
| 10 | 12 | ||
| 11 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) | 13 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) |
| 12 | 14 | ||
| @@ -241,7 +243,7 @@ public: | |||
| 241 | 243 | ||
| 242 | uint32_t size() | 244 | uint32_t size() |
| 243 | { | 245 | { |
| 244 | return nFilled; | 246 | return nFilled-nDeleted; |
| 245 | } | 247 | } |
| 246 | 248 | ||
| 247 | uint32_t getDeleted() | 249 | uint32_t getDeleted() |
| @@ -667,4 +669,47 @@ template<> bool __cmpHashKeys<std::string>( const std::string &a, const std::str | |||
| 667 | template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); | 669 | template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); |
| 668 | template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); | 670 | template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); |
| 669 | 671 | ||
| 672 | template<typename key, typename value> | ||
| 673 | Serializer &operator<<( Serializer &ar, Hash<key,value> &h ) | ||
| 674 | { | ||
| 675 | ar << h.size(); | ||
| 676 | for( typename Hash<key,value>::iterator i = h.begin(); i != h.end(); i++ ) | ||
| 677 | { | ||
| 678 | std::pair<key,value> p = *i; | ||
| 679 | ar << p.first << p.second; | ||
| 680 | } | ||
| 681 | |||
| 682 | return ar; | ||
| 683 | } | ||
| 684 | |||
| 685 | template<typename key, typename value> | ||
| 686 | Serializer &operator>>( Serializer &ar, Hash<key,value> &h ) | ||
| 687 | { | ||
| 688 | h.clear(); | ||
| 689 | uint32_t nSize; | ||
| 690 | ar >> nSize; | ||
| 691 | |||
| 692 | for( uint32_t j = 0; j < nSize; j++ ) | ||
| 693 | { | ||
| 694 | key k; value v; | ||
| 695 | ar >> k >> v; | ||
| 696 | h.insert( k, v ); | ||
| 697 | } | ||
| 698 | |||
| 699 | return ar; | ||
| 700 | } | ||
| 701 | |||
| 702 | template<typename key, typename value> | ||
| 703 | Serializer &operator&&( Serializer &ar, Hash<key,value> &h ) | ||
| 704 | { | ||
| 705 | if( ar.isLoading() ) | ||
| 706 | { | ||
| 707 | return ar >> h; | ||
| 708 | } | ||
| 709 | else | ||
| 710 | { | ||
| 711 | return ar << h; | ||
| 712 | } | ||
| 713 | } | ||
| 714 | |||
| 670 | #endif | 715 | #endif |
