vtf-logo

partition.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00016 #if !defined(__numerical_partition_h__)
00017 #define __numerical_partition_h__
00018 
00019 #include "defs.h"
00020 
00021 #include <algorithm>
00022 
00023 #include <cassert>
00024 
00025 BEGIN_NAMESPACE_NUMERICAL
00026 
00028 
00041 inline
00042 int
00043 partition(const int x, const int n, const int i) {
00044 #ifdef DEBUG_numerical
00045   assert(x >= 0 && n > 0 && 0 <= i && i < n);
00046 #endif
00047   int p = x / n;
00048   if (i < x % n) {
00049     ++p;
00050   }
00051   return p;
00052 }
00053 
00055 
00070 inline
00071 void
00072 partitionRange(const int x, const int n, const int i, int* a, int* b) {
00073   const int p = x / n;
00074   *a = p * i;
00075   *a += std::min(i, x % n);
00076   *b = *a + partition(x, n, i);
00077 }
00078 
00079 END_NAMESPACE_NUMERICAL
00080 
00081 #endif

Generated on Fri Aug 24 12:56:05 2007 for Numerical Algorithms Package by  doxygen 1.4.7