partition.h File Reference

A fair partition of an integer. More...

#include "defs.h"
#include <algorithm>
#include <cassert>

Go to the source code of this file.

Functions

BEGIN_NAMESPACE_NUMERICAL int partition (const int x, const int n, const int i)
 Return the i_th fair partition of x into n parts.
void partitionRange (const int x, const int n, const int i, int *a, int *b)
 Compute the i_th fair partition range of x into n ranges.

Detailed Description

A fair partition of an integer.


Function Documentation

BEGIN_NAMESPACE_NUMERICAL int partition ( const int  x,
const int  n,
const int  i 
) [inline]

Return the i_th fair partition of x into n parts.

Partition x into n fair parts. Return the i_th part. The parts differ by at most one and are in non-increasing order.

Parameters:
x is the number to partition.
n is the number of partitions.
i is the requested partition.
Precondition:
x is non-negative. n is positive. i is in the range [0..n).

Referenced by partitionRange().

void partitionRange ( const int  x,
const int  n,
const int  i,
int *  a,
int *  b 
) [inline]

Compute the i_th fair partition range of x into n ranges.

Partition x into n fair ranges. Compute the i_th range. The lengths of the ranges differ by at most one and are in non-increasing order.

Parameters:
x is the number to partition.
n is the number of partitions.
i is the requested range.
a is the begining of the range.
b is the end of the open range, [a..b).
Precondition:
x is non-negative. n is positive. i is in the range [0..n).

References min(), and partition().

Generated on Thu Jun 30 02:15:00 2016 for Numerical Algorithms Package by  doxygen 1.6.3