1 | // |
---|
2 | // C++ Interface: HuntLocator |
---|
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_HUNT_LOCATOR_H |
---|
13 | #define ASAP_HUNT_LOCATOR_H |
---|
14 | |
---|
15 | #include "Locator.h" |
---|
16 | |
---|
17 | namespace asap { |
---|
18 | |
---|
19 | /** |
---|
20 | * Implementation of locate operation by bisection search |
---|
21 | * @author TakeshiNakazato |
---|
22 | */ |
---|
23 | template <class T> class HuntLocator : public Locator<T> { |
---|
24 | public: |
---|
25 | // Default constructor. |
---|
26 | HuntLocator(); |
---|
27 | |
---|
28 | // Construct with data |
---|
29 | // @param[in] v pointer to input data. |
---|
30 | // @param[in] n length of the data. |
---|
31 | // @param[in] copystorage whether allocate internal memory or not. |
---|
32 | // @see Locator::set() |
---|
33 | HuntLocator(T *v, unsigned int n, bool copystorage=true); |
---|
34 | |
---|
35 | // Destructor. |
---|
36 | virtual ~HuntLocator(); |
---|
37 | |
---|
38 | // Return right hand side index of location using bisection search |
---|
39 | // plus hunt algorithm. |
---|
40 | // @param[in] x input value to be located. |
---|
41 | // @return location as an index j. |
---|
42 | // @see Locator::locate() |
---|
43 | unsigned int locate(T x); |
---|
44 | private: |
---|
45 | // Hunt algorithm |
---|
46 | // @param[in] x input value to be located. |
---|
47 | // @param[in,out] left input: the starting point for hunt. |
---|
48 | // output: the left index of hunted region. |
---|
49 | // @param[out] right the right index of hunted region. |
---|
50 | void hunt(T x, unsigned int &left, unsigned int &right); |
---|
51 | |
---|
52 | // Storage for previous result. |
---|
53 | unsigned int prev_; |
---|
54 | }; |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | #include "HuntLocator.tcc" |
---|
59 | |
---|
60 | #endif |
---|