Skip to content

Commit

Permalink
Switch statement instead of semimap
Browse files Browse the repository at this point in the history
  • Loading branch information
willdealtry authored and Gem Dot Artigas committed Sep 29, 2023
1 parent d7b6e1b commit 144a1a6
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions cpp/arcticdb/entity/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
*
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
*/
#ifdef ARCTICDB_USE_CONDA
#include <semimap/semimap.h>
#else
#include <third_party/semimap/semimap.h>
#endif
#include <arcticdb/entity/key.hpp>

namespace arcticdb::entity {
Expand Down Expand Up @@ -37,15 +32,12 @@ struct KeyData {
const char* description_;
};

const KeyData& get_key_data(KeyType key_type) {
struct KeyMapTag{};
using KeyMap = semi::static_map<int, KeyData, KeyMapTag>;

#define KEY_ID(x) []() constexpr { return static_cast<int>(x); }
#define NUMERIC_KEY(kt, name, c) KeyMap::get(KEY_ID(kt)) = { #name, c, VariantType::NUMERIC_TYPE, KeyClass::ATOM_KEY, #kt };
#define STRING_KEY(kt, name, c) KeyMap::get(KEY_ID(kt)) = { #name, c, VariantType::STRING_TYPE, KeyClass::ATOM_KEY, #kt};
#define STRING_REF(kt, name, c) KeyMap::get(KEY_ID(kt)) = { #name, c, VariantType::STRING_TYPE, KeyClass::REF_KEY, #kt };
KeyData get_key_data(KeyType key_type) {
#define NUMERIC_KEY(kt, name, c) case kt: return KeyData{ #name, c, VariantType::NUMERIC_TYPE, KeyClass::ATOM_KEY, #kt };
#define STRING_KEY(kt, name, c) case kt: return KeyData{ #name, c, VariantType::STRING_TYPE, KeyClass::ATOM_KEY, #kt};
#define STRING_REF(kt, name, c) case kt: return KeyData{ #name, c, VariantType::STRING_TYPE, KeyClass::REF_KEY, #kt };

switch (key_type) {
NUMERIC_KEY(KeyType::STREAM_GROUP, sg, 'g')
NUMERIC_KEY(KeyType::GENERATION, gen, 'G')
STRING_KEY(KeyType::TABLE_DATA, tdata, 'd')
Expand All @@ -72,11 +64,8 @@ const KeyData& get_key_data(KeyType key_type) {
STRING_KEY(KeyType::TOMBSTONE_ALL, tall, 'q')
STRING_REF(KeyType::LIBRARY_CONFIG, cref, 'C')
STRING_KEY(KeyType::COLUMN_STATS, cstats, 'S')


const auto& data = KeyMap::get(int(key_type));
util::check(data.short_name_ != 'u', "Could not get data for key_type {}", static_cast<int>(key_type));
return data;
default:util::raise_rte("Could not get data for key_type {}", static_cast<int>(key_type));
};
}

const char* key_type_long_name(KeyType key_type) {
Expand Down

0 comments on commit 144a1a6

Please sign in to comment.