aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-07 19:30:43 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:46:17 +0200
commitf4ab1d3b31a04edaebde3ceb96e3708b151eca53 (patch)
tree3c0b5fd2887019ee32ae16894133fc31dfc8c54f
parent5194cf21beef5a52aeb7454bd517b96eff5ff0a0 (diff)
downloadchilbert-f4ab1d3b31a04edaebde3ceb96e3708b151eca53.tar.gz
chilbert-f4ab1d3b31a04edaebde3ceb96e3708b151eca53.tar.bz2
chilbert-f4ab1d3b31a04edaebde3ceb96e3708b151eca53.zip
Fix indentation
-rw-r--r--chilbert/Algorithm.hpp778
1 files changed, 389 insertions, 389 deletions
diff --git a/chilbert/Algorithm.hpp b/chilbert/Algorithm.hpp
index bd4a9a1..99adc9d 100644
--- a/chilbert/Algorithm.hpp
+++ b/chilbert/Algorithm.hpp
@@ -54,444 +54,444 @@
namespace chilbert
{
- // 'Transforms' a point.
- template<class I>
- inline
- void
- transform(
- const I &e,
- int d,
- int n,
- I &a
- )
- {
- a ^= e;
- a.rotr( d, n );//#D d+1, n );
- return;
- }
+// 'Transforms' a point.
+template<class I>
+inline
+void
+transform(
+ const I &e,
+ int d,
+ int n,
+ I &a
+ )
+{
+ a ^= e;
+ a.rotr( d, n );//#D d+1, n );
+ return;
+}
- // Inverse 'transforms' a point.
- template<class I>
- inline
- void
- transformInv(
- const I &e,
- int d,
- int n,
- I &a
- )
- {
- a.rotl( d, n );//#D d+1, n );
- a ^= e;
- return;
- }
+// Inverse 'transforms' a point.
+template<class I>
+inline
+void
+transformInv(
+ const I &e,
+ int d,
+ int n,
+ I &a
+ )
+{
+ a.rotl( d, n );//#D d+1, n );
+ a ^= e;
+ return;
+}
- // Update for method 1 (GrayCodeInv in the loop)
- template<class I>
- inline
- void
- update1(
- const I &l,
- const I &t,
- const I &w,
- int n,
- I &e,
- int &d
- )
- {
- assert( 0 <= d && d < n );
- e = l;
- e.toggle( d ); //#D d == n-1 ? 0 : d+1 );
+// Update for method 1 (GrayCodeInv in the loop)
+template<class I>
+inline
+void
+update1(
+ const I &l,
+ const I &t,
+ const I &w,
+ int n,
+ I &e,
+ int &d
+ )
+{
+ assert( 0 <= d && d < n );
+ e = l;
+ e.toggle( d ); //#D d == n-1 ? 0 : d+1 );
- // Update direction
- d += 1 + t.fsb();
- if ( d >= n ) d -= n;
- if ( d >= n ) d -= n;
- assert( 0 <= d && d < n );
+ // Update direction
+ d += 1 + t.fsb();
+ if ( d >= n ) d -= n;
+ if ( d >= n ) d -= n;
+ assert( 0 <= d && d < n );
- if ( ! (w.rack() & 1) )
- e.toggle( d == 0 ? n-1 : d-1 ); //#D d );
+ if ( ! (w.rack() & 1) )
+ e.toggle( d == 0 ? n-1 : d-1 ); //#D d );
- return;
- }
+ return;
+}
- // Update for method 2 (GrayCodeInv out of loop)
- template<class I>
- inline
- void
- update2(
- const I &l,
- const I &t,
- const I &w,
- int n,
- I &e,
- int &d
- )
- {
- assert( 0 <= d && d < n );
- e = l;
- e.toggle( d );//#D d == n-1 ? 0 : d+1 );
+// Update for method 2 (GrayCodeInv out of loop)
+template<class I>
+inline
+void
+update2(
+ const I &l,
+ const I &t,
+ const I &w,
+ int n,
+ I &e,
+ int &d
+ )
+{
+ assert( 0 <= d && d < n );
+ e = l;
+ e.toggle( d );//#D d == n-1 ? 0 : d+1 );
- // Update direction
- d += 1 + t.fsb();
- if ( d >= n ) d -= n;
- if ( d >= n ) d -= n;
- assert( 0 <= d && d < n );
+ // Update direction
+ d += 1 + t.fsb();
+ if ( d >= n ) d -= n;
+ if ( d >= n ) d -= n;
+ assert( 0 <= d && d < n );
- return;
- }
+ return;
+}
- template <class P,class H,class I>
- inline
- void
- _coordsToIndex(
- const P *p,
- int m,
- int n,
- H &h,
- I&& scratch,
- int *ds = nullptr // #HACK
- )
+template <class P,class H,class I>
+inline
+void
+_coordsToIndex(
+ const P *p,
+ int m,
+ int n,
+ H &h,
+ I&& scratch,
+ int *ds = nullptr // #HACK
+ )
+{
+ I e{std::move(scratch)};
+ I l{e};
+ I t{e};
+ I w{e};
+ int d, i;
+ int ho = m*n;
+
+ // Initialize
+ e.reset();
+ d = D0;
+ l.reset();
+ h = 0U;
+
+ // Work from MSB to LSB
+ for ( i = m-1; i >= 0; i-- )
{
- I e{std::move(scratch)};
- I l{e};
- I t{e};
- I w{e};
- int d, i;
- int ho = m*n;
-
- // Initialize
- e.reset();
- d = D0;
- l.reset();
- h = 0U;
-
- // Work from MSB to LSB
- for ( i = m-1; i >= 0; i-- )
- {
- // #HACK
- if ( ds ) ds[i] = d;
+ // #HACK
+ if ( ds ) ds[i] = d;
- // Get corner of sub-hypercube where point lies.
- getLocation<P,I>(p,n,i,l);
+ // Get corner of sub-hypercube where point lies.
+ getLocation<P,I>(p,n,i,l);
- // Mirror and reflect the location.
- // t = T_{(e,d)}(l)
- t = l;
- transform<I>(e,d,n,t);
+ // Mirror and reflect the location.
+ // t = T_{(e,d)}(l)
+ t = l;
+ transform<I>(e,d,n,t);
- w = t;
- if ( i < m-1 )
- w.toggle(n - 1);
+ w = t;
+ if ( i < m-1 )
+ w.toggle(n - 1);
- // Concatenate to the index.
- ho -= n;
- setBits<H,I>(h,n,ho,w);
+ // Concatenate to the index.
+ ho -= n;
+ setBits<H,I>(h,n,ho,w);
- // Update the entry point and direction.
- update2<I>(l,t,w,n,e,d);
- }
-
- grayCodeInv(h);
-
- return;
+ // Update the entry point and direction.
+ update2<I>(l,t,w,n,e,d);
}
- // This is wrapper to the basic Hilbert curve index
- // calculation function. It will support fixed or
- // arbitrary precision, templated. Depending on the
- // number of dimensions, it will use the most efficient
- // representation for interim variables.
- // Assumes h is big enough for the output (n*m bits!)
- template<class P,class H>
- inline
- void
- coordsToIndex(
- const P *p, // [in ] point
- int m, // [in ] precision of each dimension in bits
- int n, // [in ] number of dimensions
- H &h // [out] Hilbert index
- )
- {
- // Intermediate variables will fit in fixed width?
- if ( n <= FBV_BITS )
- _coordsToIndex<P,H,CFixBitVec>(p,m,n,h, CFixBitVec{});
- // Otherwise, they must be BigBitVecs.
- else
- _coordsToIndex<P,H,CBigBitVec>(p,m,n,h, CBigBitVec(n));
+ grayCodeInv(h);
- return;
- }
+ return;
+}
+// This is wrapper to the basic Hilbert curve index
+// calculation function. It will support fixed or
+// arbitrary precision, templated. Depending on the
+// number of dimensions, it will use the most efficient
+// representation for interim variables.
+// Assumes h is big enough for the output (n*m bits!)
+template<class P,class H>
+inline
+void
+coordsToIndex(
+ const P *p, // [in ] point
+ int m, // [in ] precision of each dimension in bits
+ int n, // [in ] number of dimensions
+ H &h // [out] Hilbert index
+ )
+{
+ // Intermediate variables will fit in fixed width?
+ if ( n <= FBV_BITS )
+ _coordsToIndex<P,H,CFixBitVec>(p,m,n,h, CFixBitVec{});
+ // Otherwise, they must be BigBitVecs.
+ else
+ _coordsToIndex<P,H,CBigBitVec>(p,m,n,h, CBigBitVec(n));
+
+ return;
+}
- template <class P,class H,class I>
- inline
- void
- _indexToCoords(
- P *p,
- int m,
- int n,
- const H &h,
- I&& scratch
- )
- {
- I e{std::move(scratch)};
- I l{e};
- I t{e};
- I w{e};
- int d, i, j, ho;
-
- // Initialize
- e.reset();
- d = D0;
- l.reset();
- for ( j = 0; j < n; j++ )
- p[j] = 0U;
-
- ho = m*n;
+
+template <class P,class H,class I>
+inline
+void
+_indexToCoords(
+ P *p,
+ int m,
+ int n,
+ const H &h,
+ I&& scratch
+ )
+{
+ I e{std::move(scratch)};
+ I l{e};
+ I t{e};
+ I w{e};
+ int d, i, j, ho;
+
+ // Initialize
+ e.reset();
+ d = D0;
+ l.reset();
+ for ( j = 0; j < n; j++ )
+ p[j] = 0U;
+
+ ho = m*n;
- // Work from MSB to LSB
- for ( i = m-1; i >= 0; i-- )
- {
- // Get the Hilbert index bits
- ho -= n;
- getBits<H,I>(h,n,ho,w);
+ // Work from MSB to LSB
+ for ( i = m-1; i >= 0; i-- )
+ {
+ // Get the Hilbert index bits
+ ho -= n;
+ getBits<H,I>(h,n,ho,w);
- // t = GrayCode(w)
- t = w;
- grayCode(t);
+ // t = GrayCode(w)
+ t = w;
+ grayCode(t);
- // Reverse the transform
- // l = T^{-1}_{(e,d)}(t)
- l = t;
- transformInv<I>(e,d,n,l);
+ // Reverse the transform
+ // l = T^{-1}_{(e,d)}(t)
+ l = t;
+ transformInv<I>(e,d,n,l);
- // Distribute these bits
- // to the coordinates.
- setLocation<P,I>(p,n,i,l);
+ // Distribute these bits
+ // to the coordinates.
+ setLocation<P,I>(p,n,i,l);
- // Update the entry point and direction.
- update1<I>(l,t,w,n,e,d);
- }
-
- return;
+ // Update the entry point and direction.
+ update1<I>(l,t,w,n,e,d);
}
- // This is wrapper to the basic Hilbert curve inverse
- // index function. It will support fixed or
- // arbitrary precision, templated. Depending on the
- // number of dimensions, it will use the most efficient
- // representation for interim variables.
- // Assumes each entry of p is big enough to hold the
- // appropriate variable.
- template<class P,class H>
- inline
- void
- indexToCoords(
- P *p, // [out] point
- int m, // [in ] precision of each dimension in bits
- int n, // [in ] number of dimensions
- const H &h // [out] Hilbert index
- )
- {
- // Intermediate variables will fit in fixed width?
- if ( n <= FBV_BITS )
- _indexToCoords<P,H,CFixBitVec>(p,m,n,h,CFixBitVec{});
- // Otherwise, they must be BigBitVecs.
- else
- _indexToCoords<P,H,CBigBitVec>(p,m,n,h,CBigBitVec(n));
+ return;
+}
- return;
- }
+// This is wrapper to the basic Hilbert curve inverse
+// index function. It will support fixed or
+// arbitrary precision, templated. Depending on the
+// number of dimensions, it will use the most efficient
+// representation for interim variables.
+// Assumes each entry of p is big enough to hold the
+// appropriate variable.
+template<class P,class H>
+inline
+void
+indexToCoords(
+ P *p, // [out] point
+ int m, // [in ] precision of each dimension in bits
+ int n, // [in ] number of dimensions
+ const H &h // [out] Hilbert index
+ )
+{
+ // Intermediate variables will fit in fixed width?
+ if ( n <= FBV_BITS )
+ _indexToCoords<P,H,CFixBitVec>(p,m,n,h,CFixBitVec{});
+ // Otherwise, they must be BigBitVecs.
+ else
+ _indexToCoords<P,H,CBigBitVec>(p,m,n,h,CBigBitVec(n));
+
+ return;
+}
- template <class P,class HC,class I>
- inline
- void
- _coordsToCompactIndex(
- const P *p,
- const int *ms,
- int n,
- HC &hc,
- I&& scratch,
- int M = 0,
- int m = 0
- )
- {
- int i, mn;
- int *ds;
+template <class P,class HC,class I>
+inline
+void
+_coordsToCompactIndex(
+ const P *p,
+ const int *ms,
+ int n,
+ HC &hc,
+ I&& scratch,
+ int M = 0,
+ int m = 0
+ )
+{
+ int i, mn;
+ int *ds;
- // Get total precision and max precision
- // if not supplied
- if ( M == 0 || m == 0 )
+ // Get total precision and max precision
+ // if not supplied
+ if ( M == 0 || m == 0 )
+ {
+ M = m = 0;
+ for ( i = 0; i < n; i++ )
{
- M = m = 0;
- for ( i = 0; i < n; i++ )
- {
- if ( ms[i] > m ) m = ms[i];
- M += ms[i];
- }
+ if ( ms[i] > m ) m = ms[i];
+ M += ms[i];
}
+ }
- mn = m*n;
+ mn = m*n;
- // If we could avoid allocation altogether (ie: have a
- // fixed buffer allocated on the stack) then this increases
- // speed by a bit (4% when n=4, m=20)
- ds = new int [ m ];
+ // If we could avoid allocation altogether (ie: have a
+ // fixed buffer allocated on the stack) then this increases
+ // speed by a bit (4% when n=4, m=20)
+ ds = new int [ m ];
- if ( mn > FBV_BITS )
- {
- CBigBitVec h(mn);
- _coordsToIndex<P,CBigBitVec,I>(p,m,n,h,std::move(scratch),ds);
- compactIndex<CBigBitVec,HC>(ms,ds,n,m,h,hc);
- }
- else
- {
- CFixBitVec h;
- _coordsToIndex<P,CFixBitVec,I>(p,m,n,h,std::move(scratch),ds);
- compactIndex<CFixBitVec,HC>(ms,ds,n,m,h,hc);
- }
-
- delete [] ds;
-
- return;
+ if ( mn > FBV_BITS )
+ {
+ CBigBitVec h(mn);
+ _coordsToIndex<P,CBigBitVec,I>(p,m,n,h,std::move(scratch),ds);
+ compactIndex<CBigBitVec,HC>(ms,ds,n,m,h,hc);
}
-
- // This is wrapper to the basic Hilbert curve index
- // calculation function. It will support fixed or
- // arbitrary precision, templated. Depending on the
- // number of dimensions, it will use the most efficient
- // representation for interim variables.
- // Assumes h is big enough for the output (n*m bits!)
- template<class P,class HC>
- inline
- void
- coordsToCompactIndex(
- const P *p, // [in ] point
- const int *ms,// [in ] precision of each dimension in bits
- int n, // [in ] number of dimensions
- HC &hc, // [out] Hilbert index
- int M = 0,
- int m = 0
- )
+ else
{
- // Intermediate variables will fit in fixed width?
- if ( n <= FBV_BITS )
- _coordsToCompactIndex<P,HC,CFixBitVec>(p,ms,n,hc,CFixBitVec{},M,m);
- // Otherwise, they must be BigBitVecs.
- else
- _coordsToCompactIndex<P,HC,CBigBitVec>(p,ms,n,hc,CBigBitVec(n),M,m);
-
- return;
+ CFixBitVec h;
+ _coordsToIndex<P,CFixBitVec,I>(p,m,n,h,std::move(scratch),ds);
+ compactIndex<CFixBitVec,HC>(ms,ds,n,m,h,hc);
}
- template <class P,class HC,class I>
- inline
- void
- _compactIndexToCoords(
- P *p,
- const int *ms,
- int n,
- const HC &hc,
- I&& scratch,
- int M = 0,
- int m = 0
- )
+ delete [] ds;
+
+ return;
+}
+
+// This is wrapper to the basic Hilbert curve index
+// calculation function. It will support fixed or
+// arbitrary precision, templated. Depending on the
+// number of dimensions, it will use the most efficient
+// representation for interim variables.
+// Assumes h is big enough for the output (n*m bits!)
+template<class P,class HC>
+inline
+void
+coordsToCompactIndex(
+ const P *p, // [in ] point
+ const int *ms,// [in ] precision of each dimension in bits
+ int n, // [in ] number of dimensions
+ HC &hc, // [out] Hilbert index
+ int M = 0,
+ int m = 0
+ )
+{
+ // Intermediate variables will fit in fixed width?
+ if ( n <= FBV_BITS )
+ _coordsToCompactIndex<P,HC,CFixBitVec>(p,ms,n,hc,CFixBitVec{},M,m);
+ // Otherwise, they must be BigBitVecs.
+ else
+ _coordsToCompactIndex<P,HC,CBigBitVec>(p,ms,n,hc,CBigBitVec(n),M,m);
+
+ return;
+}
+
+template <class P,class HC,class I>
+inline
+void
+_compactIndexToCoords(
+ P *p,
+ const int *ms,
+ int n,
+ const HC &hc,
+ I&& scratch,
+ int M = 0,
+ int m = 0
+ )
+{
+ I e{std::move(scratch)};
+ I l{e};
+ I t{e};
+ I w{e};
+ I r{e};
+ I mask{e};
+ I ptrn{e};
+
+ int d, i, j, b;
+
+ // Get total precision and max precision
+ // if not supplied
+ if ( M == 0 || m == 0 )
{
- I e{std::move(scratch)};
- I l{e};
- I t{e};
- I w{e};
- I r{e};
- I mask{e};
- I ptrn{e};
-
- int d, i, j, b;
-
- // Get total precision and max precision
- // if not supplied
- if ( M == 0 || m == 0 )
+ M = m = 0;
+ for ( i = 0; i < n; i++ )
{
- M = m = 0;
- for ( i = 0; i < n; i++ )
- {
- if ( ms[i] > m ) m = ms[i];
- M += ms[i];
- }
+ if ( ms[i] > m ) m = ms[i];
+ M += ms[i];
}
+ }
- // Initialize
- e.reset();
- d = D0;
- l.reset();
- for ( j = 0; j < n; j++ )
- p[j] = 0;
+ // Initialize
+ e.reset();
+ d = D0;
+ l.reset();
+ for ( j = 0; j < n; j++ )
+ p[j] = 0;
- // Work from MSB to LSB
- for ( i = m-1; i >= 0; i-- )
- {
- // Get the mask and ptrn
- extractMask<I>(ms,n,d,i,mask,b);
- ptrn = e;
- ptrn.rotr(d,n);//#D ptrn.Rotr(d+1,n);
-
- // Get the Hilbert index bits
- M -= b;
- r.reset(); // GetBits doesn't do this
- getBits<HC,I>(hc,b,M,r);
-
- // w = GrayCodeRankInv(r)
- // t = GrayCode(w)
- grayCodeRankInv<I>(mask,ptrn,r,n,b,t,w);
-
- // Reverse the transform
- // l = T^{-1}_{(e,d)}(t)
- l = t;
- transformInv<I>(e,d,n,l);
-
- // Distribute these bits
- // to the coordinates.
- setLocation<P,I>(p,n,i,l);
-
- // Update the entry point and direction.
- update1<I>(l,t,w,n,e,d);
- }
-
- return;
+ // Work from MSB to LSB
+ for ( i = m-1; i >= 0; i-- )
+ {
+ // Get the mask and ptrn
+ extractMask<I>(ms,n,d,i,mask,b);
+ ptrn = e;
+ ptrn.rotr(d,n);//#D ptrn.Rotr(d+1,n);
+
+ // Get the Hilbert index bits
+ M -= b;
+ r.reset(); // GetBits doesn't do this
+ getBits<HC,I>(hc,b,M,r);
+
+ // w = GrayCodeRankInv(r)
+ // t = GrayCode(w)
+ grayCodeRankInv<I>(mask,ptrn,r,n,b,t,w);
+
+ // Reverse the transform
+ // l = T^{-1}_{(e,d)}(t)
+ l = t;
+ transformInv<I>(e,d,n,l);
+
+ // Distribute these bits
+ // to the coordinates.
+ setLocation<P,I>(p,n,i,l);
+
+ // Update the entry point and direction.
+ update1<I>(l,t,w,n,e,d);
}
- // This is wrapper to the basic Hilbert curve inverse
- // index function. It will support fixed or
- // arbitrary precision, templated. Depending on the
- // number of dimensions, it will use the most efficient
- // representation for interim variables.
- // Assumes each entry of p is big enough to hold the
- // appropriate variable.
- template<class P,class HC>
- inline
- void
- compactIndexToCoords(
- P *p, // [out] point
- const int *ms,// [in ] precision of each dimension in bits
- int n, // [in ] number of dimensions
- const HC &hc, // [out] Hilbert index
- int M = 0,
- int m = 0
- )
- {
- // Intermediate variables will fit in fixed width?
- if ( n <= FBV_BITS ) {
- CFixBitVec scratch;
- _compactIndexToCoords<P,HC,CFixBitVec>(p,ms,n,hc,CFixBitVec{},M,m);
- // Otherwise, they must be BigBitVecs.
- } else {
- CBigBitVec scratch(n);
- _compactIndexToCoords<P,HC,CBigBitVec>(p,ms,n,hc,std::move(scratch),M,m);
- }
+ return;
+}
- return;
+// This is wrapper to the basic Hilbert curve inverse
+// index function. It will support fixed or
+// arbitrary precision, templated. Depending on the
+// number of dimensions, it will use the most efficient
+// representation for interim variables.
+// Assumes each entry of p is big enough to hold the
+// appropriate variable.
+template<class P,class HC>
+inline
+void
+compactIndexToCoords(
+ P *p, // [out] point
+ const int *ms,// [in ] precision of each dimension in bits
+ int n, // [in ] number of dimensions
+ const HC &hc, // [out] Hilbert index
+ int M = 0,
+ int m = 0
+ )
+{
+ // Intermediate variables will fit in fixed width?
+ if ( n <= FBV_BITS ) {
+ CFixBitVec scratch;
+ _compactIndexToCoords<P,HC,CFixBitVec>(p,ms,n,hc,CFixBitVec{},M,m);
+ // Otherwise, they must be BigBitVecs.
+ } else {
+ CBigBitVec scratch(n);
+ _compactIndexToCoords<P,HC,CBigBitVec>(p,ms,n,hc,std::move(scratch),M,m);
}
+ return;
+}
+
}