Back to index

texmacs  1.0.7.15
hashfunc.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : hashfunc.hpp
00004 * DESCRIPTION: functions with a memorizing hash table
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef HASHFUNC_H
00013 #define HASHFUNC_H
00014 #include "hashmap.hpp"
00015 
00016 template<class T, class U> class hashfunc_rep: public concrete_struct {
00017   U (*func) (T);          // the function
00018   hashmap<T,U> remember;  // remembered values
00019 public:
00020   inline hashfunc_rep (U (*func2) (T), U init):
00021     func (func2), remember (init) {}
00022   U apply (T x);
00023 };
00024 
00025 template<class T, class U> class hashfunc {
00026   CONCRETE_TEMPLATE_2(hashfunc,T,U);
00027   inline hashfunc (U (*func) (T), U init):
00028     rep (tm_new<hashfunc_rep<T,U> > (func, init)) {}
00029   inline U operator [] (T x) { return rep->apply (x); }
00030   operator tree ();
00031 };
00032 CONCRETE_TEMPLATE_2_CODE(hashfunc,class,T,class,U);
00033 
00034 #include "hashfunc.cpp"
00035 
00036 #endif // defined HASHFUNC_H