Remove old io::FileWrite serialization code
This commit is contained in:
@@ -32,41 +32,6 @@ namespace serialization
|
||||
* All vector types with this guarantee should be placed in this file.
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
inline void read(storage::io::FileReader &reader, util::DeallocatingVector<T> &vec)
|
||||
{
|
||||
vec.current_size = reader.ReadElementCount64(vec.current_size);
|
||||
std::size_t num_blocks =
|
||||
std::ceil(vec.current_size / util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK);
|
||||
vec.bucket_list.resize(num_blocks);
|
||||
// Read all but the last block which can be partital
|
||||
for (auto bucket_index : util::irange<std::size_t>(0, num_blocks - 1))
|
||||
{
|
||||
vec.bucket_list[bucket_index] = new T[util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK];
|
||||
reader.ReadInto(vec.bucket_list[bucket_index],
|
||||
util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK);
|
||||
}
|
||||
std::size_t last_block_size =
|
||||
vec.current_size % util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK;
|
||||
vec.bucket_list.back() = new T[util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK];
|
||||
reader.ReadInto(vec.bucket_list.back(), last_block_size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void write(storage::io::FileWriter &writer, const util::DeallocatingVector<T> &vec)
|
||||
{
|
||||
writer.WriteElementCount64(vec.current_size);
|
||||
// Write all but the last block which can be partially filled
|
||||
for (auto bucket_index : util::irange<std::size_t>(0, vec.bucket_list.size() - 1))
|
||||
{
|
||||
writer.WriteFrom(vec.bucket_list[bucket_index],
|
||||
util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK);
|
||||
}
|
||||
std::size_t last_block_size =
|
||||
vec.current_size % util::DeallocatingVector<T>::ELEMENTS_PER_BLOCK;
|
||||
writer.WriteFrom(vec.bucket_list.back(), last_block_size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void read(storage::tar::FileReader &reader, const std::string& name, util::DeallocatingVector<T> &vec)
|
||||
{
|
||||
@@ -82,27 +47,18 @@ inline void write(storage::tar::FileWriter &writer, const std::string& name, con
|
||||
}
|
||||
|
||||
#if USE_STXXL_LIBRARY
|
||||
template <typename T> inline void read(storage::io::FileReader &reader, stxxl::vector<T> &vec)
|
||||
template <typename T> inline void read(storage::tar::FileReader &reader, const std::string& name, stxxl::vector<T> &vec)
|
||||
{
|
||||
auto size = reader.ReadElementCount64();
|
||||
auto size = reader.ReadElementCount64(name);
|
||||
vec.reserve(size);
|
||||
T tmp;
|
||||
for (auto idx : util::irange<std::size_t>(0, size))
|
||||
{
|
||||
(void)idx;
|
||||
reader.ReadInto(tmp);
|
||||
vec.push_back(tmp);
|
||||
}
|
||||
reader.ReadStreaming<T>(name, std::back_inserter(vec), size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void write(storage::io::FileWriter &writer, const stxxl::vector<T> &vec)
|
||||
inline void write(storage::tar::FileWriter &writer, const std::string& name, const stxxl::vector<T> &vec)
|
||||
{
|
||||
writer.WriteFrom(vec.size());
|
||||
for (auto idx : util::irange<std::size_t>(0, vec.size()))
|
||||
{
|
||||
writer.WriteFrom<T>(vec[idx]);
|
||||
}
|
||||
writer.WriteElementCount64(name, vec.size());
|
||||
writer.WriteStreaming<T>(name, vec.begin(), vec.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -168,34 +124,6 @@ void write(tar::FileWriter &writer, const std::string &name, const util::vector_
|
||||
writer.WriteFrom(name, data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void read(io::FileReader &reader, std::vector<T> &data)
|
||||
{
|
||||
const auto count = reader.ReadElementCount64();
|
||||
data.resize(count);
|
||||
reader.ReadInto(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void write(io::FileWriter &writer, const std::vector<T> &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
writer.WriteElementCount64(count);
|
||||
writer.WriteFrom(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void read(io::FileReader &reader, util::vector_view<T> &data)
|
||||
{
|
||||
const auto count = reader.ReadElementCount64();
|
||||
data.resize(count);
|
||||
reader.ReadInto(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void write(io::FileWriter &writer, const util::vector_view<T> &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
writer.WriteElementCount64(count);
|
||||
writer.WriteFrom(data.data(), count);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T>
|
||||
@@ -217,37 +145,6 @@ inline void unpackBits(T &data, std::size_t index, std::size_t count, unsigned c
|
||||
data[index] = value & mask;
|
||||
}
|
||||
|
||||
template <typename VectorT> void readBoolVector(io::FileReader &reader, VectorT &data)
|
||||
{
|
||||
const auto count = reader.ReadElementCount64();
|
||||
data.resize(count);
|
||||
std::uint64_t index = 0;
|
||||
unsigned char block_data;
|
||||
for (std::uint64_t next = CHAR_BIT; next < count; index = next, next += CHAR_BIT)
|
||||
{
|
||||
reader.ReadInto(block_data);
|
||||
unpackBits(data, index, CHAR_BIT, block_data);
|
||||
}
|
||||
if (count > index)
|
||||
{
|
||||
reader.ReadInto(block_data);
|
||||
unpackBits(data, index, count - index, block_data);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VectorT> void writeBoolVector(io::FileWriter &writer, const VectorT &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
writer.WriteElementCount64(count);
|
||||
std::uint64_t index = 0;
|
||||
for (std::uint64_t next = CHAR_BIT; next < count; index = next, next += CHAR_BIT)
|
||||
{
|
||||
writer.WriteFrom<unsigned char>(packBits(data, index, CHAR_BIT));
|
||||
}
|
||||
if (count > index)
|
||||
writer.WriteFrom<unsigned char>(packBits(data, index, count - index));
|
||||
}
|
||||
|
||||
template <typename VectorT>
|
||||
void readBoolVector(tar::FileReader &reader, const std::string &name, VectorT &data)
|
||||
{
|
||||
@@ -286,26 +183,6 @@ void writeBoolVector(tar::FileWriter &writer, const std::string &name, const Vec
|
||||
}
|
||||
}
|
||||
|
||||
template <> inline void read<bool>(io::FileReader &reader, util::vector_view<bool> &data)
|
||||
{
|
||||
detail::readBoolVector(reader, data);
|
||||
}
|
||||
|
||||
template <> inline void write<bool>(io::FileWriter &writer, const util::vector_view<bool> &data)
|
||||
{
|
||||
detail::writeBoolVector(writer, data);
|
||||
}
|
||||
|
||||
template <> inline void read<bool>(io::FileReader &reader, std::vector<bool> &data)
|
||||
{
|
||||
detail::readBoolVector(reader, data);
|
||||
}
|
||||
|
||||
template <> inline void write<bool>(io::FileWriter &writer, const std::vector<bool> &data)
|
||||
{
|
||||
detail::writeBoolVector(writer, data);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void
|
||||
read<bool>(tar::FileReader &reader, const std::string &name, util::vector_view<bool> &data)
|
||||
|
||||
Reference in New Issue
Block a user