thin-provisioning-tools/caching/hint_array.h

59 lines
1.5 KiB
C
Raw Normal View History

2013-09-12 17:03:32 +05:30
#ifndef CACHE_HINT_ARRAY_H
#define CACHE_HINT_ARRAY_H
#include "persistent-data/data-structures/array.h"
#include <string>
//----------------------------------------------------------------
namespace caching {
namespace hint_array_detail {
template <uint32_t WIDTH>
struct hint_traits {
typedef unsigned char byte;
typedef byte disk_type[WIDTH];
2013-09-24 16:30:09 +05:30
typedef vector<byte> value_type;
2013-09-12 17:03:32 +05:30
typedef no_op_ref_counter<value_type> ref_counter;
2013-09-24 16:30:09 +05:30
// FIXME: slow copying for now
2013-09-12 19:12:59 +05:30
static void unpack(disk_type const &disk, value_type &value) {
2013-09-24 16:30:09 +05:30
for (unsigned byte = 0; byte < WIDTH; byte++)
value[byte] = disk[byte];
2013-09-12 19:12:59 +05:30
}
static void pack(value_type const &value, disk_type &disk) {
2013-09-24 16:30:09 +05:30
for (unsigned byte = 0; byte < WIDTH; byte++)
disk[byte] = value[byte];
2013-09-12 19:12:59 +05:30
}
2013-09-12 17:03:32 +05:30
};
// FIXME: data visitor stuff
}
2013-09-24 16:30:09 +05:30
class hint_array {
public:
typedef boost::shared_ptr<hint_array> ptr;
typedef typename persistent_data::transaction_manager::ptr tm_ptr;
hint_array(tm_ptr tm, unsigned width);
hint_array(tm_ptr tm, unsigned width, block_address root, unsigned nr_entries);
unsigned get_nr_entries() const;
void grow(unsigned new_nr_entries, void const *v);
block_address get_root() const;
void get_hint(unsigned index, vector<unsigned char> &data) const;
void set_hint(unsigned index, vector<unsigned char> const &data);
private:
unsigned width_;
boost::shared_ptr<persistent_data::array_base> impl_;
};
2013-09-12 17:03:32 +05:30
}
//----------------------------------------------------------------
#endif