matlab - How to organize a list of tags with IDs and subtag-relations into a nested structure? -


i have given 1xn-fields struct array nested n structs 3 fields:

  • id: unique numerical identifier
  • name: unique alphanumeric name
  • parent_id: parental relation id

the parental relation given parent_id, refers id under current id nesting, making current tag subtag. parent_id can blank, meaning current id @ root level , not nested under other id. example:

tags =      field1: [1x1 struct]     field2: [1x1 struct]  tags.field1 =             id: 1          name: 'tag1'     parent_id: []   tags.field2 =             id: 2          name: 'tag2'     parent_id: 1 

with struct tags above, field2 nested in field1 in tree diagram. leads me problem: how can reorganize data in given format efficiently generate text based tree diagrams , provide data further processing?

one approach tried reorganization whole bunch of nested structs, this:

tags_sorted =      field1: [1x1 struct]  tags_sorted.id_1 =             id: 1          name: 'tag1'     parent_id: []          id_2: [1x1 struct]  tags_sorted.id_1.id_2 =             id: 2          name: 'tag2'     parent_id: 1 

leading deeper , deeper nestings number of subtags of subtags (of subtags, of subbtags …) rises. not come algorithm capable of handling unlimited number of nestings.

any ideas that? i'm afraid input data structure of tags can not altered.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -