DVE2: Use mspool for compressed states.
* iface/dve2/dve2.cc: Adjust to use the new mspool allocator, and get rid of the std::vector used to store compressed states. * src/misc/intvcomp.hh: Add an "int* -> int*" interface in addition to the "int* -> vector<unsigned>*" interface. * src/tgbatest/intvcomp.cc: Test the two interfaces.
This commit is contained in:
parent
56e487d468
commit
ebb85c4da7
4 changed files with 271 additions and 80 deletions
|
|
@ -183,11 +183,11 @@ namespace spot
|
|||
unsigned int bits_left_;
|
||||
};
|
||||
|
||||
class int_array_compression:
|
||||
public stream_compression_base<int_array_compression>
|
||||
class int_array_vector_compression:
|
||||
public stream_compression_base<int_array_vector_compression>
|
||||
{
|
||||
public:
|
||||
int_array_compression(int* array, size_t n)
|
||||
int_array_vector_compression(const int* array, size_t n)
|
||||
: array_(array), n_(n), pos_(0), result_(new std::vector<unsigned int>)
|
||||
{
|
||||
}
|
||||
|
|
@ -226,20 +226,78 @@ namespace spot
|
|||
}
|
||||
|
||||
protected:
|
||||
int* array_;
|
||||
const int* array_;
|
||||
size_t n_;
|
||||
size_t pos_;
|
||||
std::vector<unsigned int>* result_;
|
||||
};
|
||||
|
||||
const std::vector<unsigned int>*
|
||||
int_array_compress(int* array, unsigned int n)
|
||||
class int_array_array_compression:
|
||||
public stream_compression_base<int_array_array_compression>
|
||||
{
|
||||
int_array_compression c(array, n);
|
||||
public:
|
||||
int_array_array_compression(const int* array, size_t n,
|
||||
int* dest, size_t& dest_n)
|
||||
: array_(array), n_(n), pos_(0),
|
||||
result_size_(dest_n), result_(dest), result_end_(dest + dest_n)
|
||||
{
|
||||
result_size_ = 0; // this resets dest_n.
|
||||
}
|
||||
|
||||
void push_data(unsigned int i)
|
||||
{
|
||||
assert(result_ < result_end_);
|
||||
++result_size_;
|
||||
*result_++ = static_cast<int>(i);
|
||||
}
|
||||
|
||||
bool have_data() const
|
||||
{
|
||||
return pos_ < n_;
|
||||
}
|
||||
|
||||
unsigned int next_data()
|
||||
{
|
||||
return static_cast<unsigned int>(array_[pos_++]);
|
||||
}
|
||||
|
||||
bool skip_if(unsigned int val)
|
||||
{
|
||||
if (!have_data())
|
||||
return false;
|
||||
|
||||
if (static_cast<unsigned int>(array_[pos_]) != val)
|
||||
return false;
|
||||
|
||||
++pos_;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
const int* array_;
|
||||
size_t n_;
|
||||
size_t pos_;
|
||||
size_t& result_size_;
|
||||
int* result_;
|
||||
int* result_end_;
|
||||
};
|
||||
|
||||
const std::vector<unsigned int>*
|
||||
int_array_vector_compress(const int* array, size_t n)
|
||||
{
|
||||
int_array_vector_compression c(array, n);
|
||||
c.run();
|
||||
return c.result();
|
||||
}
|
||||
|
||||
void
|
||||
int_array_array_compress(const int* array, size_t n,
|
||||
int* dest, size_t& dest_size)
|
||||
{
|
||||
int_array_array_compression c(array, n, dest, dest_size);
|
||||
c.run();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Self>
|
||||
|
|
@ -394,12 +452,13 @@ namespace spot
|
|||
unsigned int buffer_mask_;
|
||||
};
|
||||
|
||||
class int_array_decompression:
|
||||
public stream_decompression_base<int_array_decompression>
|
||||
class int_vector_array_decompression:
|
||||
public stream_decompression_base<int_vector_array_decompression>
|
||||
{
|
||||
public:
|
||||
int_array_decompression(const std::vector<unsigned int>* array, int* res,
|
||||
size_t size)
|
||||
int_vector_array_decompression(const std::vector<unsigned int>* array,
|
||||
int* res,
|
||||
size_t size)
|
||||
: prev_(0), array_(array), n_(array->size()), pos_(0), result_(res),
|
||||
size_(size)
|
||||
{
|
||||
|
|
@ -443,11 +502,70 @@ namespace spot
|
|||
size_t size_;
|
||||
};
|
||||
|
||||
void
|
||||
int_array_decompress(const std::vector<unsigned int>* array, int* res,
|
||||
size_t size)
|
||||
class int_array_array_decompression:
|
||||
public stream_decompression_base<int_array_array_decompression>
|
||||
{
|
||||
int_array_decompression c(array, res, size);
|
||||
public:
|
||||
int_array_array_decompression(const int* array,
|
||||
size_t array_size,
|
||||
int* res,
|
||||
size_t size)
|
||||
: prev_(0), array_(array), n_(array_size), pos_(0), result_(res),
|
||||
size_(size)
|
||||
{
|
||||
}
|
||||
|
||||
bool complete() const
|
||||
{
|
||||
return size_ == 0;
|
||||
}
|
||||
|
||||
void push_data(int i)
|
||||
{
|
||||
prev_ = i;
|
||||
*result_++ = i;
|
||||
--size_;
|
||||
}
|
||||
|
||||
void repeat(unsigned int i)
|
||||
{
|
||||
size_ -= i;
|
||||
while (i--)
|
||||
*result_++ = prev_;
|
||||
}
|
||||
|
||||
bool have_comp_data() const
|
||||
{
|
||||
return pos_ < n_;
|
||||
}
|
||||
|
||||
unsigned int next_comp_data()
|
||||
{
|
||||
return array_[pos_++];
|
||||
}
|
||||
|
||||
protected:
|
||||
int prev_;
|
||||
const int* array_;
|
||||
size_t n_;
|
||||
size_t pos_;
|
||||
int* result_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
void
|
||||
int_vector_array_decompress(const std::vector<unsigned int>* array, int* res,
|
||||
size_t size)
|
||||
{
|
||||
int_vector_array_decompression c(array, res, size);
|
||||
c.run();
|
||||
}
|
||||
|
||||
void
|
||||
int_array_array_decompress(const int* array, size_t array_size,
|
||||
int* res, size_t size)
|
||||
{
|
||||
int_array_array_decompression c(array, array_size, res, size);
|
||||
c.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,31 +22,32 @@
|
|||
#include "misc/intvcomp.hh"
|
||||
#include <cstring>
|
||||
|
||||
int check(int* comp, int size, unsigned expected = 0)
|
||||
int check_av(int* data, int size, unsigned expected = 0)
|
||||
{
|
||||
const std::vector<unsigned int>* v = spot::int_array_compress(comp, size);
|
||||
const std::vector<unsigned int>* v =
|
||||
spot::int_array_vector_compress(data, size);
|
||||
|
||||
std::cout << "C[" << v->size() << "] ";
|
||||
std::cout << "VC[" << v->size() << "] ";
|
||||
for (size_t i = 0; i < v->size(); ++i)
|
||||
std::cout << (*v)[i] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
int* decomp = new int[size];
|
||||
spot::int_array_decompress(v, decomp, size);
|
||||
spot::int_vector_array_decompress(v, decomp, size);
|
||||
|
||||
std::cout << "D[" << size << "] ";
|
||||
std::cout << "VD[" << size << "] ";
|
||||
for (int i = 0; i < size; ++i)
|
||||
std::cout << decomp[i] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
int res = memcmp(comp, decomp, size * sizeof(int));
|
||||
int res = memcmp(data, decomp, size * sizeof(int));
|
||||
|
||||
if (res)
|
||||
{
|
||||
std::cout << "*** cmp error *** " << res << std::endl;
|
||||
std::cout << "E[" << size << "] ";
|
||||
std::cout << "VE[" << size << "] ";
|
||||
for (int i = 0; i < size; ++i)
|
||||
std::cout << comp[i] << " ";
|
||||
std::cout << data[i] << " ";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +66,56 @@ int check(int* comp, int size, unsigned expected = 0)
|
|||
return !!res;
|
||||
}
|
||||
|
||||
int check_aa(int* data, int size, unsigned expected = 0)
|
||||
{
|
||||
int* comp = new int[size *2];
|
||||
size_t csize = size * 2;
|
||||
spot::int_array_array_compress(data, size, comp, csize);
|
||||
|
||||
std::cout << "AC[" << csize << "] ";
|
||||
for (size_t i = 0; i < csize; ++i)
|
||||
std::cout << comp[i] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
int* decomp = new int[size];
|
||||
spot::int_array_array_decompress(comp, csize, decomp, size);
|
||||
|
||||
std::cout << "AD[" << size << "] ";
|
||||
for (int i = 0; i < size; ++i)
|
||||
std::cout << decomp[i] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
int res = memcmp(data, decomp, size * sizeof(int));
|
||||
|
||||
if (res)
|
||||
{
|
||||
std::cout << "*** cmp error *** " << res << std::endl;
|
||||
std::cout << "AE[" << size << "] ";
|
||||
for (int i = 0; i < size; ++i)
|
||||
std::cout << data[i] << " ";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if (expected && (csize * sizeof(int) != expected))
|
||||
{
|
||||
std::cout << "*** size error *** (expected "
|
||||
<< expected << " bytes, got " << csize * sizeof(int)
|
||||
<< " bytes)" << std::endl;
|
||||
res = 1;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
delete[] comp;
|
||||
delete[] decomp;
|
||||
return !!res;
|
||||
}
|
||||
|
||||
int check(int* comp, int size, unsigned expected = 0)
|
||||
{
|
||||
return check_av(comp, size, expected) + check_aa(comp, size, expected);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int errors = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue