X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fwildcard.cpp;h=d45ffca038ab5ff98505464b4f5c70318f7d615f;hp=a0d593493558a2e17bc99d209269a64d96778eda;hb=ed914545e01d60ecf2544e6141d6c5142c01327f;hpb=488cad4c124885230154720041bd51fa4d983a8b diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index a0d59349..d45ffca0 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's wildcard objects. */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2016 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 @@ -17,15 +17,15 @@ * * 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 "wildcard.h" -#include "print.h" #include "archive.h" #include "utils.h" +#include "hash_seed.h" + +#include namespace GiNaC { @@ -38,7 +38,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic, // default constructor ////////// -wildcard::wildcard() : inherited(TINFO_wildcard), label(0) +wildcard::wildcard() : label(0) { setflag(status_flags::evaluated | status_flags::expanded); } @@ -47,7 +47,7 @@ wildcard::wildcard() : inherited(TINFO_wildcard), label(0) // other constructors ////////// -wildcard::wildcard(unsigned l) : inherited(TINFO_wildcard), label(l) +wildcard::wildcard(unsigned l) : label(l) { setflag(status_flags::evaluated | status_flags::expanded); } @@ -56,11 +56,13 @@ wildcard::wildcard(unsigned l) : inherited(TINFO_wildcard), label(l) // archiving ////////// -wildcard::wildcard(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst) +void wildcard::read_archive(const archive_node& n, lst& sym_lst) { + inherited::read_archive(n, sym_lst); n.find_unsigned("label", label); setflag(status_flags::evaluated | status_flags::expanded); } +GINAC_BIND_UNARCHIVER(wildcard); void wildcard::archive(archive_node &n) const { @@ -68,8 +70,6 @@ void wildcard::archive(archive_node &n) const n.add_unsigned("label", label); } -DEFAULT_UNARCHIVE(wildcard) - ////////// // functions overriding virtual functions from base classes ////////// @@ -92,7 +92,7 @@ void wildcard::do_print(const print_context & c, unsigned level) const void wildcard::do_print_tree(const print_tree & c, unsigned level) const { - c.s << std::string(level, ' ') << class_name() << " (" << label << ")" + c.s << std::string(level, ' ') << class_name() << "(" << label << ")" << " @" << this << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; } @@ -105,14 +105,15 @@ void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level) unsigned wildcard::calchash() const { // this is where the schoolbook method - // (golden_ratio_hash(tinfo()) ^ label) + // (golden_ratio_hash(typeid(*this).name()) ^ label) // is not good enough yet... - hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label); + unsigned seed = make_hash_seed(typeid(*this)); + hashvalue = golden_ratio_hash(seed ^ label); setflag(status_flags::hash_calculated); return hashvalue; } -bool wildcard::match(const ex & pattern, lst & repl_lst) const +bool wildcard::match(const ex & pattern, exmap& repl_lst) const { // Wildcards must match each other exactly (this is required for // subs() to work properly because in the final step it substitutes @@ -120,4 +121,14 @@ bool wildcard::match(const ex & pattern, lst & repl_lst) const return is_equal(ex_to(pattern)); } +bool haswild(const ex & x) +{ + if (is_a(x)) + return true; + for (size_t i=0; i