Hi everybody!
I have a problem with Materialized path, so I thought may be here somebody can help me. I wrote a class which provides operations with Materialized path such as add, edit, delete and move. It's pretty easy, but I have a problem with tree normalization.
Imagine we have the following tree:
1.1
1.2
1.4
1.4.1
1.6
1.8.2.1
and we need to change it to:
1.1
1.2
1.3
1.3.1
1.4
1.5
How can we do it? I mean can somebody give an algorithm?
Page 1 of 1
Materialized Path, tree normalization
#2
Posted 07 April 2012 - 07:53 AM
Well, you could simply rebuild the tree. The indices should re-arrange that way.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
#4
Posted 07 April 2012 - 09:58 AM
Just iterate over your tree with array_values(). Take the new array keys and separate them with a dot => all done.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
#5
Posted 07 April 2012 - 10:12 AM
If it were so simple, I wouldn't have created the topic. I understand the need to go through the array and rebuild it, but you need to take into account the nesting level...
#6
Posted 07 April 2012 - 10:26 AM
Pardon me. I forgot the word "recursive". So, walklt over your tree recursively
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
#7
Posted 07 April 2012 - 11:30 AM
You know what algorithm? What I read above, it seems to me to banter...
Share this topic:
Page 1 of 1

Help














