public function getAncestorDispersionForGen($gen) {
        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
        return Database::prepare(
            'SELECT branches, count(i_id)'.
            ' FROM ('.
            '   SELECT i_id,'.
            '       CASE'.
            '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
            '           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
            '       END branches'.
            '   FROM ('.
            '       SELECT DISTINCT majs_i_id i_id,'.
            '           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
            '       FROM `##maj_sosa`'.
            '       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
            '           AND majs_gen >= :gen'.
            '   ) indistat'.
            '   GROUP BY i_id'.
            ') grouped'.
            ' GROUP BY branches')
            ->execute(array(
                'tree_id' => $this->tree->getTreeId(), 
                'user_id' => $this->user->getUserId(),
                'gen' => $gen
            ))->fetchAssoc() ?: array();
    }