DFT-EFE
 
Loading...
Searching...
No Matches
OptimizedIndexSet.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Bikash Kanungo
24 */
25#ifndef dftefeOptimizedIndexSet_h
26#define dftefeOptimizedIndexSet_h
27
28#include <utils/TypeConfig.h>
29#include <set>
30#include <vector>
31namespace dftefe
32{
33 namespace utils
34 {
35 /*
36 * @brief Class to create an optimized index set which
37 * creates contiguous sub-ranges within an index set for faster
38 * search operation. This is useful when the number of contiguous sub-ranges
39 * are fewer compared to the size of the index set. If the number of
40 * contiguous sub-ranges competes with the size of the index set (i.e., the
41 * index set is very random) then it default to the behavior of an std::set.
42 *
43 * @tparam ValueType The data type of the indices (e.g., unsigned int, unsigned long int)
44 */
45
46 template <typename T>
48 {
49 public:
56 OptimizedIndexSet(const std::set<T> &inputSet = std::set<T>());
57 ~OptimizedIndexSet() = default;
58
59 void
60 getPosition(const T &index, size_type &pos, bool &found) const;
61
62 bool
64
65 bool
66 operator==(const OptimizedIndexSet<T> &rhs) const;
67
68 const std::vector<T> &
69 getContiguousRanges() const;
70
71 private:
74
75 /*
76 * Vector of size 2*(d_numContiguousRanges in d_set).
77 * The entries are arranged as:
78 * <contiguous range1 startId> <continguous range1 endId> <contiguous
79 * range2 startId> <continguous range2 endId> ... NOTE: The endId is one
80 * past the lastId in the continguous range
81 */
82 std::vector<T> d_contiguousRanges;
83
86 std::vector<size_type> d_numEntriesBefore;
87 };
88
89 } // end of namespace utils
90
91} // end of namespace dftefe
93#endif // dftefeOptimizedSet_h
Definition: OptimizedIndexSet.h:48
bool operator==(const OptimizedIndexSet< T > &rhs) const
Definition: OptimizedIndexSet.t.cpp:130
bool getPosition(const OptimizedIndexSet< T > &rhs) const
size_type d_numContiguousRanges
Store the number of contiguous ranges in the input set of indices.
Definition: OptimizedIndexSet.h:73
std::vector< size_type > d_numEntriesBefore
Definition: OptimizedIndexSet.h:86
void getPosition(const T &index, size_type &pos, bool &found) const
Definition: OptimizedIndexSet.t.cpp:84
const std::vector< T > & getContiguousRanges() const
Definition: OptimizedIndexSet.t.cpp:140
std::vector< T > d_contiguousRanges
Definition: OptimizedIndexSet.h:82
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
unsigned int size_type
Definition: TypeConfig.h:8