Yii Framework Forum: Materialized Path, tree normalization - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Materialized Path, tree normalization Rate Topic: -----

#1 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 07 April 2012 - 06:01 AM

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?
0

#2 User is online   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,214
  • Joined: 30-March 11
  • Location:Berlin, Germany

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
0

#3 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 07 April 2012 - 08:29 AM

May be I didn't understand you... How the index can help me?
0

#4 User is online   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,214
  • Joined: 30-March 11
  • Location:Berlin, Germany

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
0

#5 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

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...
0

#6 User is online   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,214
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 07 April 2012 - 10:26 AM

Pardon me. I forgot the word "recursive". So, walklt over your tree recursively :P
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#7 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 07 April 2012 - 11:30 AM

You know what algorithm? What I read above, it seems to me to banter...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users