in glean/rts/ownership.cpp [266:301]
std::unique_ptr<ComputedOwnership> computeOwnership(
const Inventory& inventory,
Lookup& lookup,
OwnershipUnitIterator *iter) {
uint32_t numUnits;
auto t = makeAutoTimer("computeOwnership");
LOG(INFO) << "computing ownership";
auto utrie = fillOwnership(iter,numUnits);
t.log("fillOwnership");
auto usets = collectUsets(numUnits,utrie);
t.log("collectUsets");
// TODO: Should `completeOwnership` work with the trie rather than a
// flat vector?
auto facts = utrie.flatten();
LOG(INFO) << "completing ownership: " << facts.size() << " facts";
completeOwnership(facts, usets, inventory, lookup);
t.log("completeOwnership");
std::vector<std::pair<Id,UsetId>> factOwners;
UsetId current = INVALID_USET;
for (uint32_t i = Id::lowest().toWord(); i < facts.size(); i++) {
auto usetid = facts[i] ? facts[i]->id : INVALID_USET;
if (usetid != current) {
factOwners.push_back(std::make_pair(Id::fromWord(i), usetid));
current = usetid;
}
}
auto sets = usets.toEliasFano();
return std::make_unique<ComputedOwnership>(
usets.getFirstId(),
std::move(sets),
std::move(factOwners));
}