[7fa5e8]: src / modules / bugs / functions / Order.cc Maximize Restore History

Download this file

Order.cc    51 lines (39 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <config.h>
#include <util/dim.h>
#include "Order.h"
#include <algorithm>
using std::vector;
using std::stable_sort;
static bool lt_doubleptr (double const *arg1, double const *arg2) {
return *arg1 < *arg2;
}
namespace bugs {
Order::Order ()
: VectorFunction ("order", 1)
{
}
void Order::evaluate(double *value, vector<double const *> const &args,
vector<unsigned int> const &lengths) const
{
int N = lengths[0];
//Create a vector of pointers to the elements of arg and sort it
double const **argptrs = new double const *[N];
for (int i = 0; i < N; ++i) {
argptrs[i] = args[0] + i;
}
stable_sort(argptrs, argptrs + N, lt_doubleptr);
//Orders can be inferred from the sorted vector of pointers
for (int i = 0; i < N; ++i) {
value[i] = argptrs[i] - args[0] + 1;
}
delete [] argptrs;
}
unsigned int Order::length (vector<unsigned int> const &lengths) const
{
return lengths[0];
}
bool Order::isDiscreteValued(vector<bool> const &mask) const
{
return true;
}
}