MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / CopySubset

Method CopySubset

src/io/sparse_bin.hpp:377–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375 }
376
377 void CopySubset(const Bin* full_bin, const data_size_t* used_indices, data_size_t num_used_indices) override {
378 auto other_bin = dynamic_cast<const SparseBin<VAL_T>*>(full_bin);
379 deltas_.clear();
380 vals_.clear();
381 data_size_t start = 0;
382 if (num_used_indices > 0) {
383 start = used_indices[0];
384 }
385 SparseBinIterator<VAL_T> iterator(other_bin, start);
386 // transform to delta array
387 data_size_t last_idx = 0;
388 for (data_size_t i = 0; i < num_used_indices; ++i) {
389 VAL_T bin = iterator.InnerRawGet(used_indices[i]);
390 if (bin > 0) {
391 data_size_t cur_delta = i - last_idx;
392 while (cur_delta >= 256) {
393 deltas_.push_back(cur_delta & 0xff);
394 vals_.push_back(0);
395 cur_delta >>= 8;
396 }
397 deltas_.push_back(static_cast<uint8_t>(cur_delta));
398 vals_.push_back(bin);
399 last_idx = i;
400 }
401 }
402 // avoid out of range
403 deltas_.push_back(0);
404 num_vals_ = static_cast<data_size_t>(vals_.size());
405
406 // reduce memory cost
407 deltas_.shrink_to_fit();
408 vals_.shrink_to_fit();
409
410 // generate fast index
411 GetFastIndex();
412 }
413
414 SparseBin<VAL_T>* Clone() override;
415

Callers

nothing calls this directly

Calls 5

push_backMethod · 0.80
clearMethod · 0.45
InnerRawGetMethod · 0.45
sizeMethod · 0.45
shrink_to_fitMethod · 0.45

Tested by

no test coverage detected