Array Functions¶
Array Functions is the name given to some various support functions defined on the standard std::vector<T> type – I have termed them “Array Functions” to prevent name collisions with the JSL::Vector objects.
Locator Functions¶
-
template<class
T>
inline intJSL::FindXInY(T x, const std::vector<T> &y)¶ Gets first id such that y[id] == x, assuming that exact equality is well defined (see double override). If no such id exists, returns negative value.
- Parameters:
x – The value to be searched for
y – The vector to search through
- Returns:
The index of the first element in the array which matches x. Value is negative if no match found
-
inline int
JSL::FindXInY(double x, const std::vector<double> &y, double tolerance)¶ Gets first id such that (y[id]- x)/x < tolerance. If no such id exists, returns negative value.
- Parameters:
x – The value to be searched for
y – The vector to search through
tolerance – The fractional difference permitted between two double values for them to be declared “approximately equal”
- Returns:
The index of the first element in the array which matches x. Value is negative if no match found
-
inline int
JSL::UpperBoundLocator(double val, const std::vector<double> &valArray)¶ Similar to FindXInY except where you do not expect an exact match. Searches through an (assumed sorted) vector and locates the first value greater than or equal to the target value, else returns the index of the final value in the array.
Sort Functions¶
-
template<typename
T>
inline std::vector<size_t>JSL::SortIndices(const std::vector<T> &v)¶ Returns the sorted index array associated with a vector - not the sorted array itself
- Parameters:
v – A vector of objects where the less than operator is defined
- Returns:
a sorted index-vector y such that v[y[0]] is the smallest value in the array, v[y[1]] is the next, and so on.