Tor 0.4.9.0-alpha-dev
order.h
Go to the documentation of this file.
1/* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4/* See LICENSE for licensing information */
5
6#ifndef TOR_ORDER_H
7#define TOR_ORDER_H
8
9/**
10 * \file order.h
11 *
12 * \brief Header for order.c.
13 **/
14
16#include "lib/cc/torint.h"
17
18/* These functions, given an <b>array</b> of <b>n_elements</b>, return the
19 * <b>nth</b> lowest element. <b>nth</b>=0 gives the lowest element;
20 * <b>n_elements</b>-1 gives the highest; and (<b>n_elements</b>-1) / 2 gives
21 * the median. As a side effect, the elements of <b>array</b> are sorted. */
22int find_nth_int(int *array, int n_elements, int nth);
23time_t find_nth_time(time_t *array, int n_elements, int nth);
24double find_nth_double(double *array, int n_elements, int nth);
25int32_t find_nth_int32(int32_t *array, int n_elements, int nth);
26uint32_t find_nth_uint32(uint32_t *array, int n_elements, int nth);
27long find_nth_long(long *array, int n_elements, int nth);
28static inline int
29median_int(int *array, int n_elements)
30{
31 return find_nth_int(array, n_elements, (n_elements-1)/2);
32}
33static inline time_t
34median_time(time_t *array, int n_elements)
35{
36 return find_nth_time(array, n_elements, (n_elements-1)/2);
37}
38static inline double
39median_double(double *array, int n_elements)
40{
41 return find_nth_double(array, n_elements, (n_elements-1)/2);
42}
43static inline uint32_t
44median_uint32(uint32_t *array, int n_elements)
45{
46 return find_nth_uint32(array, n_elements, (n_elements-1)/2);
47}
48static inline int32_t
49median_int32(int32_t *array, int n_elements)
50{
51 return find_nth_int32(array, n_elements, (n_elements-1)/2);
52}
53
54static inline uint32_t
55third_quartile_uint32(uint32_t *array, int n_elements)
56{
57 return find_nth_uint32(array, n_elements, (n_elements*3)/4);
58}
59
60#endif /* !defined(TOR_ORDER_H) */
Utility macros to handle different features and behavior in different compilers.
Integer definitions used throughout Tor.