lineage/heritage
Represents the ancestry graph of a population.
A Heritage is a snapshot of the parent–child relationships across all
individuals in a population. It stores individuals by name alongside two
edge maps: one pointing from each individual to its parents, and one
pointing from each individual to its children.
The primary entry points are from_population, which converts a full
Population into a Heritage, and lineage_of, which extracts the
sub-graph of ancestors for a single individual.
Types
A directed ancestry graph covering all individuals in a population.
Fields
individuals- All known individuals keyed by nameparents- Maps each individual’s name to the names of its parentschildren- Maps each individual’s name to the names of its children
pub type Heritage {
Heritage(
individuals: dict.Dict(String, individual.Individual),
parents: dict.Dict(String, List(String)),
children: dict.Dict(String, List(String)),
)
}
Constructors
-
Heritage( individuals: dict.Dict(String, individual.Individual), parents: dict.Dict(String, List(String)), children: dict.Dict(String, List(String)), )
Values
pub fn anchestry(
tree: dict.Dict(Int, List(individual.Individual)),
) -> List(individual.Individual)
pub fn family_tree(
heritage: Heritage,
center: individual.Individual,
) -> dict.Dict(Int, List(individual.Individual))
pub fn flatten(
heritage: Heritage,
center: individual.Individual,
) -> List(#(individual.Individual, Int))
pub fn from_population(
population: population.Population,
) -> Heritage
Converts a Population into a Heritage by indexing every individual and
building parent and child edge maps from their mother and father fields.
Examples
let heritage = population |> heritage.from_population
dict.size(heritage.individuals)
// -> total number of individuals across all generations
pub fn lineage_of(
individual: individual.Individual,
heritage: Heritage,
) -> Heritage
Extracts the ancestry sub-graph for a single individual.
Walks the parent edges of heritage recursively from individual,
collecting every reachable ancestor along with their own parent and child
entries. The result is a self-contained Heritage containing only the
individuals on the ancestral path.
Examples
let ancestors = lineage_of(child, full_heritage)
dict.has_key(ancestors.individuals, child.name)
// -> True