From 8c0b390617ea42af40d409bd1fbc541e63321239 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 13 Sep 2007 06:21:54 +0000 Subject: Sets now match Hashes better, and can be Archived. --- src/archive.h | 32 +++++++++++++++++++++++++++++++- src/set.h | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/archive.h b/src/archive.h index 24c3a67..b5477bb 100644 --- a/src/archive.h +++ b/src/archive.h @@ -8,6 +8,7 @@ #include #include "bu/hash.h" #include "bu/list.h" +#include "bu/set.h" namespace Bu { @@ -235,7 +236,36 @@ namespace Bu } return ar; - } + } + + template + Archive &operator<<( Archive &ar, Set &h ) + { + ar << h.getSize(); + for( typename Set::iterator i = h.begin(); i != h.end(); i++ ) + { + ar << (*i); + } + + return ar; + } + + template + Archive &operator>>( Archive &ar, Set &h ) + { + h.clear(); + uint32_t nSize; + ar >> nSize; + + for( uint32_t j = 0; j < nSize; j++ ) + { + value v; + ar >> v; + h.insert( v ); + } + + return ar; + } } #endif diff --git a/src/set.h b/src/set.h index 4788804..ce2c10a 100644 --- a/src/set.h +++ b/src/set.h @@ -162,7 +162,7 @@ namespace Bu * Get the number of items stored in the hash table. *@returns (uint32_t) The number of items stored in the hash table. */ - uint32_t size() + uint32_t getSize() { return nFilled-nDeleted; } -- cgit v1.2.3