dhcpd-pools  2.28
ISC dhcpd lease usage analyser
Functions
sort.c File Reference

Functions to sort output. More...

#include <config.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
#include "progname.h"
#include "quote.h"
#include "dhcpd-pools.h"
Include dependency graph for sort.c:

Functions

int ipcomp_init (const union ipaddr_t *restrict a __attribute__((unused)), const union ipaddr_t *restrict b __attribute__((unused)))
 Compare IP address, with IPv4/v6 determination. More...
 
int ipcomp_v4 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
 
int ipcomp_v6 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
 
int leasecomp_init (const struct leases_t *restrict a __attribute__((unused)), const struct leases_t *restrict b __attribute__((unused)))
 Compare IP address in leases_t structure, with IPv4/v6 determination. More...
 
int leasecomp_v4 (const struct leases_t *restrict a, const struct leases_t *restrict b)
 
int leasecomp_v6 (const struct leases_t *restrict a, const struct leases_t *restrict b)
 
int rangecomp (const void *restrict r1, const void *restrict r2)
 Compare IP address in leases. More...
 
int comp_double (double f1, double f2)
 Compare two doubles. More...
 
int comp_ip (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their first_ip. More...
 
int comp_max (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their capacity. More...
 
int comp_cur (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their current usage. More...
 
int comp_percent (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their current usage percentage. More...
 
int comp_touched (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched addresses. More...
 
int comp_tc (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched and in use addresses. More...
 
int comp_tcperc (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched and in use percentage. More...
 
double ret_percent (struct range_t r)
 Percentage in use in range. More...
 
double ret_tc (struct range_t r)
 Touched and in use in range. More...
 
double ret_tcperc (struct range_t r)
 Return percentage of addresses touched and in use in range. More...
 
comparer_t field_selector (char c)
 Sort field selector. More...
 
static int merge (struct range_t *restrict left, struct range_t *restrict right)
 Perform requested sorting. More...
 
void mergesort_ranges (struct range_t *restrict orig, int size, struct range_t *restrict temp)
 Mergesort for range table. More...
 

Detailed Description

Functions to sort output.

Function Documentation

int comp_cur ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_double ( double  f1,
double  f2 
)

Compare two doubles.

Parameters
f1,f2Data to compare.
Returns
Like strcmp.

Referenced by comp_cur(), comp_max(), comp_percent(), comp_tc(), comp_tcperc(), and comp_touched().

int comp_ip ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their first_ip.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

int comp_max ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their capacity.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_percent ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_tc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_tcperc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_touched ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

comparer_t field_selector ( char  c)

Sort field selector.

Parameters
cSymbolic name of a sort by character. The sort algorithms are stabile, which means multiple sorts can be specified and they do not mess the result of previous sort. The sort algorithms are used via function pointer, that gets to be reassigned.
Returns
Return the selected compare function.

Referenced by main().

Here is the call graph for this function:

int ipcomp_init ( const union ipaddr_t *restrict a   __attribute__(unused),
const union ipaddr_t *restrict b   __attribute__(unused) 
)

Compare IP address, with IPv4/v6 determination.

Parameters
aBinary IP address.
bBinary IP address.
Returns
If a < b return -1, if a < b return 1, when they are equal return 0.
int ipcomp_v4 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

int ipcomp_v6 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

int leasecomp_init ( const struct leases_t *restrict a   __attribute__(unused),
const struct leases_t *restrict b   __attribute__(unused) 
)

Compare IP address in leases_t structure, with IPv4/v6 determination.

Parameters
aBinary IP address.
bBinary IP address.
Returns
If a < b return -1, if a < b return 1, when they are equal return 0.

Referenced by set_ipv_functions().

int leasecomp_v4 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

int leasecomp_v6 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

static int merge ( struct range_t *restrict  left,
struct range_t *restrict  right 
)
static

Perform requested sorting.

Parameters
leftThe left side of the merge sort.
rightThe right side of the merge sort.
Returns
Relevant for merge sort decision.

Referenced by mergesort_ranges().

void mergesort_ranges ( struct range_t *restrict  orig,
int  size,
struct range_t *restrict  temp 
)

Mergesort for range table.

Parameters
origPointer to range that is requested to be sorted.
sizeNumber of ranges to be sorted.
tempTemporary memory space, needed when a values has to be flipped.

Here is the call graph for this function:

int rangecomp ( const void *restrict  r1,
const void *restrict  r2 
)

Compare IP address in leases.

Suitable for sorting range table.

Parameters
r1A range structure.
r2A range structure.
Returns
Return pas through from ipcomp.
double ret_percent ( struct range_t  r)

Percentage in use in range.

Parameters
rA range structure.
Returns
Usage percentage of the given range.

Referenced by comp_percent().

double ret_tc ( struct range_t  r)

Touched and in use in range.

Parameters
rA range structure.
Returns
Number of touched or in use addresses in the given range.

Referenced by comp_tc(), and ret_tcperc().

double ret_tcperc ( struct range_t  r)

Return percentage of addresses touched and in use in range.

Parameters
rA range structure.
Returns
Percentage of touched or in use addresses in the given range.

Referenced by comp_tcperc().

Here is the call graph for this function: