LevelS C++ support library  3.83
Public Member Functions | List of all members
arr_ref< T > Class Template Reference

#include <arr.h>

Inheritance diagram for arr_ref< T >:
arrT< T, stm > arrT< T, alignAlloc__< T, align > > arrT< T, normalAlloc__< T > > arrT< T, storageManager > arr_align< T, align > arr< T >

Public Member Functions

 arr_ref (T *d_, tsize s_)
 
tsize size () const
 
void fill (const T &val)
 
template<typename T2 >
T & operator[] (T2 n)
 
template<typename T2 >
const T & operator[] (T2 n) const
 
T * begin ()
 
T * end ()
 
const T * begin () const
 
const T * end () const
 
template<typename T2 >
void copyToPtr (T *ptr) const
 
void sort ()
 
template<typename Comp >
void sort (Comp comp)
 
void interpol_helper (const T &val, tsize &idx, double &frac) const
 
template<typename Comp >
void interpol_helper (const T &val, Comp comp, tsize &idx, double &frac) const
 
void minmax (T &minv, T &maxv) const
 
bool contains (const T &val) const
 
tsize find (const T &val) const
 
bool contentsEqual (const arr_ref &other) const
 

Detailed Description

template<typename T>
class arr_ref< T >

View of a 1D array

Definition at line 46 of file arr.h.

Constructor & Destructor Documentation

◆ arr_ref()

template<typename T>
arr_ref< T >::arr_ref ( T *  d_,
tsize  s_ 
)
inline

Constructs an arr_ref of size s_, starting at d_.

Definition at line 54 of file arr.h.

Member Function Documentation

◆ size()

template<typename T>
tsize arr_ref< T >::size ( ) const
inline

Returns the current array size.

Definition at line 57 of file arr.h.

◆ fill()

template<typename T>
void arr_ref< T >::fill ( const T &  val)
inline

Writes val into every element of the array.

Definition at line 60 of file arr.h.

◆ operator[]() [1/2]

template<typename T>
template<typename T2 >
T& arr_ref< T >::operator[] ( T2  n)
inline

Returns a reference to element n

Definition at line 64 of file arr.h.

◆ operator[]() [2/2]

template<typename T>
template<typename T2 >
const T& arr_ref< T >::operator[] ( T2  n) const
inline

Returns a constant reference to element n

Definition at line 66 of file arr.h.

◆ begin() [1/2]

template<typename T>
T* arr_ref< T >::begin ( )
inline

Returns a pointer to the first array element, or NULL if the array is zero-sized.

Definition at line 70 of file arr.h.

◆ end() [1/2]

template<typename T>
T* arr_ref< T >::end ( )
inline

Returns a pointer to the one-past-last array element, or NULL if the array is zero-sized.

Definition at line 73 of file arr.h.

◆ begin() [2/2]

template<typename T>
const T* arr_ref< T >::begin ( ) const
inline

Returns a constant pointer to the first array element, or NULL if the array is zero-sized.

Definition at line 76 of file arr.h.

◆ end() [2/2]

template<typename T>
const T* arr_ref< T >::end ( ) const
inline

Returns a constant pointer to the one-past-last array element, or NULL if the array is zero-sized.

Definition at line 79 of file arr.h.

◆ copyToPtr()

template<typename T>
template<typename T2 >
void arr_ref< T >::copyToPtr ( T *  ptr) const
inline

Copies all array elements to ptr.

Definition at line 82 of file arr.h.

◆ sort() [1/2]

template<typename T>
void arr_ref< T >::sort ( )
inline

Sorts the elements in the array, in ascending order.

Definition at line 86 of file arr.h.

◆ sort() [2/2]

template<typename T>
template<typename Comp >
void arr_ref< T >::sort ( Comp  comp)
inline

Sorts the elements in the array, such that comp(d[i],d[j])==true for i<j.

Definition at line 91 of file arr.h.

◆ interpol_helper() [1/2]

template<typename T>
void arr_ref< T >::interpol_helper ( const T &  val,
tsize idx,
double &  frac 
) const
inline

Helper function for linear interpolation (or extrapolation). idx and val are computed such that val=d[idx]+frac*(d[idx+1]-d[idx]). If val<d[0], frac will be negative, if val>d[s-1], frac will be larger than 1. In all other cases 0<=frac<=1.

The array must be ordered in ascending order; no two values may be equal.

Definition at line 102 of file arr.h.

◆ interpol_helper() [2/2]

template<typename T>
template<typename Comp >
void arr_ref< T >::interpol_helper ( const T &  val,
Comp  comp,
tsize idx,
double &  frac 
) const
inline

Helper function for linear interpolation (or extrapolation). idx and val are computed such that val=d[idx]+frac*(d[idx+1]-d[idx]). If comp(val,d[0])==true, frac will be negative, if comp(val,d[s-1])==false, frac will be larger than 1. In all other cases 0<=frac<=1.

The array must be ordered such that comp(d[i],d[j])==true for i<j; no two values may be equal.

Definition at line 113 of file arr.h.

◆ minmax()

template<typename T>
void arr_ref< T >::minmax ( T &  minv,
T &  maxv 
) const
inline

Returns the minimum and maximum entry in minv and maxv, respectively. Throws an exception if the array is zero-sized.

Definition at line 119 of file arr.h.

◆ contains()

template<typename T>
bool arr_ref< T >::contains ( const T &  val) const
inline

Returns true, if val is found in the array, else false.

Definition at line 131 of file arr.h.

◆ find()

template<typename T>
tsize arr_ref< T >::find ( const T &  val) const
inline

Returns the index of the first occurrence of val in the array. If it is not found, an exception is thrown.

Definition at line 140 of file arr.h.

◆ contentsEqual()

template<typename T>
bool arr_ref< T >::contentsEqual ( const arr_ref< T > &  other) const
inline

Returns true if the array has the same size as other and all elements of both arrays are equal, else false.

Definition at line 149 of file arr.h.


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

Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library