Typewise structured sorting for arbirarily complex data structures