Proto  3.2
Proto_Morton.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MORTON_H_
3 #define _PROTO_MORTON_H_
4 #include <cstdint>
5 #include <algorithm>
6 #include "Proto_Point.H"
7 
8 #if DIM==1
9 #define LOGSIZE 16 // 21 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
10 #define MORTONSIZE 65536 // 2097152 // = 2^LOGSIZE.
11 #endif
12 #if DIM==2
13 #define LOGSIZE 16 // 21 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
14 #define MORTONSIZE 65536 // 2097152 // = 2^LOGSIZE.
15 #endif
16 #if DIM==3
17 #define LOGSIZE 10 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
18 #define MORTONSIZE 1024 // = 2^LOGSIZE.
19 #endif
20 #if DIM==4
21 #define LOGSIZE 16 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
22 #define MORTONSIZE 65536 // = 2^LOGSIZE.
23 #endif
24 #if DIM==5
25 #define LOGSIZE 12 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
26 #define MORTONSIZE 4096 // = 2^LOGSIZE.
27 #endif
28 #if DIM==6
29 #define LOGSIZE 10 // DIM*LOGSIZE must be less than the size (in bits) of (uint64_t).
30 #define MORTONSIZE 1024 // = 2^LOGSIZE.
31 #endif
32 
33 namespace Proto
34 {
35  /// Morton Indexer
36  /**
37  Utility class for computing the Morton Index of a DIM-tuple corresponding to the
38  bits of each element of the tuple.
39  */
40  class Morton
41  {
42  public:
43 
44  /// Compute Morton Index
45  /**
46  Compute the Morton index of a Point.
47 
48  \param a_pt A Point
49  \param a_morton A Morton indexer
50  */
51  inline static uint64_t index(const Point& a_pt);
52 
53  /// Morton Sort
54  /**
55  Sort a vector of Point in place by Morton index.
56  \param a_pts A vector of Points to be sorted
57  */
58  inline static void sort(vector<Point>& a_pts);
59 
60  private:
61 
63 
64  // Public construction is not allowed. Morton is a singleton.
65  inline Morton();
66 
67  // Access the singleton Morton object
68  inline static Morton& instance();
69 
70  // Sorting condition
71  inline static bool compareSecond(pair<Point,uint64_t> a_a,pair<Point,uint64_t> a_b)
72  {
73  return a_a.second < a_b.second;
74  }
75  };
76 #include "implem/Proto_MortonImplem.H"
77 }// end Proto namespace.
78 #endif
Morton Indexer.
Definition: Proto_Morton.H:40
Morton()
Definition: Proto_Morton.H:38
static uint64_t index(const Point &a_pt)
Compute Morton Index.
Definition: Proto_Morton.H:8
static Morton & instance()
Definition: Proto_Morton.H:2
static bool compareSecond(pair< Point, uint64_t > a_a, pair< Point, uint64_t > a_b)
Definition: Proto_Morton.H:71
Definition: Proto_Array.H:17
A templated constant size array object similar to std::array, but with the ability to be used inside ...
Definition: Proto_Array.H:28
Array< vector< uint64_t >, DIM > m_morton1D
Definition: Proto_Morton.H:62
Integer Valued Vector.
Definition: Proto_Point.H:24
static void sort(vector< Point > &a_pts)
Morton Sort.
Definition: Proto_Morton.H:22