blob: 27120be2722025bb9854e9218d6b06678cc26c3d [file] [log] [blame]
Ana Krulec434c22d2018-11-28 13:48:36 +01001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Ana Krulec434c22d2018-11-28 13:48:36 +010021#include "SchedulerUtils.h"
22
23#include <cinttypes>
24#include <numeric>
25#include <unordered_map>
26#include <vector>
27
28namespace android {
29namespace scheduler {
30
31int64_t calculate_median(std::vector<int64_t>* v) {
32 if (!v || v->empty()) {
33 return 0;
34 }
35
36 size_t n = v->size() / 2;
37 nth_element(v->begin(), v->begin() + n, v->end());
38 return v->at(n);
39}
40
Ana Krulec434c22d2018-11-28 13:48:36 +010041} // namespace scheduler
42} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080043
44// TODO(b/129481165): remove the #pragma below and fix conversion issues
45#pragma clang diagnostic pop // ignored "-Wconversion"