summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Bauer <mail@ulrich-bauer.org>2016-08-25 23:17:00 +0200
committerUlrich Bauer <mail@ulrich-bauer.org>2016-08-26 01:30:46 +0200
commit099ce879f4c729ec1fcbb148477aae64750bd90b (patch)
treea98f2a8a557ede535948f60d9e9a6d19de8b1042
parentc10327ed6ccf9e3c8961833cbf95431433d6b282 (diff)
packed entry_t
-rw-r--r--ripser.cpp10
-rw-r--r--ripser.xcodeproj/project.pbxproj3
2 files changed, 9 insertions, 4 deletions
diff --git a/ripser.cpp b/ripser.cpp
index b4b528c..d3b969a 100644
--- a/ripser.cpp
+++ b/ripser.cpp
@@ -47,7 +47,7 @@ typedef float value_t;
// typedef uint16_t value_t;
typedef long index_t;
-typedef long coefficient_t;
+typedef short coefficient_t;
class binomial_coeff_table {
std::vector<std::vector<index_t>> B;
@@ -132,18 +132,22 @@ std::vector<index_t> vertices_of_simplex(const index_t simplex_index, const inde
#ifdef USE_COEFFICIENTS
struct entry_t {
- index_t index;
+ index_t index : 8 * (sizeof(index_t) - sizeof(coefficient_t));
coefficient_t coefficient;
entry_t(index_t _index, coefficient_t _coefficient) : index(_index), coefficient(_coefficient) {}
entry_t(index_t _index) : index(_index), coefficient(1) {}
entry_t() : index(0), coefficient(1) {}
-};
+} __attribute__((packed));
+
+static_assert(sizeof(entry_t) == sizeof(index_t), "size of entry_t is not the same as index_t");
+
entry_t make_entry(index_t _index, coefficient_t _coefficient) { return entry_t(_index, _coefficient); }
index_t get_index(entry_t e) { return e.index; }
index_t get_coefficient(entry_t e) { return e.coefficient; }
void set_coefficient(entry_t& e, const coefficient_t c) { e.coefficient = c; }
+
bool operator==(const entry_t& e1, const entry_t& e2) {
return get_index(e1) == get_index(e2) && get_coefficient(e1) == get_coefficient(e2);
}
diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj
index 980df17..04bc3a6 100644
--- a/ripser.xcodeproj/project.pbxproj
+++ b/ripser.xcodeproj/project.pbxproj
@@ -209,9 +209,10 @@
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
- FILE_FORMAT_DISTANCE_MATRIX,
+ _FILE_FORMAT_DISTANCE_MATRIX,
_FILE_FORMAT_LOWER_DISTANCE_MATRIX,
_FILE_FORMAT_POINT_CLOUD,
+ USE_COEFFICIENTS,
);
PRODUCT_NAME = "$(TARGET_NAME)";
};