1 #ifndef L1Trigger_L1TMuonEndCapPhase2_DataUtils_h 2 #define L1Trigger_L1TMuonEndCapPhase2_DataUtils_h 15 template <
typename T,
typename C>
16 void swapWires(
T arr[],
const unsigned int& wire_1,
const unsigned int& wire_2,
const C& comparator) {
17 int result = comparator(arr[wire_1], arr[wire_2]);
20 auto temp = arr[wire_1];
21 arr[wire_1] = arr[wire_2];
26 template <
typename T,
typename C>
28 const unsigned int&
offset,
29 const unsigned int&
step,
30 const unsigned int& block_begin,
31 const unsigned int& block_end,
32 const unsigned int& first_n,
33 const C& comparator) {
34 auto wire_offset =
offset + block_begin;
35 auto wire_cutoff = first_n + block_begin;
36 auto wire_1 = wire_offset;
37 auto wire_2 = wire_1 +
step;
40 while (wire_2 < block_end) {
42 if (first_n > 0 && wire_cutoff < block_end) {
43 bool wire_needed = (wire_offset <= wire_1) && (wire_1 <= wire_cutoff);
51 swapWires(arr, wire_1, wire_2, comparator);
61 wire_2 = wire_1 +
step;
65 template <
typename T,
typename C>
66 void mergesort(
T arr[],
const unsigned int& arr_size,
const unsigned int& first_n,
const C& comparator) {
68 auto n_pairs =
static_cast<unsigned int>(arr_size / 2);
70 for (
unsigned int i = 0;
i < n_pairs; ++
i) {
87 auto block_begin = 0u;
90 while (block_begin < arr_size) {
92 if (block_end > arr_size)
99 block_begin = block_end;
109 }
else if (
step == 2) {
133 template <
typename T,
typename C>
134 void mergesort(
T arr[],
const unsigned int& arr_size,
const C& comparator) {
139 template <
typename T>
143 if ((arr_size % 2) == 0) {
144 const auto& top = arr[arr_size / 2];
145 const auto& bot = arr[arr_size / 2 - 1];
146 mid = (top + bot) >> 1;
148 mid = arr[(arr_size - 1) / 2];
155 #endif // L1Trigger_L1TMuonEndCapPhase2_DataUtils_h not defined
T getMedianOfSorted(T arr[], const unsigned int &arr_size)
void swapWires(T arr[], const unsigned int &wire_1, const unsigned int &wire_2, const C &comparator)
void mergesort(T arr[], const unsigned int &arr_size, const unsigned int &first_n, const C &comparator)
void mergesortBlock(T arr[], const unsigned int &offset, const unsigned int &step, const unsigned int &block_begin, const unsigned int &block_end, const unsigned int &first_n, const C &comparator)