44 #ifndef TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP 45 #define TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP 47 #include "Tpetra_Details_Hash.hpp" 50 #include "Teuchos_Describable.hpp" 51 #include "Kokkos_Core.hpp" 81 template<
class KeyType,
86 typedef typename DeviceType::execution_space execution_space;
87 typedef typename DeviceType::memory_space memory_space;
88 typedef Kokkos::Device<execution_space, memory_space> device_type;
100 typedef typename Kokkos::View<
const offset_type*, Kokkos::LayoutLeft,
101 device_type> ptr_type;
108 typedef typename Kokkos::View<const Kokkos::pair<KeyType, ValueType>*,
109 Kokkos::LayoutLeft, device_type> val_type;
117 KOKKOS_INLINE_FUNCTION
bool hasContiguousValues ()
const {
118 return contiguousValues_;
125 typedef Kokkos::View<const KeyType*, Kokkos::LayoutLeft, device_type>
keys_type;
152 const bool keepKeys =
false);
168 const ValueType startingValue);
185 const ValueType startingValue,
186 const bool keepKeys =
false);
210 const KeyType firstContigKey,
211 const KeyType lastContigKey,
212 const ValueType startingValue,
213 const bool keepKeys =
false);
234 const KeyType firstContigKey,
235 const KeyType lastContigKey,
236 const ValueType startingValue,
237 const bool keepKeys =
false);
251 const Teuchos::ArrayView<const ValueType>& vals);
253 template<
class K,
class V,
class D>
261 template<
class InDeviceType>
263 typename std::enable_if<! std::is_same<DeviceType, InDeviceType>::value,
int>::type* = NULL)
265 using Kokkos::ViewAllocateWithoutInitializing;
266 typedef typename ptr_type::non_const_type nonconst_ptr_type;
267 typedef typename val_type::non_const_type nonconst_val_type;
277 nonconst_ptr_type ptr (ViewAllocateWithoutInitializing (
"ptr"),
278 src.ptr_.dimension_0 ());
280 nonconst_val_type val (ViewAllocateWithoutInitializing (
"val"),
281 src.val_.dimension_0 ());
288 this->minKey_ = src.minKey_;
289 this->maxKey_ = src.maxKey_;
290 this->minVal_ = src.minVal_;
291 this->maxVal_ = src.maxVal_;
292 this->firstContigKey_ = src.firstContigKey_;
293 this->lastContigKey_ = src.lastContigKey_;
294 this->contiguousValues_ = src.contiguousValues_;
295 this->checkedForDuplicateKeys_ = src.checkedForDuplicateKeys_;
296 this->hasDuplicateKeys_ = src.hasDuplicateKeys_;
298 #if defined(HAVE_TPETRA_DEBUG) 300 #endif // defined(HAVE_TPETRA_DEBUG) 304 KOKKOS_INLINE_FUNCTION ValueType
get (
const KeyType& key)
const {
305 const offset_type size = this->getSize ();
314 if (this->hasContiguousValues () &&
315 key >= firstContigKey_ && key <= lastContigKey_) {
316 return static_cast<ValueType
> (key - firstContigKey_) + this->
minVal ();
322 const offset_type start = ptr_[hashVal];
323 const offset_type end = ptr_[hashVal+1];
324 for (offset_type k = start; k < end; ++k) {
325 if (val_[k].first == key) {
326 return val_[k].second;
348 KOKKOS_INLINE_FUNCTION KeyType
getKey (
const ValueType& val)
const {
356 const ValueType index = val - this->
minVal ();
364 KOKKOS_INLINE_FUNCTION offset_type
numPairs ()
const {
370 if (this->hasContiguousValues ()) {
371 return val_.dimension_0 () +
static_cast<offset_type
> (lastContigKey_ - firstContigKey_);
374 return val_.dimension_0 ();
386 KOKKOS_INLINE_FUNCTION KeyType
minKey ()
const {
398 KOKKOS_INLINE_FUNCTION KeyType
maxKey ()
const {
409 KOKKOS_INLINE_FUNCTION ValueType
minVal ()
const {
420 KOKKOS_INLINE_FUNCTION ValueType
maxVal ()
const {
445 describe (Teuchos::FancyOStream &out,
446 const Teuchos::EVerbosityLevel verbLevel=
447 Teuchos::Describable::verbLevel_default)
const;
496 KeyType firstContigKey_;
504 KeyType lastContigKey_;
512 bool contiguousValues_;
519 bool checkedForDuplicateKeys_;
524 bool hasDuplicateKeys_;
530 bool checkForDuplicateKeys ()
const;
533 KOKKOS_INLINE_FUNCTION offset_type getSize ()
const {
534 return ptr_.dimension_0 () == 0 ?
535 static_cast<offset_type
> (0) :
536 static_cast<offset_type> (ptr_.dimension_0 () - 1);
542 typedef Kokkos::View<
const KeyType*,
543 typename ptr_type::HostMirror::array_layout,
544 typename ptr_type::HostMirror::execution_space,
545 Kokkos::MemoryUnmanaged> host_input_keys_type;
547 typedef Kokkos::View<
const ValueType*,
548 typename ptr_type::HostMirror::array_layout,
549 typename ptr_type::HostMirror::execution_space,
550 Kokkos::MemoryUnmanaged> host_input_vals_type;
560 const ValueType startingValue,
563 KeyType firstContigKey,
564 KeyType lastContigKey,
565 const bool computeInitContigKeys);
574 init (
const host_input_keys_type& keys,
575 const host_input_vals_type& vals,
583 #endif // TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP KOKKOS_INLINE_FUNCTION KeyType getKey(const ValueType &val) const
Get the key corresponding to the given value.
KOKKOS_INLINE_FUNCTION offset_type numPairs() const
Number of (key, value) pairs in the table.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
KOKKOS_INLINE_FUNCTION ValueType maxVal() const
The maximum value in the table.
void copyOffsets(const OutputViewType &dst, const InputViewType &src)
Copy row offsets (in a sparse graph or matrix) from src to dst. The offsets may have different types...
Traits class for "invalid" (flag) values of integer types that Tpetra uses as local ordinals or globa...
ResultType result_type
Type of the return value of the hash function.
Declare and define Tpetra::Details::copyOffsets, an implementation detail of Tpetra (in particular...
void deep_copy(MultiVector< DS, DL, DG, DN, dstClassic > &dst, const MultiVector< SS, SL, SG, SN, srcClassic > &src)
Copy the contents of the MultiVector src into dst.
KOKKOS_INLINE_FUNCTION KeyType maxKey() const
The maximum key in the table.
Implementation details of Tpetra.
std::string description() const
Implementation of Teuchos::Describable.
Traits class for "invalid" (flag) values of integer types that Tpetra uses as local ordinals or globa...
The hash function for FixedHashTable.
FixedHashTable(const FixedHashTable< KeyType, ValueType, InDeviceType > &src, typename std::enable_if<! std::is_same< DeviceType, InDeviceType >::value, int >::type *=NULL)
"Copy" constructor that takes a FixedHashTable with the same KeyType and ValueType, but a different DeviceType.
FixedHashTable()
Default constructor; makes an empty table.
bool hasKeys() const
Whether it is safe to call getKey().
OffsetType offset_type
Type of offsets into the hash table's array of (key,value) pairs.
bool hasDuplicateKeys()
Whether the table has any duplicate keys.
static KOKKOS_INLINE_FUNCTION result_type hashFunc(const argument_type &key, const offset_type &size)
The hash function.
KOKKOS_INLINE_FUNCTION ValueType minVal() const
The minimum value in the table.
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.
KOKKOS_INLINE_FUNCTION KeyType minKey() const
The minimum key in the table.
Kokkos::View< const KeyType *, Kokkos::LayoutLeft, device_type > keys_type
Type of a 1-D Kokkos::View (array) used to store keys.