X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fremember.h;h=d140f9018f77f375e3d471fc4d6641231c40ad93;hp=07e8ec9de9aebd5814e102d19dc07aba3678fe3d;hb=a06a27122b0a9087e9c64743940016c7e0176ce2;hpb=660dc3380d44928709d5ac47d3ad6e98bb7c30c2 diff --git a/ginac/remember.h b/ginac/remember.h index 07e8ec9d..d140f901 100644 --- a/ginac/remember.h +++ b/ginac/remember.h @@ -4,7 +4,7 @@ * in GiNaC functions */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2011 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,82 +18,84 @@ * * 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 +#ifndef GINAC_REMEMBER_H +#define GINAC_REMEMBER_H + +#include #include +#include -#ifndef NO_NAMESPACE_GINAC namespace GiNaC { -#endif // ndef NO_NAMESPACE_GINAC class function; class ex; - + /** A single entry in the remember table of a function. - Needs to be a friend of class function to access 'seq'. - 'last_access' and 'successful_hits' are updated at each successful - 'is_equal'. */ + * Needs to be a friend of class function to access 'seq'. + * 'last_access' and 'successful_hits' are updated at each successful + * 'is_equal'. */ class remember_table_entry { public: - remember_table_entry(function const & f, ex const & r); - bool is_equal(function const & f) const; - ex get_result(void) const { return result; } - unsigned long get_last_access(void) const { return last_access; } - unsigned long get_successful_hits(void) const { return successful_hits; }; + remember_table_entry(function const & f, ex const & r); + bool is_equal(function const & f) const; + ex get_result() const { return result; } + unsigned long get_last_access() const { return last_access; } + unsigned long get_successful_hits() const { return successful_hits; }; protected: - unsigned hashvalue; - exvector seq; - ex result; - mutable unsigned long last_access; - mutable unsigned successful_hits; - static unsigned long access_counter; + unsigned hashvalue; + exvector seq; + ex result; + mutable unsigned long last_access; + mutable unsigned successful_hits; + static unsigned long access_counter; }; /** A list of entries in the remember table having some least - significant bits of the hashvalue in common. */ -class remember_table_list : public list { + * significant bits of the hashvalue in common. */ +class remember_table_list : public std::list { public: - remember_table_list(unsigned as, unsigned strat); - void add_entry(function const & f, ex const & result); - bool lookup_entry(function const & f, ex & result) const; + remember_table_list(unsigned as, unsigned strat); + void add_entry(function const & f, ex const & result); + bool lookup_entry(function const & f, ex & result) const; protected: - unsigned max_assoc_size; - unsigned remember_strategy; + unsigned max_assoc_size; + unsigned remember_strategy; }; /** The remember table is organized like an n-fold associative cache - in a microprocessor. The table has a width of 's' (which is rounded - to table_size, some power of 2 near 's', internally) and a depth of 'as' - (unless you choose that entries are never discarded). The place where - an entry is stored depends on the hashvalue of the parameters of the - function (this corresponds to the address of byte to be cached). - The 'log_2(table_size)' least significant bits of this hashvalue - give the slot in which the entry will be stored or looked up. - Each slot can take up to 'as' entries. If a slot is full, an older - entry is removed by one of the following strategies: - - oldest entry (the first one in the list) - - least recently used (the one with the lowest 'last_access') - - least frequently used (the one with the lowest 'successful_hits') - or all entries are kept which means that the table grows indefinitely. */ -class remember_table : public vector { + * in a microprocessor. The table has a width of 's' (which is rounded + * to table_size, some power of 2 near 's', internally) and a depth of 'as' + * (unless you choose that entries are never discarded). The place where + * an entry is stored depends on the hashvalue of the parameters of the + * function (this corresponds to the address of byte to be cached). + * The 'log_2(table_size)' least significant bits of this hashvalue + * give the slot in which the entry will be stored or looked up. + * Each slot can take up to 'as' entries. If a slot is full, an older + * entry is removed by one of the following strategies: + * - oldest entry (the first one in the list) + * - least recently used (the one with the lowest 'last_access') + * - least frequently used (the one with the lowest 'successful_hits') + * or all entries are kept which means that the table grows indefinitely. */ +class remember_table : public std::vector { public: - remember_table(); - remember_table(unsigned s, unsigned as, unsigned strat); - bool lookup_entry(function const & f, ex & result) const; - void add_entry(function const & f, ex const & result); - void clear_all_entries(void); - void show_statistics(ostream & os, unsigned level) const; - static vector & remember_tables(void); + remember_table(); + remember_table(unsigned s, unsigned as, unsigned strat); + bool lookup_entry(function const & f, ex & result) const; + void add_entry(function const & f, ex const & result); + void clear_all_entries(); + void show_statistics(std::ostream & os, unsigned level) const; + static std::vector & remember_tables(); protected: - void init_table(void); - unsigned table_size; - unsigned max_assoc_size; - unsigned remember_strategy; + void init_table(); + unsigned table_size; + unsigned max_assoc_size; + unsigned remember_strategy; }; -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC + +#endif // ndef GINAC_REMEMBER_H