Sort patterns according to priority and enable state