MADNESS  version 0.9
uniqueid.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 
32  $Id $
33 */
34 
35 #ifndef MADNESS_WORLD_UNIQUEID_H__INCLUDED
36 #define MADNESS_WORLD_UNIQUEID_H__INCLUDED
37 
38 #include <cstddef>
39 #include <iostream>
41 
42 namespace madness {
43 
44  class World;
45 
46  class uniqueidT {
47  friend class World;
48  private:
49  unsigned long worldid;
50  unsigned long objid;
51 
52  uniqueidT(unsigned long worldid, unsigned long objid)
53  : worldid(worldid), objid(objid) {};
54 
55  public:
57  : worldid(0), objid(0) {};
58 
59  bool operator==(const uniqueidT& other) const {
60  return objid==other.objid && worldid==other.worldid;
61  }
62 
63  std::size_t operator()(const uniqueidT& id) const { // for GNU hash
64  return id.objid;
65  }
66 
67  operator bool() const {
68  return objid!=0;
69  }
70 
71  template <typename Archive>
72  void serialize(Archive& ar) {
73  ar & worldid & objid;
74  }
75 
76  unsigned long get_world_id() const {
77  return worldid;
78  }
79 
80  unsigned long get_obj_id() const {
81  return objid;
82  }
83 
84  friend std::ostream& operator<<(std::ostream& s, const uniqueidT& id) {
85  s << "{" << id.get_world_id() << "," << id.get_obj_id() << "}";
86  return s;
87  }
88  }; // class uniqueidT
89 
90  inline hashT hash_value(const uniqueidT& id) {
91  hashT seed = hash_value(id.get_world_id());
92  detail::combine_hash(seed, hash_value(id.get_obj_id()));
93 
94  return seed;
95  }
96 
97 
98 } // namespace madness
99 
100 
101 #endif // MADNESS_WORLD_UNIQUEID_H__INCLUDED
std::size_t operator()(const uniqueidT &id) const
Definition: uniqueid.h:63
Defines hash functions for use in distributed containers.
Definition: uniqueid.h:46
friend std::ostream & operator<<(std::ostream &s, const uniqueidT &id)
Definition: uniqueid.h:84
unsigned long get_world_id() const
Definition: uniqueid.h:76
uniqueidT()
Definition: uniqueid.h:56
void serialize(Archive &ar)
Definition: uniqueid.h:72
unsigned long get_obj_id() const
Definition: uniqueid.h:80
void combine_hash(hashT &seed, hashT hash)
Internal use only.
Definition: worldhash.h:247
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness::Hash.
Definition: array.h:62
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
std::size_t hashT
The hash value type.
Definition: worldhash.h:148
bool operator==(const uniqueidT &other) const
Definition: uniqueid.h:59
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45