MCPcopy Create free account
hub / github.com/chrxh/alien / getConstructorToMainGenomes

Method getConstructorToMainGenomes

source/EngineInterface/DescriptionEditService.cpp:703–736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701}
702
703std::vector<CellOrParticleDescription> DescriptionEditService::getConstructorToMainGenomes(DataDescription const& data)
704{
705 std::map<std::vector<uint8_t>, size_t> genomeToCellIndex;
706 for (auto const& [index, cell] : data.cells | boost::adaptors::indexed(0)) {
707 if (cell.getCellFunctionType() == CellFunction_Constructor) {
708 auto const& genome = std::get<ConstructorDescription>(*cell.cellFunction).genome;
709 if (!genomeToCellIndex.contains(genome) || cell.livingState != LivingState_UnderConstruction) {
710 genomeToCellIndex[genome] = index;
711 }
712 }
713 }
714 std::vector<std::pair<std::vector<uint8_t>, size_t>> genomeAndCellIndex;
715 for (auto const& [genome, index] : genomeToCellIndex) {
716 genomeAndCellIndex.emplace_back(std::make_pair(genome, index));
717 }
718 std::ranges::sort(genomeAndCellIndex, [](auto const& element1, auto const& element2) { return element1.first.size() > element2.first.size(); });
719
720 std::vector<CellOrParticleDescription> result;
721 for (auto it = genomeAndCellIndex.begin(); it != genomeAndCellIndex.end(); ++it) {
722 bool alreadyContained = false;
723 for (auto it2 = genomeAndCellIndex.begin(); it2 != it; ++it2) {
724 auto const& genome1 = it->first;
725 auto const& genome2 = it2->first;
726 if (contains(genome2, genome1)) {
727 alreadyContained = true;
728 break;
729 }
730 }
731 if (!alreadyContained) {
732 result.emplace_back(data.cells.at(it->second));
733 }
734 }
735 return result;
736}

Callers 1

Calls 5

sizeMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
containsFunction · 0.70
getCellFunctionTypeMethod · 0.45

Tested by

no test coverage detected