CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
algorithms.h
1
2#ifndef _algorithms_h_
3#define _algorithms_h_
4
5#include "system/shared_ptr.h"
6#include "system/collections/icomparer.h"
7
8namespace System {
9namespace Collections {
10namespace Generic {
11
22template<template<typename, typename> class containterT, class T, class Allocator>
23int _net_binnary_search(const containterT<T, Allocator> &container, int index, int count, T value, const SharedPtr<System::Collections::Generic::IComparer<T> >& comparer)
24{
25 int s = index;
26 int f = index + count - 1;
27 int c, m;
28
29 while (s <= f)
30 {
31 m = s + ((f - s) / 2);
32 c = comparer->Compare(value, container[m]);
33
34 if (c < 0) {
35 f = m - 1;
36 }
37 else if (c > 0) {
38 s = m + 1;
39 }
40 else {
41 return m;
42 }
43 }
44
45 return ~s;
46}
47
57template<template<typename, typename> class containterT, class T, class Allocator>
58typename std::enable_if<IsSmartPtr<T>::value, int>::type _net_binnary_search(const containterT<T, Allocator> &container, int index, int count, T value)
59{
60 int s = index;
61 int f = index + count - 1;
62 int c, m;
63
64 while (s <= f)
65 {
66 m = s + ((f - s) / 2);
67 c = value->CompareTo(container[m]);
68
69 if (c < 0) {
70 f = m - 1;
71 }
72 else if (c > 0) {
73 s = m + 1;
74 }
75 else {
76 return m;
77 }
78 }
79
80 return ~s;
81}
82
92template<template<typename, typename> class containterT, class T, class Allocator>
93typename std::enable_if<!IsSmartPtr<T>::value && !std::is_scalar<T>::value, int>::type _net_binnary_search(const containterT<T, Allocator> &container, int index, int count, T value)
94{
95 int s = index;
96 int f = index + count - 1;
97 int c, m;
98
99 while (s <= f)
100 {
101 m = s + ((f - s) / 2);
102
103 c = value.CompareTo(container[m]);
104
105 if (c < 0) {
106 f = m - 1;
107 }
108 else if (c > 0) {
109 s = m + 1;
110 }
111 else {
112 return m;
113 }
114 }
115
116 return ~s;
117}
118
128template<template<typename, typename> class containterT, class T, class Allocator>
129typename std::enable_if<std::is_scalar<T>::value, int>::type _net_binnary_search(const containterT<T, Allocator> &container, int index, int count, T value)
130{
131 int s = index;
132 int f = index + count - 1;
133 int m;
134
135 while (s <= f)
136 {
137 m = s + ((f - s) / 2);
138
139 if (value < container[m]) {
140 f = m - 1;
141 }
142 else if (value > container[m]) {
143 s = m + 1;
144 }
145 else {
146 return m;
147 }
148 }
149
150 return ~s;
151}
152
153
154}}}
155
156#endif
Interface that compares two objects in greater-equal-less sense. Objects of this class should only be...
Definition: icomparer.h:20
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
int _net_binnary_search(const containterT< T, Allocator > &container, int index, int count, T value, const SharedPtr< System::Collections::Generic::IComparer< T > > &comparer)
Implements binary search in random access container.
Definition: algorithms.h:23
Definition: db_command.h:9