DCPM: of trees and squishing

Steve Marvell steve at fysh.org
Tue Nov 26 10:02:14 CST 2002


Imagine a directory tree:

A -> B -> C -> D
       -> E -> F
       -> E -> G
H -> I -> J -> K
       -> L -> M
       -> N
       -> O -> P
  -> Q -> R
       -> S

etc

Now imagine directory entries:

bob (G,M)
fred (L,R)
jim (C,P,N,G)

I can't rely on them being in a nice order.

I want to basically form the subtree including only the sections
terminating in each of the of the nodes associated with the names.

ie. 

bob:

A -> B -> E -> G
H -> I -> L -> M

fred

H -> I -> L
  -> Q -> R

jim

A -> B -> C
       -> E -> G
H -> I -> N
       -> O -> P


With each entre in the tree, I've stored the ancestry, so I can easily
get:

jim

A -> B -> C
H -> I -> O -> P
H -> I -> N
A -> B -> E -> G

I just can't think of a great algorithm to combine them. I can think
of some bad ones, but no good ones.

So, imagine you have:

@v = ( [qw(A B C)] , [qw(H I O P)] , [qw(H I N)] , [qw(A B E G)] );

And now you want it in a reduced for which is suitable for printing in
the way above, say.

I suppose it could be done by pruning the main tree, but the size of
the small one is likely to be much much smaller than the main one. 

So, any thoughts?

Steve



More information about the Devoncornwall-pm mailing list