From a05d75611e24a29e2bc9846498fac8d3f0809465 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 12 Sep 2013 14:21:25 +0100 Subject: [PATCH] mapping_array.cc --- Makefile.in | 2 ++ caching/mapping_array.cc | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 caching/mapping_array.cc diff --git a/Makefile.in b/Makefile.in index a72d18c..058e32e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,6 +37,7 @@ SOURCE=\ base/error_state.cc \ \ caching/superblock.cc \ + caching/mapping_array.cc \ caching/metadata.cc \ caching/restore_emitter.cc \ caching/xml_format.cc \ @@ -236,6 +237,7 @@ CACHE_CHECK_SOURCE=\ persistent-data/space-maps/careful_alloc.cc \ persistent-data/transaction_manager.cc \ caching/superblock.cc \ + caching/mapping_array.cc \ caching/metadata.cc \ caching/restore_emitter.cc \ caching/xml_format.cc diff --git a/caching/mapping_array.cc b/caching/mapping_array.cc new file mode 100644 index 0000000..3e43d87 --- /dev/null +++ b/caching/mapping_array.cc @@ -0,0 +1,28 @@ +#include "caching/mapping_array.h" +#include "persistent-data/endian_utils.h" + +using namespace caching::mapping_array_detail; + +//---------------------------------------------------------------- + +namespace { + const uint64_t FLAGS_MASK = (1 << 16) - 1; +} + +void +mapping_traits::unpack(disk_type const &disk, value_type &value) +{ + uint64_t v = base::to_cpu(disk); + value.oblock_ = v >> 16; + value.flags_ = v & FLAGS_MASK; +} + +void +mapping_traits::pack(value_type const &value, disk_type &disk) +{ + uint64_t packed = value.oblock_ << 16; + packed = packed || (value.flags_ & FLAGS_MASK); + disk = base::to_disk(packed); +} + +//----------------------------------------------------------------