Changeset 2730 for trunk/src/HuntLocator.cpp
- Timestamp:
- 01/16/13 16:00:28 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/HuntLocator.cpp
r2727 r2730 16 16 namespace asap { 17 17 18 HuntLocator::HuntLocator(double *v, unsigned int n) 19 : Locator(v, n), 18 HuntLocator::HuntLocator() 19 : Locator(), 20 prev_(0) 21 {} 22 23 HuntLocator::HuntLocator(double *v, unsigned int n, bool copystorage) 24 : Locator(v, n, copystorage), 20 25 prev_(0) 21 26 {} … … 28 33 if (n_ == 1) 29 34 return 0; 30 bool ascending = (x_[n_-1] >= x_[0]); 31 if (ascending ) {35 36 if (ascending_) { 32 37 if (x <= x_[0]) 33 38 return 0; … … 44 49 unsigned int jl = 0; 45 50 unsigned int ju = n_; 51 52 // hunt phase 46 53 if (prev_ > 0 && prev_ < n_) { 47 // do hunt48 54 jl = prev_; 49 unsigned int inc = 1; 50 if ((x >= x_[jl]) == ascending) { 51 // hunt up 52 if (jl >= n_ - 1) 53 return jl; 54 ju = jl + inc; 55 while ((x >= x_[ju]) == ascending) { 56 jl = ju; 57 inc <<= 1; 58 ju = jl + inc; 59 if (ju > n_ - 1) { 60 ju = n_; 61 break; 62 } 63 } 64 } 65 else { 66 // hunt down 67 if (jl == 0) 68 return jl; 69 ju = jl; 70 jl -= inc; 71 while ((x < x_[jl]) == ascending) { 72 ju = jl; 73 inc <<= 1; 74 if (inc >= ju) { 75 jl = 0; 76 break; 77 } 78 else 79 jl = ju - inc; 80 } 81 } 55 hunt(x, jl, ju); 82 56 } 83 57 84 58 // final bisection phase 85 unsigned int jm; 86 if (ascending) { 87 while (ju - jl > 1) { 88 jm = (ju + jl) >> 1; 89 if (x > x_[jm]) 90 jl = jm; 91 else 92 ju = jm; 93 } 94 } 95 else { 96 while (ju - jl > 1) { 97 jm = (ju + jl) >> 1; 98 if (x < x_[jm]) 99 jl = jm; 100 else 101 ju = jm; 102 } 103 } 104 prev_ = jl; 105 return ju; 59 unsigned int j = bisection(x, jl, ju); 60 prev_ = (j > 0) ? j - 1 : 0; 61 return j; 106 62 } 107 63
Note: See TracChangeset
for help on using the changeset viewer.