source: trunk/src/BufferedBisectionLocator.cpp@ 2730

Last change on this file since 2730 was 2730, checked in by Takeshi Nakazato, 12 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: 1.3 KB
Line 
1//
2// C++ Implementation: BufferedBisectionLocator
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#include <assert.h>
13
14#include "BufferedBisectionLocator.h"
15
16namespace asap {
17BufferedBisectionLocator::BufferedBisectionLocator()
18 : Locator(),
19 prev_(0)
20{}
21
22BufferedBisectionLocator::BufferedBisectionLocator(double *v, unsigned int n,
23 bool copystorage)
24 : Locator(v, n, copystorage),
25 prev_(0)
26{}
27
28BufferedBisectionLocator::~BufferedBisectionLocator()
29{}
30
31unsigned int BufferedBisectionLocator::locate(double x)
32{
33 if (n_ == 1)
34 return 0;
35
36 unsigned int jl = 0;
37 unsigned int ju = n_;
38 if (ascending_) {
39 // ascending order
40 if (x <= x_[0])
41 return 0;
42 else if (x > x_[n_-1])
43 return n_;
44
45 if (x < x_[prev_]) {
46 ju = bisection(x, jl, prev_);
47 }
48 else {
49 ju = bisection(x, prev_, ju);
50 }
51
52 }
53 else {
54 // descending order
55 if (x >= x_[0])
56 return 0;
57 else if (x < x_[n_-1])
58 return n_;
59
60 if (x > x_[prev_]) {
61 ju = bisection(x, jl, prev_);
62 }
63 else {
64 ju = bisection(x, prev_, ju);
65 }
66 }
67
68 prev_ = (ju > 0) ? ju - 1 : 0;
69 return ju;
70}
71
72}
Note: See TracBrowser for help on using the repository browser.