Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_HashTable_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_HASHTABLE_DECL_HPP
11 #define TPETRA_HASHTABLE_DECL_HPP
12 
13 #include <Teuchos_Describable.hpp>
14 #include "Tpetra_ConfigDefs.hpp"
15 
16 namespace Tpetra {
17 namespace Details {
18 
31 template<typename KeyType, typename ValueType>
32 class HashTable : public Teuchos::Describable {
34  struct Node {
35  KeyType Key;
36  ValueType Value;
37  Node * Ptr;
38 
39  Node (const KeyType key = 0, const ValueType value = 0, Node * ptr = NULL)
40  : Key(key), Value(value), Ptr(ptr) {}
41 
42  private:
43  Node (const Node& src) : Key(src.Key), Value(src.Value), Ptr(src.Ptr) {}
44 
45  Node& operator= (const Node& src) {
46  // We may safely omit the usual check for this == &src.
47  Key = src.Key;
48  Value = src.Value;
49  Ptr = src.Ptr;
50  return *this;
51  }
52  };
53 
54  Node ** Container_;
55  KeyType Size_;
56  unsigned int Seed_;
57 #ifdef HAVE_TPETRA_DEBUG
58  int maxc_; // Max size of the list among all entries w/ collisions. debug only.
59  int nc_; // Number of entries with collisions; use only in debug mode.
60 #endif // HAVE_TPETRA_DEBUG
61 
64  int hashFunc( const KeyType key );
65 
66  int getRecommendedSize( const int size );
67 
68 public:
75  HashTable (const int size, const unsigned int seed = (2654435761U));
76 
77  HashTable (const HashTable& obj);
78  ~HashTable();
79 
81  void add (const KeyType key, const ValueType value);
82 
84  ValueType get (const KeyType key);
85 
87 
88  std::string description() const;
90 
92  void
93  describe (Teuchos::FancyOStream &out,
94  const Teuchos::EVerbosityLevel verbLevel=
95  Teuchos::Describable::verbLevel_default) const;
97 
98 private:
101  operator= (const HashTable<KeyType,ValueType>& source);
102 };
103 
104 } // Details namespace
105 
106 } // Tpetra namespace
107 
108 #endif
HashTable(const int size, const unsigned int seed=(2654435761U))
void add(const KeyType key, const ValueType value)
Add a key and its value to the hash table.
std::string description() const
Implementation of Teuchos::Describable.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity to the output stream.