X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fremember.cpp;h=8db4bc82e6b39831934e20f9b28bdb1719feb657;hp=404c7c81bf0c1823c821521ac3a3f5885648b1e1;hb=8fa654f2637fa755e890499ece1a7bc498779ea3;hpb=57b66d879a72c007eabe081420de11757b5bcf90 diff --git a/ginac/remember.cpp b/ginac/remember.cpp index 404c7c81..8db4bc82 100644 --- a/ginac/remember.cpp +++ b/ginac/remember.cpp @@ -4,7 +4,7 @@ * in GiNaC functions */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,18 +18,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include "function.h" #include "utils.h" #include "remember.h" -#ifndef NO_NAMESPACE_GINAC +#include + namespace GiNaC { -#endif // ndef NO_NAMESPACE_GINAC ////////// // class remember_table_entry @@ -46,14 +44,15 @@ bool remember_table_entry::is_equal(function const & f) const { GINAC_ASSERT(f.seq.size()==seq.size()); if (f.gethash()!=hashvalue) return false; - for (unsigned i=0; i=max_assoc_size)) { // table is full, we must delete an older entry GINAC_ASSERT(size()>0); // there must be at least one entry @@ -122,11 +121,13 @@ void remember_table_list::add_entry(function const & f, ex const & result) bool remember_table_list::lookup_entry(function const & f, ex & result) const { - for (const_iterator cit=begin(); cit!=end(); ++cit) { - if ((*cit).is_equal(f)) { - result = (*cit).get_result(); + const_iterator i = begin(), iend = end(); + while (i != iend) { + if (i->is_equal(f)) { + result = i->get_result(); return true; } + ++i; } return false; } @@ -147,7 +148,7 @@ remember_table::remember_table(unsigned s, unsigned as, unsigned strat) { // we keep max_assoc_size and remember_strategy if we need to clear // all entries - + // use some power of 2 next to s table_size = 1 << log2(s); init_table(); @@ -167,25 +168,23 @@ void remember_table::add_entry(function const & f, ex const & result) operator[](entry).add_entry(f,result); } -void remember_table::clear_all_entries(void) +void remember_table::clear_all_entries() { clear(); init_table(); } -void remember_table::init_table(void) +void remember_table::init_table() { reserve(table_size); for (unsigned i=0; i & remember_table::remember_tables(void) +std::vector & remember_table::remember_tables() { - static std::vector * rt = new std::vector; - return *rt; + static std::vector rt = std::vector(); + return rt; } -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC