Python C3 manual calculation algorithm sequence algorithm computes the order manually Python C3

Python C3 manual calculation algorithm sequence

 

Manual calculation algorithm C3 class inherits principles:

  1. In a direct subclass of the number of required classes into the respective portions
  2. In order from left to right in order to write inheritance
  3. The first inheritance first, is the first occurrence in all subsequent relationships, extracted, replaced all other
  4. If in step 3 is not satisfied, go back to the part of
  5. Then keep looking at the back of this section, know that can not be found, then go back to the first part
  6. Until the end.

On the following example, look at how to apply

1 . Write class inheritance left to right, and a good part of the divided 
left | the right 
HGECA, HGEA, HGMX, HGMY | HFDBA, HFDCA, HFECA, HFEA
 2 merge process. 
H GECA, GEA, GMX, GMY | FDBA, FDCA, FECA, FEA 
first part a first G, are present in all parts of the first, or does not appear, you can extract 
HG ECA, EA, MX, MY | FDBA, FDCA, FECA, FEA 
, part I a first E, in the first part of both appear in the first place, but in the second part appeared in the non-first place, so to go to the status of part of the 
second part of the first first F, are all part of the first one appears, or does not appear, you can extract 
HGF ECA, EA, MX, MY | DBA, DCA, ECA, EA 
is still the second part, the second part of the first the first D, all parts are in first one appears, or does not appear, you can extract 
HGFD ECA, EA, MX, MY | BA, CA, ECA, EA 
second portion of the first first B, are all part of the first occurrence, or does not appear, you can extract
ECA HGFDB, EA, MX, MY |  A, CA, ECA, EA
second part of the first first A, in the second part appeared in the non-first place, to find the first part of 
the first part of the first the first E, are all part of the first one appears, or does not appear, you can extract 
HGFDB ECA, EA, MX, MY | a, CA, ECA, EA 
HGFDBE CA, a, MX, MY | a, CA, CA, a 
first portion of the first first C All are part of the first occurrence, or does not appear, you can extract 
HGFDBEC a, a, MX, MY | a, a, a, a 
first portion of the first first a, are all part of the first occurrence or does not appear, you can extract 
HGFDBECA MX, MY | 
HGFDBECAM the X-, the Y- | 
HGFDBECAMXY

D C1 B1 A1,D C1 B1 A2|D C2 B1 A1,D C2 B1 A2,D C2 B2 A2|D C3 B2 A2,D C3 B3 A2,D C3 B3 A3
D            C1 B1 A1,C1 B1 A2|C2 B1 A1,C2 B1 A2,C2 B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1        B1 A1,B1 A2|C2 B1 A1,C2 B1 A2,C2 B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2        B1 A1,B1 A2|B1 A1,B1 A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1        A1,A2|A1, A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1 A1        A2|A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1 A1 C3        A2|A2,B2 A2|B2 A2,B3 A2,B3 A3
D C1 C2 B1 A1 C3 B2        A2|A2,A2|A2,B3 A2,B3 A3
D C1 C2 B1 A1 C3 B2 B3        A2|A2,A2|A2,A2,A3
D C1 C2 B1 A1 C3 B2 B3 A2        A3
D C1 C2 B1 A1 C3 B2 B3 A2 A3

 

 
 
 

手动计算类继承C3算法原则:

  1. 以所求类的直接子类的数目分成相应部分
  2. 按照从左往右的顺序依次写出继承关系
  3. 继承关系第一个第一位,在所有后面关系都是第一个出现的,提取出来,其他都替换掉
  4. 如果步骤3中不成立,就到后面一部分去找
  5. 然后继续在后面这部分找,知道找不到,再回到第一部分去找
  6. 直到结束。

下面上例题,看下如何应用

1.从左到右依次写出类继承关系,并分好部分
左边|右边
HGECA,HGEA,HGMX,HGMY|HFDBA,HFDCA,HFECA,HFEA
2.合并过程
H                GECA,GEA,GMX,GMY|FDBA,FDCA,FECA,FEA
第一部分第一个第一位G,在所有部分均是第一个出现,或者未出现,可以提取
HG                ECA,EA,MX,MY|FDBA,FDCA,FECA,FEA
第一部分第一个第一位E,在第一部分均出现在首位,但是在第二部分出现在非首位,所以到到地位部分去找
第二部分第一个第一位F,在所有部分均是第一个出现,或者未出现,可以提取
HGF                ECA,EA,MX,MY|DBA,DCA,ECA,EA
现在还在第二部分,第二部分第一个第一位D,在所有部分均是第一个出现,或者未出现,可以提取
HGFD            ECA,EA,MX,MY|BA,CA,ECA,EA
第二部分第一个第一位B,在所有部分均是第一个出现,或者未出现,可以提取
HGFDB            ECA,EA,MX,MY|A,CA,ECA,EA
第二部分第一个第一位A,在第二部分出现在非首位,去第一部分去找
第一部分第一个第一位E,所有部分均是第一个出现,或者未出现,可以提取
HGFDB            ECA,EA,MX,MY|A,CA,ECA,EA
HGFDBE            CA,A,MX,MY|A,CA,CA,A
第一部分第一个第一位C,所有部分均是第一个出现,或者未出现,可以提取
HGFDBEC            A,A,MX,MY|A,A,A,A
第一部分第一个第一位A,所有部分均是第一个出现,或者未出现,可以提取
HGFDBECA        MX,MY|
HGFDBECAM        X,Y|
HGFDBECAMXY

D C1 B1 A1,D C1 B1 A2|D C2 B1 A1,D C2 B1 A2,D C2 B2 A2|D C3 B2 A2,D C3 B3 A2,D C3 B3 A3
D            C1 B1 A1,C1 B1 A2|C2 B1 A1,C2 B1 A2,C2 B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1        B1 A1,B1 A2|C2 B1 A1,C2 B1 A2,C2 B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2        B1 A1,B1 A2|B1 A1,B1 A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1        A1,A2|A1, A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1 A1        A2|A2,B2 A2|C3 B2 A2,C3 B3 A2,C3 B3 A3
D C1 C2 B1 A1 C3        A2|A2,B2 A2|B2 A2,B3 A2,B3 A3
D C1 C2 B1 A1 C3 B2        A2|A2,A2|A2,B3 A2,B3 A3
D C1 C2 B1 A1 C3 B2 B3        A2|A2,A2|A2,A2,A3
D C1 C2 B1 A1 C3 B2 B3 A2        A3
D C1 C2 B1 A1 C3 B2 B3 A2 A3

 

Guess you like

Origin www.cnblogs.com/taosiyu/p/11183410.html