M12.6: add bounded regional cellular census and lineage queries
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m33s
Foundation / checks (network) (push) Successful in 21m15s
Foundation / checks (client) (push) Successful in 22m8s
Foundation / checks (tsan) (push) Successful in 25m2s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 38m24s
Foundation / checks (postgres) (push) Canceled after 38m24s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m33s
Foundation / checks (network) (push) Successful in 21m15s
Foundation / checks (client) (push) Successful in 22m8s
Foundation / checks (tsan) (push) Successful in 25m2s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 38m24s
Foundation / checks (postgres) (push) Canceled after 38m24s
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/server/lifecycle/cellular_population.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::server {
|
||||
inline constexpr std::uint32_t cellular_census_projection_version = 1;
|
||||
enum class CellularCensusKind : std::uint8_t {
|
||||
individual_wildlife,
|
||||
cohort_wildlife,
|
||||
active_controlled,
|
||||
lingering_controlled,
|
||||
suspended_controlled
|
||||
};
|
||||
inline constexpr std::size_t cellular_census_kind_count = 5;
|
||||
struct CellularCensusStock {
|
||||
std::uint64_t count{};
|
||||
accounting::Inventory body{}, reserve{};
|
||||
bool operator==(const CellularCensusStock&) const = default;
|
||||
};
|
||||
struct CellularCensusTotals {
|
||||
std::array<CellularCensusStock, cellular_census_kind_count> resident{};
|
||||
// Historical observations only: no owned inventory/current viability claim.
|
||||
std::uint64_t retained_nonresident_records{};
|
||||
bool operator==(const CellularCensusTotals&) const = default;
|
||||
};
|
||||
struct CellularCensusRow {
|
||||
std::uint64_t genome{};
|
||||
std::uint32_t schema{}, development{};
|
||||
std::vector<std::uint64_t> parents;
|
||||
CellularCensusTotals totals;
|
||||
bool operator==(const CellularCensusRow&) const = default;
|
||||
};
|
||||
struct CellularCensusBoundary {
|
||||
std::uint64_t world{}, region{}, frame{}, tick{};
|
||||
std::uint32_t owner_format{}, rules{}, population_format{}; // Zero: raw owner.
|
||||
std::uint64_t quantum_microseconds{biology::cellular_motion_tick_microseconds};
|
||||
bool operator==(const CellularCensusBoundary&) const = default;
|
||||
};
|
||||
enum class CellularCensusScope : std::uint8_t { exact_genome, descendants, invalid = 255 };
|
||||
enum class CellularCensusError : std::uint8_t {
|
||||
unsupported,
|
||||
history,
|
||||
overflow,
|
||||
unknown_genome,
|
||||
invalid_scope
|
||||
};
|
||||
// Detached bounded observation, NOT a committed/world-complete evidence record.
|
||||
// It never owns inventory, changes biology or reports terminal extinction.
|
||||
class CellularCensus {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
||||
observe(const CellularLives&);
|
||||
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
||||
observe(const CellularPopulation&);
|
||||
[[nodiscard]] const CellularCensusBoundary& boundary() const noexcept {
|
||||
return boundary_;
|
||||
}
|
||||
// Ascending genome IDs. All retained ancestors remain, even with zero residents.
|
||||
[[nodiscard]] std::span<const CellularCensusRow> rows() const noexcept {
|
||||
return rows_;
|
||||
}
|
||||
// Descendants includes the anchor. Unknown is an error, never a zero report.
|
||||
[[nodiscard]] std::expected<CellularCensusTotals, CellularCensusError>
|
||||
query(std::uint64_t anchor, CellularCensusScope scope) const;
|
||||
|
||||
private:
|
||||
CellularCensus() = default;
|
||||
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
||||
observe(const CellularLives&, std::span<const CellularCohortMember>, std::uint32_t population);
|
||||
[[nodiscard]] std::size_t locate(std::uint64_t genome) const;
|
||||
CellularCensusBoundary boundary_;
|
||||
std::vector<CellularCensusRow> rows_;
|
||||
std::vector<std::vector<std::size_t>> children_;
|
||||
};
|
||||
} // namespace evo::server
|
||||
Reference in New Issue
Block a user