aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-18 15:37:27 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:46:47 +0200
commit9be08ad2f8be8964ae72f6571d04ba38909e4388 (patch)
tree7ce85854927a47ec7c0b3e507bd7d6f333d62bb3
parent767265863fca8e2043622f0591281a1deb7821af (diff)
downloadchilbert-9be08ad2f8be8964ae72f6571d04ba38909e4388.tar.gz
chilbert-9be08ad2f8be8964ae72f6571d04ba38909e4388.tar.bz2
chilbert-9be08ad2f8be8964ae72f6571d04ba38909e4388.zip
Clean up main public API header
-rw-r--r--Makefile2
-rw-r--r--chilbert/Hilbert.hpp224
-rw-r--r--chilbert/Hilbert.ipp (renamed from chilbert/Algorithm.hpp)19
3 files changed, 73 insertions, 172 deletions
diff --git a/Makefile b/Makefile
index c6201c9..1b7a09a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
CXXFLAGS += -I. -std=c++14 -Wall -Wextra -Wno-unused-parameter
-HEADERS = $(wildcard chilbert/*.hpp)
+HEADERS = $(wildcard chilbert/*.hpp) $(wildcard chilbert/*.ipp)
TESTS = test/test_bitvec test/test_gray_code_rank test/test_hilbert
all: $(TESTS)
diff --git a/chilbert/Hilbert.hpp b/chilbert/Hilbert.hpp
index a6b48fb..5b4646d 100644
--- a/chilbert/Hilbert.hpp
+++ b/chilbert/Hilbert.hpp
@@ -19,172 +19,72 @@
#ifndef CHILBERT_HILBERT_HPP
#define CHILBERT_HILBERT_HPP
-#include "chilbert/Algorithm.hpp"
-#include "chilbert/BigBitVec.hpp"
-#include "chilbert/FixBitVec.hpp"
-
-// Description of parameters:
-//
-// FOR REGULAR HILBERT INDICES
-//
-// CFixBitVec/CBigBitVec *p
-// Pointer to array of non-negative coordinate values.
-//
-// int m
-// Precision of all coordinate values (number of bits required to
-// represent the largest possible coordinate value).
-//
-// int n
-// Number of dimensions (size of the array *p).
-//
-// CFixBitVec/CBigBitVec &h
-// Hilbert index of maximum precision m*n.
-//
-// int *ms
-// Array of precision values, one per dimension.
-//
-// FOR COMPACT HILBERT INDICES
-//
-// CFixBitVec/CBigBitVec &hc
-// Compact Hilbert index of maximum precision M.
-//
-// int M
-// Net precision value, corresponding to the size of the compact
-// Hilbert code. If not provided, defaults to zero and will be calculated
-// by the function (sum_i { ms[i] }).
-//
-// int m
-// Largest precision value (max_i { ms[i] }). If not provided, defaults
-// to zero and will be calculated by the function,
+#include <cstddef>
namespace chilbert {
-// fix -> fix
-
-inline void
-coordsToIndex(const CFixBitVec* const p,
- const size_t m,
- const size_t n,
- CFixBitVec& h)
-{
- coordsToIndex<CFixBitVec, CFixBitVec>(p, m, n, h);
-}
-
-inline void
-indexToCoords(CFixBitVec* const p,
- const size_t m,
- const size_t n,
- const CFixBitVec& h)
-{
- indexToCoords<CFixBitVec, CFixBitVec>(p, m, n, h);
-}
-
-inline void
-coordsToCompactIndex(const CFixBitVec* const p,
- const size_t* const ms,
- const size_t n,
- CFixBitVec& hc,
- const size_t M,
- const size_t m)
-{
- coordsToCompactIndex<CFixBitVec, CFixBitVec>(p, ms, n, hc, M, m);
-}
-
-inline void
-compactIndexToCoords(CFixBitVec* const p,
- const size_t* const ms,
- const size_t n,
- const CFixBitVec& hc,
- const size_t M,
- const size_t m)
-{
- compactIndexToCoords<CFixBitVec, CFixBitVec>(p, ms, n, hc, M, m);
-}
-
-// fix -> big
-
-inline void
-coordsToIndex(const CFixBitVec* const p,
- const size_t m,
- const size_t n,
- CBigBitVec& h)
-{
- coordsToIndex<CFixBitVec, CBigBitVec>(p, m, n, h);
-}
-
-inline void
-indexToCoords(CFixBitVec* const p,
- const size_t m,
- const size_t n,
- const CBigBitVec& h)
-{
- indexToCoords<CFixBitVec, CBigBitVec>(p, m, n, h);
-}
-
-inline void
-coordsToCompactIndex(const CFixBitVec* const p,
- const size_t* const ms,
- const size_t n,
- CBigBitVec& hc,
- const size_t M,
- const size_t m)
-{
- coordsToCompactIndex<CFixBitVec, CBigBitVec>(p, ms, n, hc, M, m);
-}
-
-inline void
-compactIndexToCoords(CFixBitVec* const p,
- const size_t* const ms,
- const size_t n,
- const CBigBitVec& hc,
- const size_t M,
- const size_t m)
-{
- compactIndexToCoords<CFixBitVec, CBigBitVec>(p, ms, n, hc, M, m);
-}
-
-// big -> big
-
-inline void
-coordsToIndex(const CBigBitVec* p,
- const size_t m,
- const size_t n,
- CBigBitVec& h)
-{
- coordsToIndex<CBigBitVec, CBigBitVec>(p, m, n, h);
-}
-
-inline void
-indexToCoords(CBigBitVec* const p,
- const size_t m,
- const size_t n,
- const CBigBitVec& h)
-{
- indexToCoords<CBigBitVec, CBigBitVec>(p, m, n, h);
-}
-
-inline void
-coordsToCompactIndex(const CBigBitVec* const p,
- const size_t* const ms,
- const size_t n,
- CBigBitVec& hc,
- const size_t M,
- const size_t m)
-{
- coordsToCompactIndex<CBigBitVec, CBigBitVec>(p, ms, n, hc, M, m);
-}
-
-inline void
-compactIndexToCoords(CBigBitVec* const p,
- const size_t* const ms,
- const size_t n,
- const CBigBitVec& hc,
- const size_t M,
- const size_t m)
-{
- compactIndexToCoords<CBigBitVec, CBigBitVec>(p, ms, n, hc, M, m);
-}
+/** Map the point `p` to a Hilbert Index.
+ *
+ * @param p Point with `n` dimensions.
+ * @param m Precision of each dimension in bits.
+ * @param n Number of dimensions.
+ * @param[out] h Hilbert Index.
+ */
+template <class P, class H>
+inline void coordsToIndex(const P* const p,
+ const size_t m,
+ const size_t n,
+ H& h);
+
+/** Map the Hilbert Index `p` to a point.
+ *
+ * @param[out] p Point with `n` dimensions.
+ * @param m Precision of each dimension in bits.
+ * @param n Number of dimensions.
+ * @param h Hilbert Index.
+ */
+template <class P, class H>
+inline void indexToCoords(P* const p,
+ const size_t m,
+ const size_t n,
+ const H& h);
+
+/** Map the point `p` to a Compact Hilbert Index.
+ *
+ * @param p Point with `n` dimensions.
+ * @param ms Array of `n` precision values for each dimension in bits.
+ * @param n Number of dimensions.
+ * @param[out] hc Compact Hilbert Index.
+ * @param M Optional net precision (sum of `ms`), the size of `hc` in bits.
+ * @param m Optional largest precision in `m`.
+ */
+template <class P, class H>
+inline void coordsToCompactIndex(const P* const p,
+ const size_t* const ms,
+ const size_t n,
+ H& hc,
+ const size_t M = 0,
+ const size_t m = 0);
+
+/** Map the Compact Hilbert Index `hc` to a point.
+ *
+ * @param[out] p Point with `n` dimensions.
+ * @param ms Array of `n` precision values for each dimension in bits.
+ * @param n Number of dimensions.
+ * @param hc Compact Hilbert Index.
+ * @param M Optional net precision (sum of `ms`), the size of `hc` in bits.
+ * @param m Optional largest precision in `m`.
+ */
+template <class P, class H>
+inline void compactIndexToCoords(P* const p,
+ const size_t* const ms,
+ const size_t n,
+ const H& hc,
+ const size_t M = 0,
+ const size_t m = 0);
} // namespace chilbert
+#include "chilbert/Hilbert.ipp"
+
#endif
diff --git a/chilbert/Algorithm.hpp b/chilbert/Hilbert.ipp
index e5072b0..b4f2b63 100644
--- a/chilbert/Algorithm.hpp
+++ b/chilbert/Hilbert.ipp
@@ -24,6 +24,7 @@
#include "chilbert/GetBits.hpp"
#include "chilbert/GetLocation.hpp"
#include "chilbert/GrayCodeRank.hpp"
+#include "chilbert/Hilbert.hpp"
#include "chilbert/SetBits.hpp"
#include "chilbert/SetLocation.hpp"
@@ -121,7 +122,7 @@ _coordsToIndex(const P* const p,
H& h,
I&& scratch,
size_t* const ds = nullptr // #HACK
- )
+)
{
I e{std::move(scratch)};
I l{e};
@@ -178,7 +179,7 @@ coordsToIndex(const P* const p, // [in ] point
const size_t m, // [in ] precision of each dimension in bits
const size_t n, // [in ] number of dimensions
H& h // [out] Hilbert index
- )
+)
{
if (n <= FBV_BITS) {
// Intermediate variables will fit in fixed width
@@ -244,7 +245,7 @@ indexToCoords(P* const p, // [out] point
const size_t m, // [in ] precision of each dimension in bits
const size_t n, // [in ] number of dimensions
const H& h // [out] Hilbert index
- )
+)
{
if (n <= FBV_BITS) {
// Intermediate variables will fit in fixed width
@@ -309,8 +310,8 @@ coordsToCompactIndex(
const size_t* const ms, // [in ] precision of each dimension in bits
size_t n, // [in ] number of dimensions
HC& hc, // [out] Hilbert index
- const size_t M = 0,
- const size_t m = 0)
+ const size_t M,
+ const size_t m)
{
if (n <= FBV_BITS) {
// Intermediate variables will fit in fixed width?
@@ -330,8 +331,8 @@ _compactIndexToCoords(P* const p,
const size_t n,
const HC& hc,
I&& scratch,
- size_t M = 0,
- size_t m = 0)
+ size_t M,
+ size_t m)
{
I e{std::move(scratch)};
I l{e};
@@ -407,8 +408,8 @@ compactIndexToCoords(
const size_t* ms, // [in ] precision of each dimension in bits
const size_t n, // [in ] number of dimensions
const HC& hc, // [out] Hilbert index
- const size_t M = 0,
- const size_t m = 0)
+ const size_t M,
+ const size_t m)
{
if (n <= FBV_BITS) {
// Intermediate variables will fit in fixed width