elem_hash.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_ELEM_HASH_H
19 #define LIBMESH_ELEM_HASH_H
20 
21 #include "elem.h"
22 #include LIBMESH_INCLUDE_UNORDERED_MAP
23 #include LIBMESH_INCLUDE_UNORDERED_SET
24 
25 // This header defines some typedefs that are useful for working with
26 // "unordered" containers of Elem * that use Elem::key() as a hash
27 // function.
28 namespace libMesh
29 {
30 
46 {
47 public:
48  // The "Hash" template argument. A custom hash functor that can be
49  // used with the "unordered" container types. Simply returns
50  // elem->key() as the hash.
51  inline
52  std::size_t operator()(const Elem * elem) const
53  {
54  return cast_int<std::size_t>(elem->key());
55  }
56 
57  // The "Pred" template argument. A binary predicate that takes two
58  // arguments of the same type as the elements and returns a bool.
59  // We need to specify this in order to use the unordered_multiset,
60  // otherwise it just uses std::equal_to to compare two pointers...
61  inline
62  bool operator()(const Elem * lhs, const Elem * rhs) const
63  {
64  return lhs->key() == rhs->key();
65  }
66 };
67 
68 // A convenient type for working with unordered_multiset<Elem *>
69 typedef LIBMESH_BEST_UNORDERED_MULTISET<Elem *, ElemHashUtils, ElemHashUtils> unordered_multiset_elem;
70 
71 }
72 
73 #endif
A struct providing convenience functions for hashing elements.
Definition: elem_hash.h:45
The base class for all geometric element types.
Definition: elem.h:86
std::size_t operator()(const Elem *elem) const
Definition: elem_hash.h:52
bool operator()(const Elem *lhs, const Elem *rhs) const
Definition: elem_hash.h:62
LIBMESH_BEST_UNORDERED_MULTISET< Elem *, ElemHashUtils, ElemHashUtils > unordered_multiset_elem
Definition: elem_hash.h:69
virtual dof_id_type key(const unsigned int s) const =0