source: trunk/src/BufferedBisectionLocator.tcc@ 2859

Last change on this file since 2859 was 2732, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: Yes/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...

Commit .tcc files for Locator classes.


File size: 1.5 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 {
17template <class T> BufferedBisectionLocator<T>::BufferedBisectionLocator()
18 : Locator<T>(),
19 prev_(0)
20{}
21
22template <class T>
23BufferedBisectionLocator<T>::BufferedBisectionLocator(T *v, unsigned int n,
24 bool copystorage)
25 : Locator<T>(v, n, copystorage),
26 prev_(0)
27{}
28
29template <class T> BufferedBisectionLocator<T>::~BufferedBisectionLocator()
30{}
31
32template <class T> unsigned int BufferedBisectionLocator<T>::locate(T x)
33{
34 if (this->n_ == 1)
35 return 0;
36
37 unsigned int jl = 0;
38 unsigned int ju = this->n_;
39 if (this->ascending_) {
40 // ascending order
41 if (x <= this->x_[0])
42 return 0;
43 else if (x > this->x_[this->n_-1])
44 return this->n_;
45
46 if (x < this->x_[prev_]) {
47 ju = this->bisection(x, jl, prev_);
48 }
49 else {
50 ju = this->bisection(x, prev_, ju);
51 }
52
53 }
54 else {
55 // descending order
56 if (x >= this->x_[0])
57 return 0;
58 else if (x < this->x_[this->n_-1])
59 return this->n_;
60
61 if (x > this->x_[prev_]) {
62 ju = this->bisection(x, jl, prev_);
63 }
64 else {
65 ju = this->bisection(x, prev_, ju);
66 }
67 }
68
69 prev_ = (ju > 0) ? ju - 1 : 0;
70 return ju;
71}
72
73}
Note: See TracBrowser for help on using the repository browser.