-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Efficient storage of integer G3Map and G3Vector objects (#140)
Use int64_t for in-memory representation of integer values, but store as 8-, 16- or 32- bit integers on disk, depending on bit depth of the underlying data. Backwards compatible with v1 int32 G3Map objects. Closes #122.
- Loading branch information
Showing
7 changed files
with
334 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "int_storage.h" | ||
|
||
int bit_count(const std::vector<int64_t> &d) { | ||
// Returns the smallest number N such that all ints in the | ||
// vector could be safely expressed as intN_t. Assumes two's | ||
// complement integers. Return value will be between 1 and | ||
// 64. | ||
uint64_t mask = 0; | ||
for (auto c: d) { | ||
if (c < 0) | ||
mask |= ~c; | ||
else | ||
mask |= c; | ||
} | ||
for (int i=1; i<64; i++) { | ||
if (mask == 0) | ||
return i; | ||
mask >>= 1; | ||
} | ||
return 64; | ||
} | ||
|
||
int bit_count(const std::map<std::string, int64_t> &d) { | ||
// Returns the smallest number N such that all ints in the | ||
// map could be safely expressed as intN_t. Assumes two's | ||
// complement integers. Return value will be between 1 and | ||
// 64. | ||
uint64_t mask = 0; | ||
for (auto c: d) { | ||
if (c.second < 0) | ||
mask |= ~c.second; | ||
else | ||
mask |= c.second; | ||
} | ||
for (int i=1; i<64; i++) { | ||
if (mask == 0) | ||
return i; | ||
mask >>= 1; | ||
} | ||
return 64; | ||
} | ||
|
||
#define INT_SERIALIZABLE_CODE(inttype) \ | ||
template <typename inttype> \ | ||
void load_as(cereal::PortableBinaryInputArchive &, std::vector<int64_t> &dest); \ | ||
template <typename inttype> \ | ||
void load_as(cereal::PortableBinaryInputArchive &, std::map<std::string, int64_t> &dest); \ | ||
template <typename inttype> \ | ||
void save_as(cereal::PortableBinaryOutputArchive &, const std::vector<int64_t> &src); \ | ||
template <typename inttype> \ | ||
void save_as(cereal::PortableBinaryOutputArchive &, const std::map<std::string, int64_t> &src) | ||
|
||
INT_SERIALIZABLE_CODE(int8_t); | ||
INT_SERIALIZABLE_CODE(int16_t); | ||
INT_SERIALIZABLE_CODE(int32_t); |
Oops, something went wrong.