opatIO-cpp 0.3.0a
Open Parametrized Array Table
Loading...
Searching...
No Matches
FloatIndexVector Class Reference

#include <indexVector.h>

Public Member Functions

 FloatIndexVector ()
 Default constructor.
 
 FloatIndexVector (const std::vector< double > &vec)
 Constructor with vector initialization.
 
 FloatIndexVector (const std::vector< double > &vec, int hashPrecision)
 Constructor with vector and precision initialization.
 
 FloatIndexVector (const FloatIndexVector &other)
 Copy constructor.
 
FloatIndexVectoroperator= (const FloatIndexVector &other)
 Copy assignment operator.
 
bool operator== (const FloatIndexVector &other) const
 Equality operator.
 
bool operator!= (const FloatIndexVector &other) const
 Inequality operator.
 
void setHashPrecision (int hashPrecision)
 Sets the hash precision.
 
int getHashPrecision () const
 Gets the current hash precision.
 
void setVector (const std::vector< double > &vec)
 Sets the vector of floating-point values.
 
std::vector< double > getVector () const
 Gets the current vector of floating-point values.
 
void initialize (const std::vector< double > &vec, int hashPrecision)
 Initializes the vector with precision.
 
void initialize (const std::vector< double > &vec)
 Initializes the vector without precision.
 
size_t hash () const
 Computes the hash of the vector.
 
void reserve (size_t size)
 Reserves memory for the vector and its internal representation.
 
int size () const
 Get the size of the index vector.
 
double operator[] (const size_t index) const
 Access element at a specific index.
 

Private Member Functions

void setupVecs (const std::vector< double > &vec, int hashPrecision)
 Sets up the internal representations of the vector and precision.
 

Private Attributes

std::vector< double > m_vector
 The vector of floating-point values.
 
std::vector< uint64_t > m_vectorInt
 Internal representation of the vector for hashing, storing scaled integer values.
 
int m_hashPrescision
 The precision (number of decimal places) used for rounding and hashing.
 
bool m_initialized = false
 Flag indicating whether the vector and precision have been initialized.
 

Friends

std::ostream & operator<< (std::ostream &os, const FloatIndexVector &vec)
 Overloads the << operator for ostream to print FloatIndexVector.
 

Detailed Description

Constructor & Destructor Documentation

◆ FloatIndexVector() [1/4]

FloatIndexVector::FloatIndexVector ( )

Default constructor.

Initializes an empty FloatIndexVector.

◆ FloatIndexVector() [2/4]

FloatIndexVector::FloatIndexVector ( const std::vector< double > & vec)

Constructor with vector initialization.

Parameters
vecThe vector of floating-point values to initialize with.
Exceptions
std::invalid_argumentif the input vector is empty.

◆ FloatIndexVector() [3/4]

FloatIndexVector::FloatIndexVector ( const std::vector< double > & vec,
int hashPrecision )

Constructor with vector and precision initialization.

Parameters
vecThe vector of floating-point values to initialize with.
hashPrecisionThe precision to use for hashing.
Exceptions
std::invalid_argumentif the input vector is empty.
std::invalid_argumentif hashPrescision is not a positive integer or is >= 14.

◆ FloatIndexVector() [4/4]

FloatIndexVector::FloatIndexVector ( const FloatIndexVector & other)

Copy constructor.

Parameters
otherThe FloatIndexVector to copy from.
Exceptions
std::invalid_argumentif the input vector in the other object is empty.

Member Function Documentation

◆ getHashPrecision()

int FloatIndexVector::getHashPrecision ( ) const

Gets the current hash precision.

Returns
The current hash precision.
Exceptions
std::runtime_errorif the object is not initialized.

◆ getVector()

std::vector< double > FloatIndexVector::getVector ( ) const

Gets the current vector of floating-point values.

Returns
The current vector.
Exceptions
std::runtime_errorif the object is not initialized.

◆ hash()

size_t FloatIndexVector::hash ( ) const

Computes the hash of the vector.

Returns
The hash value of the vector.
Exceptions
std::runtime_errorif the object is not initialized.

◆ initialize() [1/2]

void FloatIndexVector::initialize ( const std::vector< double > & vec)

Initializes the vector without precision.

Parameters
vecThe vector of floating-point values to initialize with.
Exceptions
std::runtime_errorif the object is already initialized.
std::invalid_argumentif the input vector is empty.

◆ initialize() [2/2]

void FloatIndexVector::initialize ( const std::vector< double > & vec,
int hashPrecision )

Initializes the vector with precision.

Parameters
vecThe vector of floating-point values to initialize with.
hashPrecisionThe precision to use for hashing.
Exceptions
std::runtime_errorif the object is already initialized.
std::invalid_argumentif the input vector is empty.
std::invalid_argumentif hashPrescision is not a positive integer or is >= 14.

◆ operator!=()

bool FloatIndexVector::operator!= ( const FloatIndexVector & other) const

Inequality operator.

Parameters
otherThe FloatIndexVector to compare with.
Returns
True if the vectors are not equal, false otherwise.

◆ operator=()

FloatIndexVector & FloatIndexVector::operator= ( const FloatIndexVector & other)

Copy assignment operator.

Parameters
otherThe FloatIndexVector to copy from.
Returns
Reference to the assigned FloatIndexVector.

◆ operator==()

bool FloatIndexVector::operator== ( const FloatIndexVector & other) const

Equality operator.

Parameters
otherThe FloatIndexVector to compare with.
Returns
True if the vectors are equal, false otherwise.

◆ operator[]()

double FloatIndexVector::operator[] ( const size_t index) const

Access element at a specific index.

Parameters
indexThe index of the element to access.
Returns
The value at the specified index.
Exceptions
std::out_of_rangeif the index is out of bounds.

◆ reserve()

void FloatIndexVector::reserve ( size_t size)
inline

Reserves memory for the vector and its internal representation.

Parameters
sizeThe number of elements to reserve.

◆ setHashPrecision()

void FloatIndexVector::setHashPrecision ( int hashPrecision)

Sets the hash precision.

Parameters
hashPrecisionThe precision to use for hashing.
Exceptions
std::runtime_errorif the object is already initialized.
std::invalid_argumentif hashPrescision is not a positive integer or is >= 14.

◆ setupVecs()

void FloatIndexVector::setupVecs ( const std::vector< double > & vec,
int hashPrecision )
private

Sets up the internal representations of the vector and precision.

This method initializes the internal vector representations (m_vector and m_vectorInt) based on the provided floating-point vector and hash precision. It converts the floating-point values into integer representations for consistent hashing.

Parameters
vecThe vector of floating-point values to initialize with.
hashPrecisionThe precision to use for hashing. Values are rounded to this precision.
Exceptions
std::invalid_argumentif the input vector is empty.
std::invalid_argumentif hashPrescision is not a positive integer or is >= 14.

Example Usage:

std::vector<double> vec = {1.2345, 2.3456, 3.4567};
index.setupVecs(vec, 2); // Sets up the vector with precision of 2 decimal places
Definition indexVector.h:38
void setupVecs(const std::vector< double > &vec, int hashPrecision)
Sets up the internal representations of the vector and precision.
Definition indexVector.cpp:58

◆ setVector()

void FloatIndexVector::setVector ( const std::vector< double > & vec)

Sets the vector of floating-point values.

Parameters
vecThe vector to set.
Exceptions
std::runtime_errorif the object is already initialized.
std::invalid_argumentif the input vector is empty.

◆ size()

int FloatIndexVector::size ( ) const

Get the size of the index vector.

Returns
size The dimension / size of the index vector

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const FloatIndexVector & vec )
friend

Overloads the << operator for ostream to print FloatIndexVector.

Parameters
osThe output stream.
vecThe FloatIndexVector to print.
Returns
Reference to the output stream.

Member Data Documentation

◆ m_hashPrescision

int FloatIndexVector::m_hashPrescision
private

The precision (number of decimal places) used for rounding and hashing.

◆ m_initialized

bool FloatIndexVector::m_initialized = false
private

Flag indicating whether the vector and precision have been initialized.

◆ m_vector

std::vector<double> FloatIndexVector::m_vector
private

The vector of floating-point values.

◆ m_vectorInt

std::vector<uint64_t> FloatIndexVector::m_vectorInt
private

Internal representation of the vector for hashing, storing scaled integer values.


The documentation for this class was generated from the following files: