MADNESS  version 0.9
simplecache.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id$
32 */
33 #ifndef MADNESS_MRA_SIMPLECACHE_H__INCLUDED
34 #define MADNESS_MRA_SIMPLECACHE_H__INCLUDED
35 
36 #include <madness/mra/key.h>
37 
38 namespace madness {
40 
44  template <typename Q, std::size_t NDIM>
45  class SimpleCache {
46  private:
48  typedef std::pair<Key<NDIM>, Q> pairT;
49  mapT cache;
50 
51  public:
52  SimpleCache() : cache() {};
53 
54  SimpleCache(const SimpleCache& c) : cache(c.cache) {};
55 
57  if (this != &c) {
58  cache.clear();
59  cache = c.cache;
60  }
61  return *this;
62  }
63 
65  inline const Q* getptr(const Key<NDIM>& key) const {
66  typename mapT::const_iterator test = cache.find(key);
67  if (test == cache.end()) return 0;
68  return &(test->second);
69  }
70 
71 
73 
75  inline const Q* getptr(Level n, Translation l) const {
77  return getptr(key);
78  }
79 
80 
82 
84  inline const Q* getptr(Level n, const Key<NDIM>& disp) const {
85  Key<NDIM> key(n,disp.translation());
86  return getptr(key);
87  }
88 
89 
91  inline void set(const Key<NDIM>& key, const Q& val) {
92  cache.insert(pairT(key,val));
93  }
94 
95  inline void set(Level n, Translation l, const Q& val) {
97  set(key, val);
98  }
99 
100  inline void set(Level n, const Key<NDIM>& disp, const Q& val) {
101  Key<NDIM> key(n,disp.translation());
102  set(key, val);
103  }
104  };
105 }
106 #endif // MADNESS_MRA_SIMPLECACHE_H__INCLUDED
iterator for hash
Definition: worldhashmap.h:190
const Vector< Translation, NDIM > & translation() const
Definition: key.h:225
void set(Level n, Translation l, const Q &val)
Definition: simplecache.h:95
iterator end()
Definition: worldhashmap.h:579
void clear()
Definition: worldhashmap.h:556
const Q * getptr(Level n, const Key< NDIM > &disp) const
If key=(n,l) is present return pointer to cached value, otherwise return NULL.
Definition: simplecache.h:84
Definition: worldhashmap.h:57
const Q * getptr(Level n, Translation l) const
If key=(n,l) is present return pointer to cached value, otherwise return NULL.
Definition: simplecache.h:75
Simplified interface around hash_map to cache stuff for 1D.
Definition: simplecache.h:45
const Q * getptr(const Key< NDIM > &key) const
If key is present return pointer to cached value, otherwise return NULL.
Definition: simplecache.h:65
std::pair< iterator, bool > insert(const datumT &datum)
Definition: worldhashmap.h:469
SimpleCache & operator=(const SimpleCache &c)
Definition: simplecache.h:56
int Level
Definition: key.h:58
void test(World &world, bool doloadbal=false)
Definition: dataloadbal.cc:225
SimpleCache()
Definition: simplecache.h:52
void set(const Key< NDIM > &key, const Q &val)
Set value associated with key ... gives ownership of a new copy to the container. ...
Definition: simplecache.h:91
void set(Level n, const Key< NDIM > &disp, const Q &val)
Definition: simplecache.h:100
Multidimension Key for MRA tree and associated iterators.
SimpleCache(const SimpleCache &c)
Definition: simplecache.h:54
int64_t Translation
Definition: key.h:57
iterator find(const keyT &key)
Definition: worldhashmap.h:524
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69