opatIO-cpp 0.3.0a
Open Parametrized Array Table
Loading...
Searching...
No Matches
indexVector.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdexcept>
4#include <vector>
5#include <functional>
6
39public:
46
52 FloatIndexVector(const std::vector<double>& vec);
53
61 FloatIndexVector(const std::vector<double>& vec, int hashPrecision);
62
69
76
82 bool operator==(const FloatIndexVector& other) const;
83
89 bool operator!=(const FloatIndexVector& other) const;
90
97 void setHashPrecision(int hashPrecision);
98
104 int getHashPrecision() const;
105
112 void setVector(const std::vector<double>& vec);
113
119 std::vector<double> getVector() const;
120
129 void initialize(const std::vector<double>& vec, int hashPrecision);
130
137 void initialize(const std::vector<double>& vec);
138
144 size_t hash() const;
145
150 void reserve(size_t size) {
151 m_vector.reserve(size);
152 m_vectorInt.reserve(size);
153 }
154
159 int size() const;
160
167 double operator[](const size_t index) const;
168
175 friend std::ostream& operator<<(std::ostream& os, const FloatIndexVector& vec);
176
177private:
197 void setupVecs(const std::vector<double>& vec, int hashPrecision);
198
199 std::vector<double> m_vector;
200 std::vector<uint64_t> m_vectorInt;
202 bool m_initialized = false;
203};
204
211namespace std {
212 template <>
213 struct hash<FloatIndexVector> {
219 size_t operator()(const FloatIndexVector& vec) const {
220 size_t hashValue = vec.hash();
221 return hashValue;
222 }
223 };
224}
Definition indexVector.h:38
friend std::ostream & operator<<(std::ostream &os, const FloatIndexVector &vec)
Overloads the << operator for ostream to print FloatIndexVector.
Definition indexVector.cpp:237
void setupVecs(const std::vector< double > &vec, int hashPrecision)
Sets up the internal representations of the vector and precision.
Definition indexVector.cpp:58
FloatIndexVector & operator=(const FloatIndexVector &other)
Copy assignment operator.
Definition indexVector.cpp:104
int getHashPrecision() const
Gets the current hash precision.
Definition indexVector.cpp:157
std::vector< double > m_vector
The vector of floating-point values.
Definition indexVector.h:199
void setVector(const std::vector< double > &vec)
Sets the vector of floating-point values.
Definition indexVector.cpp:197
size_t hash() const
Computes the hash of the vector.
Definition indexVector.cpp:210
std::vector< uint64_t > m_vectorInt
Internal representation of the vector for hashing, storing scaled integer values.
Definition indexVector.h:200
bool operator!=(const FloatIndexVector &other) const
Inequality operator.
Definition indexVector.cpp:136
void reserve(size_t size)
Reserves memory for the vector and its internal representation.
Definition indexVector.h:150
bool operator==(const FloatIndexVector &other) const
Equality operator.
Definition indexVector.cpp:116
void setHashPrecision(int hashPrecision)
Sets the hash precision.
Definition indexVector.cpp:142
int size() const
Get the size of the index vector.
Definition indexVector.cpp:220
void initialize(const std::vector< double > &vec, int hashPrecision)
Initializes the vector with precision.
Definition indexVector.cpp:166
bool m_initialized
Flag indicating whether the vector and precision have been initialized.
Definition indexVector.h:202
std::vector< double > getVector() const
Gets the current vector of floating-point values.
Definition indexVector.cpp:188
int m_hashPrescision
The precision (number of decimal places) used for rounding and hashing.
Definition indexVector.h:201
FloatIndexVector()
Default constructor.
Definition indexVector.cpp:40
double operator[](const size_t index) const
Access element at a specific index.
Definition indexVector.cpp:227
Specialization of std::hash for FloatIndexVector.
size_t operator()(const FloatIndexVector &vec) const
Computes the hash of a FloatIndexVector.
Definition indexVector.h:219