Loading [MathJax]/extensions/MathZoom.js
Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
search.h
Go to the documentation of this file.
1#ifndef SEARCH_H
2#define SEARCH_H
3
4#include "dolphin/os.h"
5#include <iterator.h>
6#include <functional.h>
7#include <algorithm.h>
8
9namespace JGadget {
10
11namespace search {
12
13template <typename T>
15
16template <>
18 static s32 get(s32 n) { return n << 3; }
19};
20
21} // namespace search
22
26template <typename T>
27inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& fallback) {
28 JUT_ASSERT(200, pValue!=0);
29 u32 index = idx;
30 if (index >= count) {
31 return fallback;
32 } else {
33 return pValue[index];
34 }
35}
36
37template <typename Category, typename T, typename Distance, typename Pointer, typename Reference>
38struct TIterator : public std::iterator<Category, T, Distance, Pointer, Reference> {
39};
40
41template <typename Iterator, typename T, typename Predicate>
42inline Iterator findUpperBound_binary_all(Iterator first, Iterator last, const T& val, Predicate p) {
43 return std::upper_bound(first, last, val, p);
44}
45
46template <typename Iterator, typename T, typename Predicate>
47inline Iterator findUpperBound_binary_begin(Iterator first, Iterator last, const T& val, Predicate p) {
48 if (first == last) {
49 return last;
50 }
51
52 typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
53 difference_type dist = std::distance(first, last);
54 difference_type stride = 1;
56 Iterator i = first;
57
58 while (true) {
59 if (p(val, *i)) {
60 if (stride == 1) {
61 return i;
62 } else {
63 break;
64 }
65 }
66 first = i;
67 dist -= stride;
68 if (dist <= 0) {
69 i = last;
70 break;
71 }
72 i += stride;
73 stride = expand.get(stride);
74 }
75
76 return findUpperBound_binary_all(first, i, val, p);
77}
78
79template <typename Iterator, typename T, typename Predicate>
80inline Iterator findUpperBound_binary_end(Iterator first, Iterator last, const T& val, Predicate p) {
81 if (first == last) {
82 return last;
83 }
84
85 typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
86 --last;
87 difference_type dist = std::distance(first, last);
88 difference_type stride = 1;
90 Iterator i = last;
91
92 while (true) {
93 if (!p(val, *i)) {
94 if (stride == 1) {
95 return ++i;
96 } else {
97 break;
98 }
99 }
100 last = i;
101 dist -= stride;
102 if (dist <= 0) {
103 i = first;
104 break;
105 }
106 i -= stride;
107 stride = expand.get(stride);
108 }
109
110 return findUpperBound_binary_all(i, ++last, val, p);
111}
112
113template <typename Iterator, typename T, typename Predicate>
114Iterator findUpperBound_binary_current(Iterator first, Iterator last, Iterator current, const T& val, Predicate p) {
115 return current == last || p(val, *current) ?
116 findUpperBound_binary_end(first, current, val, p) :
117 findUpperBound_binary_begin(current, last, val, p);
118}
119
120template <typename Iterator, typename T>
121Iterator findUpperBound_binary_current(Iterator first, Iterator last, Iterator current, const T& val) {
122 return findUpperBound_binary_current(first, last, current, val, std::less<T>());
123}
124
125} // namespace JGadget
126
127#endif /* SEARCH_H */
static u8 index[20][3]
Definition GXDraw.c:434
static void * search(void *param_1, void *param_2)
Definition d_a_tag_qs.cpp:119
p
Definition e_acos.c:98
n
Definition e_fmod.c:112
int i
Definition e_pow.c:165
Definition binary.h:6
const T & toValueFromIndex(int idx, const T *pValue, u32 count, const T &fallback)
Definition search.h:27
Iterator findUpperBound_binary_begin(Iterator first, Iterator last, const T &val, Predicate p)
Definition search.h:47
Iterator findUpperBound_binary_end(Iterator first, Iterator last, const T &val, Predicate p)
Definition search.h:80
Iterator findUpperBound_binary_current(Iterator first, Iterator last, Iterator current, const T &val, Predicate p)
Definition search.h:114
Iterator findUpperBound_binary_all(Iterator first, Iterator last, const T &val, Predicate p)
Definition search.h:42
iterator_traits< InputIterator >::difference_type distance(InputIterator first, InputIterator last)
Definition iterator.h:96
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T &val, Predicate p)
Definition algorithm.h:56
Definition search.h:38
static s32 get(s32 n)
Definition search.h:18
Definition search.h:14
Iterator::difference_type difference_type
Definition iterator.h:15
Definition iterator.h:37
Definition functional.h:16
unsigned long u32
Definition types.h:9
signed long s32
Definition types.h:8