added optional template arguments to FOR and RLE to let callers specify the size of delta_t and copy_count_t, resepectively.

This commit is contained in:
Sears Russell 2008-10-27 23:35:51 +00:00
parent 0ff6196776
commit 0a551720c8
4 changed files with 23 additions and 29 deletions

View file

@ -11,9 +11,9 @@
#include "for.h"
namespace rose {
template <class TYPE>
template <class TYPE,class DELTA_TYPE>
inline void
For<TYPE>::offset(TYPE o) {
For<TYPE,DELTA_TYPE>::offset(TYPE o) {
assert(*numdeltas_ptr() == 0);
*base_ptr() = o;
}
@ -21,9 +21,9 @@ For<TYPE>::offset(TYPE o) {
Store a new value as a delta from the page's base offset, then update
numdeltas_ptr so that we remember that we stored the value.
*/
template <class TYPE>
template <class TYPE,class DELTA_TYPE>
inline slot_index_t
For<TYPE>::append(int xid, const TYPE dat,
For<TYPE,DELTA_TYPE>::append(int xid, const TYPE dat,
byte_off_t* except, byte* exceptions, //char *exceptional,
int *free_bytes) {
// Can dat be represented as a delta from the page's base value?
@ -68,9 +68,9 @@ For<TYPE>::append(int xid, const TYPE dat,
}
template <class TYPE>
template <class TYPE,class DELTA_TYPE>
inline TYPE *
For<TYPE>::recordRead(int xid, slot_index_t slot, byte *exceptions,
For<TYPE,DELTA_TYPE>::recordRead(int xid, slot_index_t slot, byte *exceptions,
TYPE * scratch) {
if (slot >= *numdeltas_ptr()) {
return 0;
@ -86,9 +86,9 @@ For<TYPE>::recordRead(int xid, slot_index_t slot, byte *exceptions,
}
#ifndef COMPRESSION_BINARY_FIND
template <class TYPE>
template <class TYPE,class DELTA_TYPE>
inline std::pair<slot_index_t,slot_index_t>*
For<TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
For<TYPE,DELTA_TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
byte *exceptions, TYPE value,
std::pair<slot_index_t,slot_index_t>& scratch) {
std::pair<slot_index_t,slot_index_t>* ret = 0;
@ -131,9 +131,9 @@ For<TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
return ret;
}
#else // COMPRESSION_BINARY_FIND
template <class TYPE>
template <class TYPE,class DELTA_TYPE>
inline std::pair<slot_index_t,slot_index_t>*
For<TYPE>::recordFind(int xid, slot_index_t low, slot_index_t high,
For<TYPE,DELTA_TYPE>::recordFind(int xid, slot_index_t low, slot_index_t high,
byte *exceptions, TYPE value,
std::pair<slot_index_t,slot_index_t>& scratch) {
delta_t delta = value - *base_ptr();

View file

@ -47,7 +47,7 @@
#include "pstar.h"
namespace rose {
template <class TYPE>
template <class TYPE, class DELTA_TYPE=int8_t>
class For {
public:
typedef TYPE TYP;
@ -150,15 +150,9 @@ class For {
private:
typedef int8_t delta_t;
static const delta_t DELTA_MAX = CHAR_MAX;
static const delta_t DELTA_MIN = CHAR_MIN;
/* typedef int16_t delta_t;
static const delta_t DELTA_MAX = SHRT_MAX;
static const delta_t DELTA_MIN = SHRT_MIN; */
/*typedef int32_t delta_t;
static const delta_t DELTA_MAX = INT_MAX;
static const delta_t DELTA_MIN = INT_MIN;*/
typedef DELTA_TYPE delta_t;
static const delta_t DELTA_MAX = (sizeof(delta_t) == 1) ? CHAR_MAX : (sizeof(delta_t) == 2) ? SHRT_MAX : INT_MAX;
static const delta_t DELTA_MIN = (sizeof(delta_t) == 1) ? CHAR_MIN : (sizeof(delta_t) == 2) ? SHRT_MIN : INT_MIN;
inline TYPE offset() { return *base_ptr(); }

View file

@ -18,9 +18,9 @@ namespace rose {
complexity comes from dealing with integer overflow, and running
out of space.
*/
template <class TYPE>
template <class TYPE, class COUNT_TYPE>
inline slot_index_t
Rle<TYPE>::append(int xid, const TYPE dat,
Rle<TYPE,COUNT_TYPE>::append(int xid, const TYPE dat,
byte_off_t* except, byte * exceptions, //char *exceptional,
int *free_bytes) {
int64_t ret;
@ -55,9 +55,9 @@ Rle<TYPE>::append(int xid, const TYPE dat,
return (slot_index_t)ret;
}
template <class TYPE>
template <class TYPE,class COUNT_TYPE>
inline TYPE *
Rle<TYPE>::recordRead(int xid, slot_index_t slot, byte* exceptions,
Rle<TYPE,COUNT_TYPE>::recordRead(int xid, slot_index_t slot, byte* exceptions,
TYPE * scratch) {
block_index_t n = nth_block_ptr(last_)->index <= slot ? last_ : 0;
do {
@ -103,9 +103,9 @@ Rle<TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
return ret;
}
#else // COMPRESSION_BINARY_FIND
template <class TYPE>
template <class TYPE,class COUNT_TYPE>
inline std::pair<slot_index_t,slot_index_t>*
Rle<TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
Rle<TYPE, COUNT_TYPE>::recordFind(int xid, slot_index_t start, slot_index_t stop,
byte *exceptions, TYPE value,
std::pair<slot_index_t,slot_index_t>& scratch) {

View file

@ -10,14 +10,14 @@
namespace rose {
template <class TYPE>
template <class TYPE, class COUNT_TYPE=uint16_t>
class Rle {
public:
/** XXX this stuff is performance critical; should be template param.*/
typedef byte_off_t block_index_t;
typedef uint8_t copy_count_t;
static const copy_count_t MAX_COPY_COUNT = UCHAR_MAX;
typedef COUNT_TYPE copy_count_t;
static const copy_count_t MAX_COPY_COUNT = (copy_count_t)-1;
typedef TYPE TYP;