diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-11-12 17:05:30 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-11-12 17:05:30 +0000 |
commit | 509d136e9adb60c56369565b9545e613cac3678e (patch) | |
tree | f118d676edeae2d5e17f48b32b180d4761b60520 /src/hash.h | |
parent | 3166bd631a093f42ea44a4b0f4d914cf51518bd4 (diff) | |
download | libbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.gz libbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.bz2 libbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.xz libbu++-509d136e9adb60c56369565b9545e613cac3678e.zip |
I've started my campaign to clean up all of the header files in libbu++ as far
as includes go. This required a little bit of reworking as far as archive goes,
but I've been planning on changing it aronud for a bit anyway.
The final result here is that you may need to add some more includes in your
own code, libbu++ doesn't include as many random things you didn't ask for
anymore, most of these seem to be bu/hash.h, unistd.h, and time.h.
Also, any Archive functions and operators should use ArchiveBase when they can
instead of Archive, archivebase.h is a much lighterweight include that will
be used everywhere in core that it can be, there are a few classes that actually
want a specific archiver to be used, they will use it (such as the nids storage
class).
So far, except for adding header files, nothing has changed in functionality,
and no other code changes should be required, although the above mentioned
archive changeover is reccomended.
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 56 |
1 files changed, 19 insertions, 37 deletions
@@ -8,17 +8,11 @@ | |||
8 | #ifndef BU_HASH_H | 8 | #ifndef BU_HASH_H |
9 | #define BU_HASH_H | 9 | #define BU_HASH_H |
10 | 10 | ||
11 | #include <stddef.h> | ||
12 | #include <string.h> | ||
13 | #include <memory> | 11 | #include <memory> |
14 | #include <iostream> | ||
15 | #include <list> | ||
16 | #include <utility> | ||
17 | #include "bu/exceptionbase.h" | 12 | #include "bu/exceptionbase.h" |
18 | #include "bu/list.h" | 13 | #include "bu/list.h" |
19 | #include "bu/util.h" | 14 | #include "bu/util.h" |
20 | //#include "archival.h" | 15 | #include "archivebase.h" |
21 | //#include "archive.h" | ||
22 | 16 | ||
23 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) | 17 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) |
24 | 18 | ||
@@ -373,6 +367,11 @@ namespace Bu | |||
373 | return nFilled-nDeleted; | 367 | return nFilled-nDeleted; |
374 | } | 368 | } |
375 | 369 | ||
370 | bool isEmpty() const | ||
371 | { | ||
372 | return (nFilled-nDeleted) == 0; | ||
373 | } | ||
374 | |||
376 | /** | 375 | /** |
377 | * Get the number of items which have been deleted, but not yet | 376 | * Get the number of items which have been deleted, but not yet |
378 | * cleaned up. | 377 | * cleaned up. |
@@ -1171,9 +1170,6 @@ namespace Bu | |||
1171 | template<> uint32_t __calcHashCode<char *>( char * const &k ); | 1170 | template<> uint32_t __calcHashCode<char *>( char * const &k ); |
1172 | template<> bool __cmpHashKeys<char *>( char * const &a, char * const &b ); | 1171 | template<> bool __cmpHashKeys<char *>( char * const &a, char * const &b ); |
1173 | 1172 | ||
1174 | template<> uint32_t __calcHashCode<std::string>( const std::string &k ); | ||
1175 | template<> bool __cmpHashKeys<std::string>( const std::string &a, const std::string &b ); | ||
1176 | |||
1177 | class Formatter; | 1173 | class Formatter; |
1178 | Formatter &operator<<( Formatter &rOut, char *sStr ); | 1174 | Formatter &operator<<( Formatter &rOut, char *sStr ); |
1179 | Formatter &operator<<( Formatter &rOut, signed char c ); | 1175 | Formatter &operator<<( Formatter &rOut, signed char c ); |
@@ -1190,30 +1186,30 @@ namespace Bu | |||
1190 | f << '}'; | 1186 | f << '}'; |
1191 | 1187 | ||
1192 | return f; | 1188 | return f; |
1193 | } | 1189 | } |
1194 | 1190 | ||
1195 | /* | 1191 | template<typename key, typename value, typename a, typename b, |
1196 | template<typename key, typename value> | 1192 | typename c, typename d> |
1197 | Archive &operator<<( Archive &ar, Hash<key,value> &h ) | 1193 | ArchiveBase &operator<<( ArchiveBase &ar, const Hash<key,value,a,b,c,d> &h ) |
1198 | { | 1194 | { |
1199 | ar << h.size(); | 1195 | ar << h.getSize(); |
1200 | for( typename Hash<key,value>::iterator i = h.begin(); i != h.end(); i++ ) | 1196 | for( typename Hash<key,value>::const_iterator i = h.begin(); i != h.end(); i++ ) |
1201 | { | 1197 | { |
1202 | std::pair<key,value> p = *i; | 1198 | ar << (i.getKey()) << (i.getValue()); |
1203 | ar << p.first << p.second; | ||
1204 | } | 1199 | } |
1205 | 1200 | ||
1206 | return ar; | 1201 | return ar; |
1207 | } | 1202 | } |
1208 | 1203 | ||
1209 | template<typename key, typename value> | 1204 | template<typename key, typename value, typename a, typename b, |
1210 | Archive &operator>>( Archive &ar, Hash<key,value> &h ) | 1205 | typename c, typename d> |
1206 | ArchiveBase &operator>>( ArchiveBase &ar, Hash<key,value,a,b,c,d> &h ) | ||
1211 | { | 1207 | { |
1212 | h.clear(); | 1208 | h.clear(); |
1213 | uint32_t nSize; | 1209 | long nSize; |
1214 | ar >> nSize; | 1210 | ar >> nSize; |
1215 | 1211 | ||
1216 | for( uint32_t j = 0; j < nSize; j++ ) | 1212 | for( long j = 0; j < nSize; j++ ) |
1217 | { | 1213 | { |
1218 | key k; value v; | 1214 | key k; value v; |
1219 | ar >> k >> v; | 1215 | ar >> k >> v; |
@@ -1221,21 +1217,7 @@ namespace Bu | |||
1221 | } | 1217 | } |
1222 | 1218 | ||
1223 | return ar; | 1219 | return ar; |
1224 | }*/ | 1220 | } |
1225 | |||
1226 | /* | ||
1227 | template<typename key, typename value> | ||
1228 | Serializer &operator&&( Serializer &ar, Hash<key,value> &h ) | ||
1229 | { | ||
1230 | if( ar.isLoading() ) | ||
1231 | { | ||
1232 | return ar >> h; | ||
1233 | } | ||
1234 | else | ||
1235 | { | ||
1236 | return ar << h; | ||
1237 | } | ||
1238 | }*/ | ||
1239 | } | 1221 | } |
1240 | 1222 | ||
1241 | #endif | 1223 | #endif |