# itk::NeighborhoodRange: a new class for efficient modern C++ style iteration

**URL:** https://discourse.itk.org/t/itk-neighborhoodrange-a-new-class-for-efficient-modern-c-style-iteration/833
**Category:** Engineering
**Created:** [April 10, 2018, 7:37pm UTC](https://discourse.itk.org/t/itk-neighborhoodrange-a-new-class-for-efficient-modern-c-style-iteration/833 "2018-04-10T19:37:56Z")
**Posts on this page:** 1
**Showing post:** 63

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [May 15, 2018, 8:24pm UTC](https://discourse.itk.org/t/itk-neighborhoodrange-a-new-class-for-efficient-modern-c-style-iteration/833/63 "2018-05-15T20:24:12Z")

</div>

@phcerdan Update: I just learned that it appears better **_not_** to call a `Factorial` function, when calculating the binomial coefficient, _“n over m”_, as I did before to calculate the number of offsets _N_ needed for an _N_-connected neigborhood ([TopologicalConnectivityImageNeighborhoodShape](https://gist.github.com/N-Dekker/0f17c0473b29494faea93244bbb43393)). My colleague Baldur van Lew suggested me to calculate the binomial coefficient as described by Walter (June 23 2017), at:

> <https://stackoverflow.com/questions/44718971/calculate-binomial-coffeficient-very-reliably/44719165#44719165>

When using this clever `binom` function, the value _N_ of an _N_-connected neighborhood can be calculated for images that have far more than 20 dimensions!!! Without integer overflow! 😃 So although it might be nice to make the existing `itk::GeometryUtilities::Factorial` function _constexpr_, it’s certainly not necessary for the implementation this shape class.

By the way, the hyperrectangular shape class is still “under review”, it has its first “+1” from @dzenanz: [http://review.source.kitware.com/#/c/23389/](http://review.source.kitware.com/#/c/23389/) See also: [A shape class for ShapedImageNeighborhoodRange and ShapedNeighborhoodIterator](https://discourse.itk.org/t/a-shape-class-for-shapedimageneighborhoodrange-and-shapedneighborhooditerator/924) As you know, I would like the hyperrectangular shape class to be accepted before proposing an _N_-connected shape class.

---

_[View the full topic](https://discourse.itk.org/t/itk-neighborhoodrange-a-new-class-for-efficient-modern-c-style-iteration/833)._
