[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: breadth-first search through multiple inheritance hierarchy??
- From: "Leo Razoumov" <slonik.az@...>
- Date: Tue, 26 Sep 2006 11:22:01 -0400
PiL2 as well as PiL1 has a section on multiple inheritance (section
16.3) complete with an example on how to implement multiple
inheritance in Lua. The problem with this implementation is that the
inheritance hierarchy is traversed in "depth-first" fashion. This has
a problem. Let say I have the following hierarchy
T--> M --> B [ B has "foo"]
\-> N [ N has "foo"]
If I try T.foo it will find B.foo because depth-first search visits
the whole T->M->B hierarchy before T->N. One gets "foo" from a
grandparent instead of a direct parent.
More natural way of traversing inheritance hierarchy would be a
"breadth-first search" when all immediate parents are visited first
followed by all the grandparents across all the parents and so on.
Is there any simple way to do breadth-first search in this case?
Conventional wisdom from CS books recommends to deploy a FIFO queue.