DiskPart Volume Numbers ?

Can anyone tell me the algorithm that DiskPart uses to assign volume
numbers to volumes created on Dynamic disks.

The algorithm that I thought was correct has suddenly broken and I can’t
spot how to re-order my volume list. I use both the mount manager APIs and
a scan of the LDM database to acquire the volume information, but I need to
match and be able to associate each volume with the number generated by

Any help appreciated.