From f5ac2c1ba333ce6aa6d385d9a63b658caaa46503 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 18 Aug 2012 23:43:21 +0000 Subject: Added hashtable += support, optomized the random number base some? --- src/stable/hash.h | 15 +++++++++++++++ src/stable/randombase.cpp | 15 --------------- src/stable/randombase.h | 13 ++++++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) (limited to 'src/stable') diff --git a/src/stable/hash.h b/src/stable/hash.h index e461cf5..86f189e 100644 --- a/src/stable/hash.h +++ b/src/stable/hash.h @@ -1212,6 +1212,21 @@ namespace Bu return !(*this == rhs); } + MyType &operator+=( const MyType &rhs ) + { + if( this == &rhs ) + return *this; + if( core == rhs.core ) + return *this; + if( core == NULL || rhs.core == NULL ) + return *this; + + for( const_iterator i = rhs.begin(); i; i++ ) + insert( i.getKey(), i.getValue() ); + + return *this; + } + protected: virtual Core *_copyCore( Core *src ) { diff --git a/src/stable/randombase.cpp b/src/stable/randombase.cpp index 71a5c89..6514df3 100644 --- a/src/stable/randombase.cpp +++ b/src/stable/randombase.cpp @@ -14,18 +14,3 @@ Bu::RandomBase::~RandomBase() { } -int32_t Bu::RandomBase::rand( int32_t iMax ) -{ - return rand( 0, iMax ); -} - -int32_t Bu::RandomBase::rand( int32_t iMin, int32_t iMax ) -{ - return iMin+(randNorm()*(iMax-iMin)); -} - -double Bu::RandomBase::randNorm() -{ - return (((uint32_t)rand())&0xfffffffeul)/(double)(0xfffffffful); -} - diff --git a/src/stable/randombase.h b/src/stable/randombase.h index a5a4f42..d33bb99 100644 --- a/src/stable/randombase.h +++ b/src/stable/randombase.h @@ -19,9 +19,16 @@ namespace Bu virtual void seed( int32_t iSeed )=0; virtual int32_t rand()=0; - virtual int32_t rand( int32_t iMax ); - virtual int32_t rand( int32_t iMin, int32_t iMax ); - virtual double randNorm(); + virtual inline int32_t rand( int32_t iMax ) { + return rand( 0, iMax ); + } + virtual inline int32_t rand( int32_t iMin, int32_t iMax ) { + return iMin+(randNorm()*(iMax-iMin)); + } + virtual inline double randNorm() { + return (((uint32_t)rand())&0xfffffffeul)*0x1.00000001p-32; +// return (((uint32_t)rand())&0xfffffffeul)/(double)(0xfffffffful); + } }; }; -- cgit v1.2.3