Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial_rank.hpp
1 // -*- C++ -*-
2 //
3 // Copyright Sylvain Bougerel 2009 - 2013.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file COPYING or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
14 #ifndef SPATIAL_RANK_HPP
15 #define SPATIAL_RANK_HPP
16 
17 #include "spatial_node.hpp" // for modulo()
18 
19 namespace spatial
20 {
21  namespace details
22  {
29  template <dimension_type Value>
30  struct Static_rank
31  {
35  { return Value; }
36  };
37 
42  struct Dynamic_rank
43  {
46  { return _rank; }
47 
50  explicit
52  : _rank(rank)
53  { }
54 
55  private:
58  };
59 
66  template<typename Rank>
67  inline dimension_type
68  incr_dim(Rank rank, dimension_type node_dim)
69  { return (node_dim + 1) % rank(); }
70 
77  template<typename Rank>
78  inline dimension_type
79  decr_dim(Rank rank, dimension_type node_dim)
80  { return (rank() + node_dim - 1) % rank(); }
81 
95  template <typename Link, typename Rank>
96  inline dimension_type
97  modulo(const Node<Link>* x, Rank r)
98  {
99  dimension_type d = r() - 1;
100  while(!header(x)) { ++d; x = x->parent; }
101  return d % r();
102  }
103  }
104 }
105 
106 #endif // SPATIAL_RANK_HPP
dimension_type _rank
The value that stores the rank dimension.
The dimension value is stored by a member of the object, but can be modified at run time...
dimension_type modulo(const Node< Link > *x, Rank r)
Returns the modulo of a node's heigth by a container's rank.
The basic node for any tree in the library.
bool header(const Node< Link > *x)
Check if node is a header node.
std::size_t dimension_type
Defines the type for the dimension as being a size.
Definition: spatial.hpp:71
The dimension value is set by a template value, thus consuming no memory.
The main namespace used in the library.
Definition: algorithm.hpp:23
dimension_type decr_dim(Rank rank, dimension_type node_dim)
Decrement dimension node_dim, given rank.
dimension_type operator()() const
Returns the dimension for the rank specified in the template parameter Value.
Node * parent
A pointer to the parent of the current node.
dimension_type operator()() const
Returns the dimension for the rank stored in _rank.
dimension_type incr_dim(Rank rank, dimension_type node_dim)
Increment dimension node_dim, given rank.
Dynamic_rank(dimension_type rank=1)
Build a rank with a default dimension of 1.