Added "no-op" compressor (to allow compression to be disabled...)

This commit is contained in:
Sears Russell 2008-03-08 07:43:53 +00:00
parent e8490c8b8a
commit 893c1afee9
5 changed files with 120 additions and 6 deletions

View file

@ -20,19 +20,20 @@ int main(int argc, char **argv) {
typedef rose::StaticTuple<COLS,typ0,typ1,typ2,typ3,typ4,typ5,typ6,typ7,typ8,typ9> tup;
using rose::For;
using rose::Rle;
using rose::Nop;
int ret;
// multicolumn is deprecated; want static dispatch!
rose::plugin_id_t * plugins = (rose::plugin_id_t*)malloc(10 * sizeof(rose::plugin_id_t));
plugins[0] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ0>, typ0>();
plugins[1] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ1>, typ1>();
plugins[1] = rose::plugin_id<rose::Multicolumn<tup>, Nop<typ1>, typ1>(); // rle
plugins[2] = rose::plugin_id<rose::Multicolumn<tup>, For<typ2>, typ2>();
plugins[3] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ3>, typ3>();
plugins[4] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ4>, typ4>();
plugins[4] = rose::plugin_id<rose::Multicolumn<tup>, Nop<typ4>, typ4>(); // rle
plugins[5] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ5>, typ5>();
plugins[6] = rose::plugin_id<rose::Multicolumn<tup>, For<typ6>, typ6>();
plugins[7] = rose::plugin_id<rose::Multicolumn<tup>, For<typ7>, typ7>();
plugins[7] = rose::plugin_id<rose::Multicolumn<tup>, Nop<typ7>, typ7>(); // for
plugins[8] = rose::plugin_id<rose::Multicolumn<tup>, For<typ8>, typ8>();
plugins[9] = rose::plugin_id<rose::Multicolumn<tup>, Rle<typ9>, typ9>();

View file

@ -60,11 +60,11 @@ inline plugin_id_t plugin_id() {
// assert(sizeof(TYPE) <= 8 && type_idx[sizeof(TYPE)] >= 0);
// XXX first '2' hardcodes the number of COMPRESSOR implementations...
// XXX '3' hardcodes the number of COMPRESSOR implementations...
plugin_id_t ret = USER_DEFINED_PAGE(0)
// II S C
+ idx_count * 2 * 2 * PAGEFORMAT::PAGE_FORMAT_ID
+ idx_count * 2 * 3 * PAGEFORMAT::PAGE_FORMAT_ID
+ idx_count * 2 * COMPRESSOR::PLUGIN_ID
+ idx_count * (is_signed < 0)
+ type_idx[sizeof(TYPE)];

View file

@ -0,0 +1,103 @@
#ifndef _ROSE_COMPRESSION_NOP_H__
#define _ROSE_COMPRESSION_NOP_H__
#undef try
#undef catch
#undef end
#include <algorithm>
/**
@file A 'no-op' compression implementation
This file implements a COMPRESSOR plugin that stores data in
uncompressed form.
*/
#include <limits.h>
#include "pstar.h"
namespace rose {
template <class TYPE> class Nop {
public:
typedef TYPE TYP;
static const int PLUGIN_ID = 2;
inline void offset(TYPE o) {}
inline size_t max_overrun() { return 0; }
inline slot_index_t append(int xid, const TYPE dat, byte_off_t * except,
byte * exceptions, int *free_bytes) {
if(*free_bytes >= (int)sizeof(TYPE)) {
slot_index_t ret = *numentries_ptr();
((TYPE*)(numentries_ptr()+1))[ret] = dat;
(*free_bytes)-=sizeof(TYPE);
(*numentries_ptr())++;
return ret;
} else {
return NOSPACE;
}
}
inline TYPE *recordRead(int xid, slot_index_t slot, byte *exceptions,
TYPE *buf) {
if(slot < *numentries_ptr()) {
*buf = ((TYPE*)(numentries_ptr()+1))[slot];
return buf;
} else {
return 0;
}
}
inline std::pair<slot_index_t,slot_index_t>*
recordFind(int xid, slot_index_t start, slot_index_t stop,
byte *exceptions, TYPE value,
std::pair<slot_index_t,slot_index_t>& scratch) {
slot_index_t i;
std::pair<slot_index_t,slot_index_t>*ret = 0;
TYPE *rec = 0;
for(i = start; i< stop; i++) {
TYPE t;
rec = recordRead(xid,i,0,&t);
if(*rec == value) {
scratch.first = i;
scratch.second = stop;
ret = &scratch;
i++;
break;
}
}
for(;i<stop; i++) {
TYPE t;
TYPE *rec = recordRead(xid,i,0,&t);
if(*rec != value) {
scratch.second = i;
break;
}
}
return ret;
}
Nop(int xid, void * mem): mem_(mem) {
*numentries_ptr() = 0;
}
Nop(void * mem): mem_(mem) { }
Nop() : mem_(0) {}
inline slot_index_t recordCount() {
return *numentries_ptr();
}
inline byte_off_t bytes_used() {return sizeof(slot_index_t) + ( *numentries_ptr() * sizeof(TYPE) ); }
inline void mem(byte * mem) { mem_=mem; }
inline void init_mem(byte* mem) {
mem_=mem;
*numentries_ptr() = 0;
}
private:
inline slot_index_t* numentries_ptr() {
return reinterpret_cast<slot_index_t*>(mem_);
}
void * mem_;
};
}
#endif

View file

@ -45,7 +45,8 @@ class PluginDispatcher{
public:
#define dispatchSwitch(col,cases,...) \
static const int base = USER_DEFINED_PAGE(0) + 2 * 2 * 4;\
static const int base = USER_DEFINED_PAGE(0) + 3 * 2 * 4;\
/*printf("page = %d pluginid = %d base = %d\n", USER_DEFINED_PAGE(0), plugin_ids_[col], base); fflush(stdout);*/ \
switch(plugin_ids_[col]-base) { \
cases(0, For<uint8_t>, col,uint8_t, __VA_ARGS__); \
cases(1, For<uint16_t>,col,uint16_t,__VA_ARGS__); \
@ -63,6 +64,14 @@ class PluginDispatcher{
cases(13,Rle<int16_t>, col,int16_t, __VA_ARGS__); \
cases(14,Rle<int32_t>, col,int32_t, __VA_ARGS__); \
cases(15,Rle<int64_t>, col,int64_t, __VA_ARGS__); \
cases(16,Nop<uint8_t>, col,uint8_t, __VA_ARGS__); \
cases(17,Nop<uint16_t>,col,uint16_t,__VA_ARGS__); \
cases(18,Nop<uint32_t>,col,uint32_t,__VA_ARGS__); \
cases(19,Nop<uint64_t>,col,uint64_t,__VA_ARGS__); \
cases(20,Nop<int8_t>, col,int8_t, __VA_ARGS__); \
cases(21,Nop<int16_t>, col,int16_t, __VA_ARGS__); \
cases(22,Nop<int32_t>, col,int32_t, __VA_ARGS__); \
cases(23,Nop<int64_t>, col,int64_t, __VA_ARGS__); \
default: abort(); \
};

View file

@ -15,6 +15,7 @@
#include "compression.h"
#include "for.h"
#include "rle.h"
#include "nop.h"
#include "string.h"
namespace rose {