Skip to content

Commit 9bb39a4

Browse files
committed
Created common function for set_D_sparse
Signed-off-by: Chuck Ketcham <[email protected]>
1 parent ce05831 commit 9bb39a4

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

libs/qec/lib/decoder.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,11 @@ void decoder::set_decoder_id(uint32_t decoder_id) {
190190

191191
uint32_t decoder::get_decoder_id() const { return pimpl->decoder_id; }
192192

193-
void decoder::set_D_sparse(const std::vector<std::vector<uint32_t>> &D_sparse) {
194-
this->D_sparse = D_sparse;
195-
auto *sw_decoder = dynamic_cast<sliding_window *>(this);
193+
template <typename PimplType>
194+
void set_D_sparse_common(decoder *decoder,
195+
const std::vector<std::vector<uint32_t>> &D_sparse,
196+
PimplType *pimpl) {
197+
auto *sw_decoder = dynamic_cast<sliding_window *>(decoder);
196198

197199
if (sw_decoder != nullptr) {
198200
pimpl->is_sliding_window = true;
@@ -215,28 +217,14 @@ void decoder::set_D_sparse(const std::vector<std::vector<uint32_t>> &D_sparse) {
215217
pimpl->msyn_buffer_index = 0;
216218
}
217219

220+
void decoder::set_D_sparse(const std::vector<std::vector<uint32_t>> &D_sparse) {
221+
this->D_sparse = D_sparse;
222+
set_D_sparse_common(this, D_sparse, pimpl.get());
223+
}
224+
218225
void decoder::set_D_sparse(const std::vector<int64_t> &D_sparse_vec_in) {
219226
set_sparse_from_vec(D_sparse_vec_in, this->D_sparse);
220-
auto *sw_decoder = dynamic_cast<sliding_window *>(this);
221-
222-
if (sw_decoder != nullptr) {
223-
pimpl->is_sliding_window = true;
224-
pimpl->num_syndromes_per_round = sw_decoder->get_num_syndromes_per_round();
225-
// Check if first row is a first-round detector (single syndrome index)
226-
pimpl->has_first_round_detectors =
227-
(this->D_sparse.size() > 0 && this->D_sparse[0].size() == 1);
228-
pimpl->current_round = 0;
229-
pimpl->persistent_detector_buffer.resize(pimpl->num_syndromes_per_round);
230-
pimpl->persistent_soft_detector_buffer.resize(
231-
pimpl->num_syndromes_per_round);
232-
} else {
233-
pimpl->is_sliding_window = false;
234-
}
235-
236-
pimpl->num_msyn_per_decode = calculate_num_msyn_per_decode(this->D_sparse);
237-
pimpl->msyn_buffer.clear();
238-
pimpl->msyn_buffer.resize(pimpl->num_msyn_per_decode);
239-
pimpl->msyn_buffer_index = 0;
227+
set_D_sparse_common(this, this->D_sparse, pimpl.get());
240228
}
241229

242230
bool decoder::enqueue_syndrome(const uint8_t *syndrome,

0 commit comments

Comments
 (0)