-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
102 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string_view> | ||
|
||
#include "codec/block_codec.hpp" | ||
|
||
namespace pisa { | ||
|
||
[[nodiscard]] auto get_block_codec(std::string_view name) -> std::unique_ptr<BlockCodec>; | ||
|
||
} // namespace pisa |
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
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
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,64 @@ | ||
#include "codec/block_codec_registry.hpp" | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <memory> | ||
#include <string_view> | ||
|
||
#include <fmt/format.h> | ||
|
||
#include "codec/block_codec.hpp" | ||
#include "codec/interpolative.hpp" | ||
#include "codec/maskedvbyte.hpp" | ||
#include "codec/optpfor.hpp" | ||
#include "codec/qmx.hpp" | ||
#include "codec/simdbp.hpp" | ||
#include "codec/simple16.hpp" | ||
#include "codec/simple8b.hpp" | ||
#include "codec/streamvbyte.hpp" | ||
#include "codec/varint_g8iu.hpp" | ||
#include "codec/varintgb.hpp" | ||
|
||
namespace pisa { | ||
|
||
template <typename... C> | ||
class BlockCodecRegistry { | ||
using BlockCodecConstructor = std::unique_ptr<BlockCodec> (*)(); | ||
|
||
constexpr static std::array<std::string_view, sizeof...(C)> m_names = | ||
std::array<std::string_view, sizeof...(C)>{C::name...}; | ||
|
||
constexpr static std::array<BlockCodecConstructor, sizeof...(C)> m_constructors = | ||
std::array<BlockCodecConstructor, sizeof...(C)>{[]() -> std::unique_ptr<BlockCodec> { | ||
return std::make_unique<C>(); | ||
}...}; | ||
|
||
public: | ||
constexpr static auto count() -> std::size_t { return sizeof...(C); } | ||
static auto get(std::string_view name) -> std::unique_ptr<BlockCodec> { | ||
auto pos = std::find(m_names.begin(), m_names.end(), name); | ||
if (pos == m_names.end()) { | ||
throw std::domain_error(fmt::format("invalid codec: {}", name)); | ||
} | ||
auto constructor = m_constructors[std::distance(m_names.begin(), pos)]; | ||
return constructor(); | ||
} | ||
}; | ||
|
||
using BlockCodecs = BlockCodecRegistry< | ||
InterpolativeBlockCodec, | ||
MaskedVByteBlockCodec, | ||
OptPForBlockCodec, | ||
QmxBlockCodec, | ||
SimdBpBlockCodec, | ||
Simple16BlockCodec, | ||
Simple8bBlockCodec, | ||
StreamVByteBlockCodec, | ||
VarintG8IUBlockCodec, | ||
VarintGbBlockCodec>; | ||
|
||
auto get_block_codec(std::string_view name) -> std::unique_ptr<BlockCodec> { | ||
return BlockCodecs::get(name); | ||
} | ||
|
||
} // namespace pisa |
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