Sufficient and necessary conditions for hereditarity of infinite category algebras