Mercurial > hg > octave-terminal
changeset 3554:747a87bc8594
[project @ 2000-02-03 03:28:49 by jwe]
author | jwe |
---|---|
date | Thu, 03 Feb 2000 03:28:49 +0000 |
parents | c5600b44bef9 |
children | 0b00b69ab2fd |
files | src/ChangeLog src/Map.cc src/Map.h |
diffstat | 3 files changed, 22 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- 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'.
--- 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 <class C> -int -goodCHptr (CHNode<C> *t) -{ - return (((X_CAST (unsigned, t)) & 1) == 0); -} - #define index_to_CHptr(i) (X_CAST (void *, (i << 1) + 1)) template <class C> -unsigned int -CHptr_to_index (CHNode<C> *t) -{ - return (X_CAST (unsigned, t)) >> 1; -} - -template <class C> CHMap<C>::CHMap (const C& dflt, unsigned int sz) : Map<C> (dflt) { tab = new CHNode<C>* [size = sz]; @@ -155,7 +137,7 @@ { unsigned int h = hash (key) % size; - for (CHNode<C> *t = tab[h]; goodCHptr (t); t = t->tl) + for (CHNode<C> *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<C> *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<C> *t = tab[h]; CHNode<C> *trail = t; - while (goodCHptr (t)) + while (t->goodCHptr ()) { if (key == t->hd) { @@ -212,7 +194,7 @@ { CHNode<C> *p = tab[i]; tab[i] = static_cast<CHNode<C> *> (index_to_CHptr (i+1)); - while (goodCHptr (p)) + while (p->goodCHptr ()) { CHNode<C> *nxt = p->tl; delete p; @@ -227,7 +209,7 @@ CHMap<C>::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<C>::next (Pix& p) const { CHNode<C> *t = (static_cast<CHNode<C> *> (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<C> *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;
--- 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