org.pealfactory.compose.halfleadspliced
Class RowNode

java.lang.Object
  |
  +--org.pealfactory.ring.Row
        |
        +--org.pealfactory.ring.ImmutableRow
              |
              +--org.pealfactory.compose.halfleadspliced.RowNode
All Implemented Interfaces:
java.lang.Cloneable, Constants

class RowNode
extends ImmutableRow

Represent a single Row together with precalculated table values to increase performance. Every RowNode has a table of pointers (fPermLinks) to those RowNodes which would be reached by every possible place notation permutation in the table of methods. This means expensive place notation operations are not longer necessary - a change can be generated simply by accessing the fPermLink array.

For those RowNodes representing potential leadheads (i.e. any with the treble home) the fPermLinks array also contain pointers to the nodes which would be reached by permutation with any of the leadheads in the table of methods. The leadhead of a composition can therefore be generated by a single table lookup.

Leadhead nodes also contain a table of precalculated music scores for every method (fLeadMusic). This allows music scoring to proceed with just one operation per lead.

For this class, performance is all!


Field Summary
private  boolean fLeadhead
          true if treble at lead
private  int fLeadheadNumber
          Only valid if treble home
private  int[] fLeadMusic
          Only set if treble home: music for entire lead of each (composite) method
private  int fLeadsTillTenorsHome
          Only valid if treble home and tenors together
private  int fMusic
          Music score for this one row
private  boolean fNicePartEnd
           
private  int fNodeNumber
           
private  int fNParts
           
private  RowNode[] fPermLinks
           
private  int fRegenOffset
           
 
Fields inherited from class org.pealfactory.ring.ImmutableRow
fHashcode, fHashcodeSet, fPBRow, fPBRowSet, fRounds, fTenorsHome, fTenorsTogether, fTHSet, fTTSet, kROUNDS_ROW
 
Fields inherited from class org.pealfactory.ring.Row
fNBells, fRow
 
Fields inherited from interface org.pealfactory.ring.Constants
kCALL_BOB, kCALL_EXTREME, kCALL_PLAIN, kCALL_SINGLE, kCALL_USER, kCHAR_CROSS, kCHAR_LH, kMAXNBELLS, kMINNBELLS, kROUNDS
 
Constructor Summary
(package private) RowNode(Row row, Tables tables)
           
 
Method Summary
protected  void calcLeadMusic(Method method)
           
protected  void calcLeadsToTenorsHome(Method method0)
          Must ONLY be called on tenors-together nodes with the treble leading.
protected  void calcMusicScore(Music[] music)
           
private  void calcNicePartEnd(Music[] parts)
           
private  void calcPartStats()
           
(package private)  boolean calcPermLinks(Tables tables, byte[][] pnPerms, byte[][] leadheadPerms)
          Returns false if error.
 int getLeadheadNumber()
          Final for speed.
 int getLeadMusic(int m)
          Gets music for entire lead.
 int getMusic()
          Final for speed (inlining)
 int getNodeNumber()
          Final for speed (inlining)
 int getNParts()
          Final for speed (inlining)
 int getRegenOffset()
          Final for speed.
 boolean isLeadhead()
          Returns true if treble at lead for this row.
 boolean isNicePartEnd()
          Final for speed (inlining)
 RowNode permute(int permNum)
          Final for speed (inlining)
private  int score(Music music)
          Final for speed.
 void setLeadheadNumber(int leadheadNumber)
           
 void setRegenOffset(boolean tenorsTogether)
          Should only be called on tenors-together leadhead nodes.
 
Methods inherited from class org.pealfactory.ring.ImmutableRow
applyPermutation, applyPermutation, applyPN, change, hashCode, isPBrow, isRounds, isTenorsHome, isTenorsTogether, permute, permute, setRow, setRow, swap
 
Methods inherited from class org.pealfactory.ring.Row
bellAt, calcPermutation, clone, equals, findBell, getNBells, isPBrow, nextCourseBell, nextCourseBellNoTreble, setNBells, test, toBytes, toString
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

fNodeNumber

private int fNodeNumber

fMusic

private int fMusic
Music score for this one row

fPermLinks

private RowNode[] fPermLinks

fLeadhead

private boolean fLeadhead
true if treble at lead

fLeadMusic

private int[] fLeadMusic
Only set if treble home: music for entire lead of each (composite) method

fLeadheadNumber

private int fLeadheadNumber
Only valid if treble home

fNParts

private int fNParts

fNicePartEnd

private boolean fNicePartEnd

fLeadsTillTenorsHome

private int fLeadsTillTenorsHome
Only valid if treble home and tenors together

fRegenOffset

private int fRegenOffset
Constructor Detail

RowNode

RowNode(Row row,
        Tables tables)
Method Detail

permute

public final RowNode permute(int permNum)
Final for speed (inlining)

getNodeNumber

public final int getNodeNumber()
Final for speed (inlining)

getLeadheadNumber

public final int getLeadheadNumber()
Final for speed.

setLeadheadNumber

public void setLeadheadNumber(int leadheadNumber)

getMusic

public final int getMusic()
Final for speed (inlining)

isLeadhead

public final boolean isLeadhead()
Returns true if treble at lead for this row. Final for speed (inlining)

getNParts

public final int getNParts()
Final for speed (inlining)

isNicePartEnd

public final boolean isNicePartEnd()
Final for speed (inlining)

getLeadMusic

public final int getLeadMusic(int m)
Gets music for entire lead. Final for speed.

calcLeadMusic

protected final void calcLeadMusic(Method method)

getRegenOffset

public final int getRegenOffset()
Final for speed.

setRegenOffset

public final void setRegenOffset(boolean tenorsTogether)
Should only be called on tenors-together leadhead nodes. If tenorsTogether parameter is true, sets fRegenOffset to be equal to -fLeadsToTenorsHome, which must already have been set for the 0th method in the search by calcLeadsToTenorsHome(). Otherwise, fRegenOffset is set to 0.

calcPermLinks

boolean calcPermLinks(Tables tables,
                      byte[][] pnPerms,
                      byte[][] leadheadPerms)
Returns false if error. LeadheadPerms are perms backstroke lh to handstroke le. Very important - this call also clears out the node-music table, so MUST BE CALLED whenever the methods list is changed (even if it is only re-ordered).

calcNicePartEnd

private void calcNicePartEnd(Music[] parts)

calcLeadsToTenorsHome

protected void calcLeadsToTenorsHome(Method method0)
Must ONLY be called on tenors-together nodes with the treble leading. May fail for differential methods!

calcMusicScore

protected void calcMusicScore(Music[] music)

score

private final int score(Music music)
Final for speed.

calcPartStats

private void calcPartStats()