From 1e49367eb4601a5dd3e5aab75ea71e8386d19a02 Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Tue, 28 Nov 2023 20:40:03 -0800 Subject: [PATCH] refactor: return to uint32_t for dbFlags --- src/databases.cpp | 13 +++++++------ src/databases.hpp | 6 +++--- src/main.cpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/databases.cpp b/src/databases.cpp index 52c9c3c2..1bc2d47a 100644 --- a/src/databases.cpp +++ b/src/databases.cpp @@ -1,5 +1,6 @@ #include "databases.hpp" +#include #include #include #include @@ -15,7 +16,7 @@ namespace lost { const int32_t PairDistanceKVectorDatabase::kMagicValue = 0x2536f009; -inline bool isFlagSet(uint8_t dbFlags, uint8_t flag) { +inline bool isFlagSet(uint32_t dbFlags, uint32_t flag) { return (dbFlags & flag) != 0; } @@ -253,8 +254,8 @@ const int16_t *PairDistanceKVectorDatabase::FindPairsExact(const Catalog &catalo // sense anyway) assert(maxQueryDistance <= DECIMAL_M_PI); - decimal maxQueryCos = cos(minQueryDistance); - decimal minQueryCos = cos(maxQueryDistance); + decimal maxQueryCos = DECIMAL_COS(minQueryDistance); + decimal minQueryCos = DECIMAL_COS(maxQueryDistance); long liberalUpperIndex; long liberalLowerIndex = index.QueryLiberal(minQueryDistance, maxQueryDistance, &liberalUpperIndex); @@ -322,7 +323,7 @@ const unsigned char *MultiDatabase::SubDatabasePointer(int32_t magicValue) const if (curMagicValue == 0) { return nullptr; } - uint8_t dbFlags = DeserializePrimitive(des); + uint32_t dbFlags = DeserializePrimitive(des); // Ensure that our database is using the same type as the runtime. #ifdef LOST_FLOAT_MODE @@ -351,10 +352,10 @@ const unsigned char *MultiDatabase::SubDatabasePointer(int32_t magicValue) const void SerializeMultiDatabase(SerializeContext *ser, const MultiDatabaseDescriptor &dbs, - uint8_t flags) { + uint32_t flags) { for (const MultiDatabaseEntry &multiDbEntry : dbs) { SerializePrimitive(ser, multiDbEntry.magicValue); - SerializePrimitive(ser, flags); + SerializePrimitive(ser, flags); SerializePrimitive(ser, multiDbEntry.bytes.size()); SerializePadding(ser); std::copy(multiDbEntry.bytes.cbegin(), multiDbEntry.bytes.cend(), std::back_inserter(ser->buffer)); diff --git a/src/databases.hpp b/src/databases.hpp index 56d145a5..c510ab78 100644 --- a/src/databases.hpp +++ b/src/databases.hpp @@ -12,7 +12,7 @@ namespace lost { const int32_t kCatalogMagicValue = 0xF9A283BC; -inline bool isFlagSet(uint8_t dbFlags, uint8_t flag); +inline bool isFlagSet(uint32_t dbFlags, uint32_t flag); /** * A data structure enabling constant-time range queries into fixed numerical data. @@ -116,13 +116,13 @@ class MultiDatabaseEntry { : magicValue(magicValue), bytes(bytes) { } int32_t magicValue; - uint8_t flags; + uint32_t flags; std::vector bytes; }; typedef std::vector MultiDatabaseDescriptor; -void SerializeMultiDatabase(SerializeContext *, const MultiDatabaseDescriptor &dbs, uint8_t flags); +void SerializeMultiDatabase(SerializeContext *, const MultiDatabaseDescriptor &dbs, uint32_t flags); } diff --git a/src/main.cpp b/src/main.cpp index c864ddc6..86c20b77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ static void DatabaseBuild(const DatabaseOptions &values) { SerializeContext ser = serFromDbValues(values); // Create & Set Flags. - uint8_t dbFlags = 0; + uint32_t dbFlags = 0; dbFlags |= typeid(decimal) == typeid(float) ? MULTI_DB_FLOAT_FLAG : 0; // Serialize Flags