| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "segmented_sequences.h"
- #include <algorithm>
- SegmentedSequencesLeaf::SegmentedSequencesLeaf(
- std::shared_ptr<std::string> sequence)
- : sequence_(sequence) {}
- void SegmentedSequencesLeaf::Visit(
- std::function<void(SegmentedString sequence)> visitor) const {
- visitor(SegmentedString{sequence_});
- }
- size_t SegmentedSequencesLeaf::MinSize() const {
- return sequence_->size();
- }
- SegmentedSequencesAlternatives::SegmentedSequencesAlternatives(
- std::vector<std::shared_ptr<SegmentedSequences>> alternatives) {
- min_size_ = alternatives[0]->MinSize();
- for (const auto &alt : alternatives) {
- min_size_ = std::min(min_size_, alt->MinSize());
- }
- for (const auto &alt : alternatives) {
- if (alt->MinSize() == min_size_) {
- alternatives_.push_back(alt);
- }
- }
- }
- void SegmentedSequencesAlternatives::Visit(
- std::function<void(SegmentedString sequence)> visitor) const {
- for (const auto &alt : alternatives_) {
- alt->Visit(visitor);
- }
- }
- size_t SegmentedSequencesAlternatives::MinSize() const {
- return min_size_;
- }
- SegmentedSequencesProduct::SegmentedSequencesProduct(
- std::shared_ptr<SegmentedSequences> a,
- std::shared_ptr<SegmentedSequences> b)
- : a_(a), b_(b) {
- min_size_ = a_->MinSize() + b_->MinSize();
- }
- void SegmentedSequencesProduct::Visit(
- std::function<void(SegmentedString sequence)> visitor) const {
- a_->Visit([this, visitor](SegmentedString seq_a) {
- b_->Visit([this, visitor, &seq_a](SegmentedString seq_b) {
- SegmentedString joined_seq = seq_a;
- joined_seq.insert(joined_seq.end(), seq_b.begin(), seq_b.end());
- visitor(joined_seq);
- });
- });
- }
- size_t SegmentedSequencesProduct::MinSize() const {
- return min_size_;
- }
|