Dependence of magnetoresistivity on charge-carrier density in metallic ferromagnets and doped magnetic semiconductors