New function for fast degree calculation