aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chilbert/Algorithm.hpp52
-rw-r--r--chilbert/FixBitVec.hpp2
-rw-r--r--test/test_fsb.cpp10
3 files changed, 42 insertions, 22 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;
}
diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp
index bea1c1a..d8fee9a 100644
--- a/chilbert/FixBitVec.hpp
+++ b/chilbert/FixBitVec.hpp
@@ -62,7 +62,7 @@ public:
// Returns the current size in bits.
int
- size()
+ size() const
{
return FBV_BITS;
}
diff --git a/test/test_fsb.cpp b/test/test_fsb.cpp
index 473438f..c55d9cb 100644
--- a/test/test_fsb.cpp
+++ b/test/test_fsb.cpp
@@ -26,11 +26,11 @@ using namespace chilbert;
template <typename T>
int
-test_fsb(const int size)
+test_fsb(const T& empty_field)
{
- for (int i = 0; i < size; ++i) {
- T field{size};
- field.reset();
+ assert(empty_field.none());
+ for (int i = 0; i < empty_field.size(); ++i) {
+ T field = empty_field;
field.set(i);
assert(field.fsb() == i + 1);
}
@@ -41,5 +41,5 @@ test_fsb(const int size)
int
main()
{
- return test_fsb<CFixBitVec>(FBV_BITS) || test_fsb<CBigBitVec>(1024);
+ return test_fsb(CFixBitVec{}) || test_fsb(CBigBitVec{1024});
}