# HG changeset patch # User jwe # Date 949548529 0 # Node ID 747a87bc85943ff5bd8a4be3294fe1f7b7a0b3f5 # Parent c5600b44bef95510f04770c4b91c995c615956d5 [project @ 2000-02-03 03:28:49 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -13,6 +13,8 @@ * TEMPLATE-INST/Map-fnc.cc: Don't try to instantiate goodCHptr or CHptr_to_index here. * TEMPLATE-INST/Map-tc.cc: Likewise. + * Map.h (CHNode::goodCHptr, CHNode::CHptr_to_index): Now member + functions. Change all callers. * load-save.cc (read_binary_file_header): Declare magic_len `const'. diff --git a/src/Map.cc b/src/Map.cc --- a/src/Map.cc +++ b/src/Map.cc @@ -109,27 +109,9 @@ // CHMap class. -// The nodes are linked together serially via a version of a trick -// used in some vtables: odd pointers are actually links to the next -// table entry. Not terrible, but not wonderful either. - -template -int -goodCHptr (CHNode *t) -{ - return (((X_CAST (unsigned, t)) & 1) == 0); -} - #define index_to_CHptr(i) (X_CAST (void *, (i << 1) + 1)) template -unsigned int -CHptr_to_index (CHNode *t) -{ - return (X_CAST (unsigned, t)) >> 1; -} - -template CHMap::CHMap (const C& dflt, unsigned int sz) : Map (dflt) { tab = new CHNode* [size = sz]; @@ -155,7 +137,7 @@ { unsigned int h = hash (key) % size; - for (CHNode *t = tab[h]; goodCHptr (t); t = t->tl) + for (CHNode *t = tab[h]; t->goodCHptr (); t = t->tl) if (key == t->hd) return Pix (t); @@ -169,7 +151,7 @@ unsigned int h = hash (item) % size; CHNode *t = 0; - for (t = tab[h]; goodCHptr (t); t = t->tl) + for (t = tab[h]; t->goodCHptr (); t = t->tl) if (item == t->hd) return t->cont; @@ -187,7 +169,7 @@ CHNode *t = tab[h]; CHNode *trail = t; - while (goodCHptr (t)) + while (t->goodCHptr ()) { if (key == t->hd) { @@ -212,7 +194,7 @@ { CHNode *p = tab[i]; tab[i] = static_cast *> (index_to_CHptr (i+1)); - while (goodCHptr (p)) + while (p->goodCHptr ()) { CHNode *nxt = p->tl; delete p; @@ -227,7 +209,7 @@ CHMap::first (void) const { for (unsigned int i = 0; i < size; ++i) - if (goodCHptr (tab[i])) + if (tab[i]->goodCHptr ()) return Pix (tab[i]); return 0; } @@ -237,13 +219,13 @@ CHMap::next (Pix& p) const { CHNode *t = (static_cast *> (p))->tl; - if (goodCHptr (t)) + if (t->goodCHptr ()) p = Pix (t); else { - for (unsigned int i = CHptr_to_index (t); i < size; ++i) + for (unsigned int i = t->CHptr_to_index (); i < size; ++i) { - if (goodCHptr (tab[i])) + if (tab[i]->goodCHptr ()) { p = Pix (tab[i]); return; @@ -264,10 +246,10 @@ { CHNode *p = 0; - for (p = tab[i]; goodCHptr (p); p = p->tl) + for (p = tab[i]; p->goodCHptr (); p = p->tl) ++n; - v &= CHptr_to_index (p) == i + 1; + v &= p->CHptr_to_index () == i + 1; } v &= count == n; diff --git a/src/Map.h b/src/Map.h --- a/src/Map.h +++ b/src/Map.h @@ -95,6 +95,16 @@ : tl (t), hd (h), cont (c) { } ~CHNode (void) { } + + // The nodes are linked together serially via a version of a trick + // used in some vtables: odd pointers are actually links to the next + // table entry. Not terrible, but not wonderful either. + + int goodCHptr (void) + { return (((X_CAST (unsigned, t)) & 1) == 0); } + + unsigned int CHptr_to_index (void) + { return (X_CAST (unsigned, t)) >> 1; } }; #ifndef DEFAULT_INITIAL_CAPACITY