source: trunk/src/Locator.h @ 2730

Last change on this file since 2730 was 2730, checked in by Takeshi Nakazato, 11 years ago

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Rewrite implementations for locator and interpolator.
Documentation (doxygen format) is added to header files.


File size: 2.4 KB
Line 
1//
2// C++ Interface: Locator
3//
4// Description:
5//
6//
7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAP_LOCATOR_H
13#define ASAP_LOCATOR_H
14
15namespace asap {
16
17/**
18 * Base class for locate operation
19 * @author TakeshiNakazato
20 */
21class Locator {
22public:
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);
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.
47  virtual ~Locator();
48
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.
56  virtual unsigned int locate(double x) = 0;
57
58protected:
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.
73  double *x_;
74
75  // Length of the data.
76  unsigned int n_;
77
78  // Is data ascending or descending?
79  bool ascending_;
80
81  // Is internal storage allocated?
82  bool copy_;
83};
84
85}
86#endif
Note: See TracBrowser for help on using the repository browser.