Changeset 2730 for trunk/src/Locator.h
- Timestamp:
- 01/16/13 16:00:28 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Locator.h
r2727 r2730 21 21 class Locator { 22 22 public: 23 Locator() {;} 24 Locator(double *v, unsigned int n); 25 void set(double *v, unsigned int n); 23 // Default constructor. 24 Locator(); 25 26 // Construct with data. 27 // @param[in] v pointer to input data. 28 // @param[in] n length of the data. 29 // @param[in] copystorage whether allocate internal memory or not. 30 // @see set() 31 Locator(double *v, unsigned int n, bool copystorage=true); 26 32 33 // Set data. The data must be sorted in either ascending or descending 34 // order, and must not have any duplicate elements. 35 // @param[in] v pointer to input data. 36 // @param[in] n length of the data. 37 // @param[in] copystorage whether allocate internal memory or not. 38 // 39 // Setting copystorage=false is bit faster since it directly points 40 // to the input array instead to allocate memory and copy input array. 41 // However, you have to be careful to set copystorage to false since 42 // it will take a risk to allow to edit the data to be searched from 43 // outside the class. 44 void set(double *v, unsigned int n, bool copystorage=true); 45 46 // Destructor. 27 47 virtual ~Locator(); 28 48 29 // return right hand side index of location 30 // (return j+1 if x[j] < x <= x[j+1]) 31 // return value 0 or x.nelements() indicates out of range 49 // Return right hand side index of location. 50 // @param[in] x input value to be located. 51 // @return location as an index j. 52 // 53 // Returned index j satisfies x_[j-1] < x <= x_[j] for ascending 54 // case while x_[j-1] > x >= x_[j] for descending case. 55 // Returned value 0 or x.nelements() indicates out of range. 32 56 virtual unsigned int locate(double x) = 0; 33 57 34 58 protected: 59 // Bisection search. 60 // @param[in] x input value to be located. 61 // @param[in] left the leftmost index to search. 62 // @param[in] right the rightmost index to search. 63 unsigned int bisection(double x, unsigned int left, unsigned int right); 64 65 // Hunt algorithm 66 // @param[in] x input value to be located. 67 // @param[in,out] left input: the starting point for hunt. 68 // output: the left index of hunted region. 69 // @param[out] right the right index of hunted region. 70 void hunt(double x, unsigned int &left, unsigned int &right); 71 72 // Pointer to the data. 35 73 double *x_; 74 75 // Length of the data. 36 76 unsigned int n_; 77 78 // Is data ascending or descending? 79 bool ascending_; 80 81 // Is internal storage allocated? 82 bool copy_; 37 83 }; 38 84
Note: See TracChangeset
for help on using the changeset viewer.