Skip to content

Commit

Permalink
history .vi key
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr committed Dec 3, 2024
1 parent feb4637 commit 648582a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
12 changes: 12 additions & 0 deletions silkworm/db/datastore/snapshots/common/raw_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ struct RawDecoder : public Decoder {
static_assert(DecoderConcept<RawDecoder<Bytes>>);
static_assert(DecoderConcept<RawDecoder<ByteView>>);

template <BytesOrByteView TBytes>
struct RawEncoder : public Encoder {
TBytes value;
~RawEncoder() override = default;
ByteView encode_word() override {
return value;
}
};

static_assert(EncoderConcept<RawEncoder<Bytes>>);
static_assert(EncoderConcept<RawEncoder<ByteView>>);

} // namespace silkworm::snapshots
6 changes: 6 additions & 0 deletions silkworm/db/datastore/snapshots/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "history_accessor_index.hpp"
#include "inverted_index.hpp"
#include "rec_split/accessor_index.hpp"
#include "segment/segment_reader.hpp"
Expand All @@ -26,6 +27,11 @@ struct History {
const segment::SegmentFileReader& segment;
const rec_split::AccessorIndex& accessor_index;
InvertedIndex inverted_index;

template <EncoderConcept TIIKeyEncoder>
static HistoryAccessorIndexKeyEncoder<TIIKeyEncoder> make_accessor_index_key_encoder() {
return HistoryAccessorIndexKeyEncoder<TIIKeyEncoder>{};
}
};

} // namespace silkworm::snapshots
51 changes: 51 additions & 0 deletions silkworm/db/datastore/snapshots/history_accessor_index.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2024 The Silkworm Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include <silkworm/core/common/endian.hpp>

#include "common/codec.hpp"
#include "common/raw_codec.hpp"

namespace silkworm::snapshots {

template <EncoderConcept TIIKeyEncoder>
struct HistoryAccessorIndexKeyEncoder : public snapshots::Encoder {
struct {
TxnId txn_id{};
TIIKeyEncoder inverted_index_key;
} value;

Bytes word;

~HistoryAccessorIndexKeyEncoder() override = default;

ByteView encode_word() override {
word.clear();

word.append(sizeof(TxnId), 0);
endian::store_big_u64(word.data(), value.txn_id);

word += value.inverted_index_key.encode_word();

return word;
}
};

static_assert(snapshots::EncoderConcept<HistoryAccessorIndexKeyEncoder<RawEncoder<ByteView>>>);

} // namespace silkworm::snapshots

0 comments on commit 648582a

Please sign in to comment.