8#ifndef META_OCEAN_BASE_MEDIAN_H 
    9#define META_OCEAN_BASE_MEDIAN_H 
   34        static inline T 
median2(
const T& v0, 
const T& v1);
 
   46        static inline T 
median3(
const T& v0, 
const T& v1, 
const T& v2);
 
   59        static inline T 
median4(
const T& v0, 
const T& v1, 
const T& v2, 
const T& v3);
 
   73        static inline T 
median5(
const T& v0, 
const T& v1, 
const T& v2, 
const T& v3, 
const T& v4);
 
   85        static T 
median(T* values, 
const size_t number);
 
   97        static T 
constMedian(
const T* values, 
const size_t number);
 
 
  103    return v0 < v1 ? v0 : v1;
 
 
  335inline T 
Median::median5(
const T& v0, 
const T& v1, 
const T& v2, 
const T& v3, 
const T& v4)
 
 
 1151template <
typename T>
 
 1154    ocean_assert(values && number > 0);
 
 1157    size_t high = number - 1;
 
 1158    size_t median = (low + high) >> 1;
 
 1160    size_t ll, hh, middle;
 
 1171        if (high == low + 1)
 
 1173            if (values[low] > values[high])
 
 1175                std::swap(values[low], values[high]);
 
 1181        middle = (low + high) / 2;
 
 1183        if (values[middle] > values[high])
 
 1185            std::swap(values[middle], values[high]);
 
 1188        if (values[low] > values[high])
 
 1190            std::swap(values[low], values[high]);
 
 1193        if (values[middle] > values[low])
 
 1195            std::swap(values[middle], values[low]);
 
 1198        std::swap(values[middle], values[low + 1]);
 
 1205            while (ll < number && values[low] > values[++ll])
 
 1210            while (hh > 0 && values[--hh] > values[low])
 
 1220            std::swap(values[ll], values[hh]);
 
 1223        std::swap(values[low], values[hh]);
 
 
 1237template <
typename T>
 
 1240    ocean_assert(values != 
nullptr && number > 0);
 
 1247    Memory memory = Memory::create<T>(number);
 
 1249    if (memory.
data() == 
nullptr)
 
 1251        ocean_assert(
false && 
"Out of memory");
 
 1255    memcpy(memory.
data<T>(), values, 
sizeof(T) * number);
 
 1256    const T result = 
median(memory.
data<T>(), number);
 
 
This class implements an object able to allocate memory.
Definition base/Memory.h:22
void * data()
Returns the pointer to the writable memory which is allocated by this object.
Definition base/Memory.h:303
The namespace covering the entire Ocean framework.
Definition Accessor.h:15