LCOV - code coverage report
Current view: top level - lib/container - order.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 12 12 100.0 %
Date: 2021-11-24 03:28:48 Functions: 6 6 100.0 %

          Line data    Source code
       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             : 
      15             : #include "lib/cc/compat_compiler.h"
      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. */
      22             : int find_nth_int(int *array, int n_elements, int nth);
      23             : time_t find_nth_time(time_t *array, int n_elements, int nth);
      24             : double find_nth_double(double *array, int n_elements, int nth);
      25             : int32_t find_nth_int32(int32_t *array, int n_elements, int nth);
      26             : uint32_t find_nth_uint32(uint32_t *array, int n_elements, int nth);
      27             : long find_nth_long(long *array, int n_elements, int nth);
      28             : static inline int
      29          53 : median_int(int *array, int n_elements)
      30             : {
      31          53 :   return find_nth_int(array, n_elements, (n_elements-1)/2);
      32             : }
      33             : static inline time_t
      34          77 : median_time(time_t *array, int n_elements)
      35             : {
      36          77 :   return find_nth_time(array, n_elements, (n_elements-1)/2);
      37             : }
      38             : static inline double
      39          12 : median_double(double *array, int n_elements)
      40             : {
      41          12 :   return find_nth_double(array, n_elements, (n_elements-1)/2);
      42             : }
      43             : static inline uint32_t
      44          78 : median_uint32(uint32_t *array, int n_elements)
      45             : {
      46          78 :   return find_nth_uint32(array, n_elements, (n_elements-1)/2);
      47             : }
      48             : static inline int32_t
      49          92 : median_int32(int32_t *array, int n_elements)
      50             : {
      51          92 :   return find_nth_int32(array, n_elements, (n_elements-1)/2);
      52             : }
      53             : 
      54             : static inline uint32_t
      55           5 : third_quartile_uint32(uint32_t *array, int n_elements)
      56             : {
      57           5 :   return find_nth_uint32(array, n_elements, (n_elements*3)/4);
      58             : }
      59             : 
      60             : #endif /* !defined(TOR_ORDER_H) */

Generated by: LCOV version 1.14