aboutsummaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/hash.h b/src/hash.h
index 6671ae6..c37cfba 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -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
667template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); 669template<> uint32_t __calcHashCode<Hashable>( const Hashable &k );
668template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); 670template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b );
669 671
672template<typename key, typename value>
673Serializer &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
685template<typename key, typename value>
686Serializer &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
702template<typename key, typename value>
703Serializer &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