X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=cds%2Fopt%2Fbuffer.h;h=2623069eca3d967a69a33e0fcbd82422e8d22f4e;hp=90d79478cfe85e5b59d4076f6b07a6a13bc2e4c3;hb=HEAD;hpb=d15c6730bbd5f63f903496277939b7fe18ac9853
diff --git a/cds/opt/buffer.h b/cds/opt/buffer.h
index 90d79478..2623069e 100644
--- a/cds/opt/buffer.h
+++ b/cds/opt/buffer.h
@@ -176,8 +176,8 @@ namespace cds { namespace opt {
/// Returns idx % capacity()
/**
- If the buffer size is a power of two, binary arithmethics is used
- instead of modulo arithmetics
+ If the buffer size is a power of two, binary arithmethics is used
+ instead of modulo arithmetics
*/
size_t mod( size_t idx )
{
@@ -186,6 +186,17 @@ namespace cds { namespace opt {
else
return idx % capacity();
}
+
+ //@cond
+ template
+ typename std::enable_if< sizeof(I) != sizeof(size_t), size_t >::type mod( I idx )
+ {
+ static_if( c_bExp2 )
+ return static_cast( idx & static_cast( capacity() - 1 ));
+ else
+ return static_cast( idx % capacity());
+ }
+ //@endcond
};
/// Static initialized buffer
@@ -291,6 +302,17 @@ namespace cds { namespace opt {
else
return idx % capacity();
}
+
+ //@cond
+ template
+ typename std::enable_if< sizeof( I ) != sizeof( size_t ), size_t >::type mod( I idx )
+ {
+ static_if( c_bExp2 )
+ return static_cast( idx & static_cast( capacity() - 1 ));
+ else
+ return static_cast( idx % capacity());
+ }
+ //@endcond
};
/// Dynamically allocated uninitialized buffer
@@ -406,6 +428,17 @@ namespace cds { namespace opt {
else
return idx % capacity();
}
+
+ //@cond
+ template
+ typename std::enable_if< sizeof( I ) != sizeof( size_t ), size_t >::type mod( I idx )
+ {
+ static_if ( c_bExp2 )
+ return static_cast( idx & static_cast( capacity() - 1 ));
+ else
+ return static_cast( idx % capacity());
+ }
+ //@endcond
};
@@ -523,6 +556,17 @@ namespace cds { namespace opt {
else
return idx % capacity();
}
+
+ //@cond
+ template
+ typename std::enable_if< sizeof( I ) != sizeof( size_t ), size_t >::type mod( I idx )
+ {
+ static_if( c_bExp2 )
+ return static_cast( idx & static_cast( capacity() - 1 ));
+ else
+ return static_cast( idx % capacity());
+ }
+ //@endcond
};
} // namespace v