From b5ccd93add426ba4aa3e46af97801d94d03ce601 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 3 May 2005 08:45:36 +0000 Subject: fixed bitreversing use flext maps svn path=/trunk/externals/nusmuk/; revision=2887 --- msd.h | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/msd.h b/msd.h index c08f15b..4d32128 100644 --- a/msd.h +++ b/msd.h @@ -39,7 +39,6 @@ #include #include #include -#include // define constants #define MSD_VERSION 0.05 @@ -218,7 +217,7 @@ template inline T bitrev(T k) { T r = 0; - for(int i = 0; i < sizeof(k)*4; ++i) r = (r<<1)|(k&1),k >>= 1; + for(int i = 0; i < sizeof(k)*8; ++i) r = (r<<1)|(k&1),k >>= 1; return r; } @@ -239,7 +238,7 @@ public: Parent::clear(); } - inline size_t size() const { return Parent::size(); } + inline int size() const { return Parent::size(); } inline T insert(unsigned int k,T v) { return Parent::insert(bitrev(k),v); } @@ -259,13 +258,13 @@ public: template class IDMap - : std::map *> + : TablePtrMap *> { public: // that's the container holding the data items (masses, links) of one ID typedef TablePtrMap Container; // that's the map for the key ID (symbol,int) relating to the data items - typedef std::map Parent; + typedef TablePtrMap Parent; typedef typename Container::iterator iterator; @@ -275,38 +274,32 @@ public: void reset() { - typename Parent::iterator it; - for(it = Parent::begin(); it != Parent::end(); ++it) - delete it->second; + typename Parent::iterator it(*this); + for(; it; ++it) delete it.data(); Parent::clear(); } void insert(T item) { - typename Parent::iterator it = Parent::find(item->Id); - Container *c; - if(it == Parent::end()) - Parent::operator[](item->Id) = c = new Container; - else - c = it->second; + Container *c = Parent::find(item->Id); + if(!c) + Parent::insert(item->Id,c = new Container); c->insert(item,item); } iterator find(const t_symbol *key) { - typename Parent::iterator it = Parent::find(key); - if(it == Parent::end()) - return iterator(); - else { - Container *c = it->second; + Container *c = Parent::find(key); + if(c) return iterator(*c); - } + else + return iterator(); } void erase(T item) { - typename Parent::iterator it = Parent::find(item->Id); - if(it != Parent::end()) it->second->remove(item); + Container *c = Parent::find(item->Id); + if(c) c->remove(item); } }; -- cgit v1.2.1