aboutsummaryrefslogtreecommitdiffstats
path: root/chilbert/Algorithm.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-07 17:28:27 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:45:39 +0200
commit0bcaa46d0fb0af324fc2991ddcdf3d34c594f741 (patch)
treed8b88814da73b82980a25d0548ac6c0b823dbdc8 /chilbert/Algorithm.hpp
parent1f689397601b53f51f7be973f8f952d0dec408da (diff)
downloadchilbert-0bcaa46d0fb0af324fc2991ddcdf3d34c594f741.tar.gz
chilbert-0bcaa46d0fb0af324fc2991ddcdf3d34c594f741.tar.bz2
chilbert-0bcaa46d0fb0af324fc2991ddcdf3d34c594f741.zip
Raise responsibility of allocating scratch
Use copy constructors instead of size-based initialization in deeper methods instead. This avoids the assumption that the types take a dynamic size parameter.
Diffstat (limited to 'chilbert/Algorithm.hpp')
-rw-r--r--chilbert/Algorithm.hpp52
1 files changed, 36 insertions, 16 deletions
diff --git a/chilbert/Algorithm.hpp b/chilbert/Algorithm.hpp
index cee638a..bd4a9a1 100644
--- a/chilbert/Algorithm.hpp
+++ b/chilbert/Algorithm.hpp
@@ -149,10 +149,14 @@ namespace chilbert
int m,
int n,
H &h,
+ I&& scratch,
int *ds = nullptr // #HACK
)
{
- I e(n), l(n), t(n), w(n);
+ I e{std::move(scratch)};
+ I l{e};
+ I t{e};
+ I w{e};
int d, i;
int ho = m*n;
@@ -211,10 +215,10 @@ namespace chilbert
{
// Intermediate variables will fit in fixed width?
if ( n <= FBV_BITS )
- _coordsToIndex<P,H,CFixBitVec>(p,m,n,h);
+ _coordsToIndex<P,H,CFixBitVec>(p,m,n,h, CFixBitVec{});
// Otherwise, they must be BigBitVecs.
else
- _coordsToIndex<P,H,CBigBitVec>(p,m,n,h);
+ _coordsToIndex<P,H,CBigBitVec>(p,m,n,h, CBigBitVec(n));
return;
}
@@ -227,10 +231,14 @@ namespace chilbert
P *p,
int m,
int n,
- const H &h
+ const H &h,
+ I&& scratch
)
{
- I e(n), l(n), t(n), w(n);
+ I e{std::move(scratch)};
+ I l{e};
+ I t{e};
+ I w{e};
int d, i, j, ho;
// Initialize
@@ -288,10 +296,10 @@ namespace chilbert
{
// Intermediate variables will fit in fixed width?
if ( n <= FBV_BITS )
- _indexToCoords<P,H,CFixBitVec>(p,m,n,h);
+ _indexToCoords<P,H,CFixBitVec>(p,m,n,h,CFixBitVec{});
// Otherwise, they must be BigBitVecs.
else
- _indexToCoords<P,H,CBigBitVec>(p,m,n,h);
+ _indexToCoords<P,H,CBigBitVec>(p,m,n,h,CBigBitVec(n));
return;
}
@@ -304,6 +312,7 @@ namespace chilbert
const int *ms,
int n,
HC &hc,
+ I&& scratch,
int M = 0,
int m = 0
)
@@ -333,13 +342,13 @@ namespace chilbert
if ( mn > FBV_BITS )
{
CBigBitVec h(mn);
- _coordsToIndex<P,CBigBitVec,I>(p,m,n,h,ds);
+ _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,ds);
+ _coordsToIndex<P,CFixBitVec,I>(p,m,n,h,std::move(scratch),ds);
compactIndex<CFixBitVec,HC>(ms,ds,n,m,h,hc);
}
@@ -368,10 +377,10 @@ namespace chilbert
{
// Intermediate variables will fit in fixed width?
if ( n <= FBV_BITS )
- _coordsToCompactIndex<P,HC,CFixBitVec>(p,ms,n,hc,M,m);
+ _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,M,m);
+ _coordsToCompactIndex<P,HC,CBigBitVec>(p,ms,n,hc,CBigBitVec(n),M,m);
return;
}
@@ -384,11 +393,19 @@ namespace chilbert
const int *ms,
int n,
const HC &hc,
+ I&& scratch,
int M = 0,
int m = 0
)
{
- I e(n), l(n), t(n), w(n), r(n), mask(n), ptrn(n);
+ 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
@@ -463,11 +480,14 @@ namespace chilbert
)
{
// Intermediate variables will fit in fixed width?
- if ( n <= FBV_BITS )
- _compactIndexToCoords<P,HC,CFixBitVec>(p,ms,n,hc,M,m);
+ if ( n <= FBV_BITS ) {
+ CFixBitVec scratch;
+ _compactIndexToCoords<P,HC,CFixBitVec>(p,ms,n,hc,CFixBitVec{},M,m);
// Otherwise, they must be BigBitVecs.
- else
- _compactIndexToCoords<P,HC,CBigBitVec>(p,ms,n,hc,M,m);
+ } else {
+ CBigBitVec scratch(n);
+ _compactIndexToCoords<P,HC,CBigBitVec>(p,ms,n,hc,std::move(scratch),M,m);
+ }
return;
}