org.pealfactory.compose.halfleadspliced
Class Tables

java.lang.Object
  extended by org.pealfactory.bronze.Tracker
      extended by org.pealfactory.compose.halfleadspliced.Tables
All Implemented Interfaces:
java.lang.Runnable, Trackable

 class Tables
extends Tracker

Calculates and holds tables of permutations and nodes - vital to the performance of Elf. There are five stages of table building which must all be performed before a search can begin:

  1. buildNodeTable() - this is performed once only, as it does not depend on choice of methods and music. It creates the initial table of 40320 RowNodes (note this is hardwired to 8 bells). Leadhead and tenors-together RowNodes are also identified during this process, and referenced by separate tables.
  2. prepareMusic() - must be performed if the music definition have changed. For each RowNode, it calculates a single music score value.
  3. prepareMethods() - must be performed if the methods have changed, even if only the order has been changed. For half-lead spliced searches, it creates the table of composite methods (a composite method has its first half-lead from one method and the second half-lead from another). It then populates the table of RowNodes with permutation links for all place notations and leadhead permutations in the table of methods.
  4. prepareLeadMusic() - must be performed if either the methods OR the music have changed. It calculates the tables of "lead music" for leadhead RowNodes. These tables are held in the appropriate RowNode and contain music counts for an entire lead of each method.
  5. prepareRegenPtrs() - must be performed before every search. Calculates regeneration pointers for the rotationally-sorted search.
Each of these table-build jobs can be monitored using the Tracker task-management system, except for the last one, which is too quick to bother with.


Field Summary
private  java.util.Hashtable fAllNodes
           
private  Method[] fCompositeMethods
           
private  RowNode[] fLeadheadNodes
           
private  java.util.Vector fLeadheadPerms
           
private  boolean fLeadMusicDirty
           
private  Method[] fMethods
           
private  boolean fMethodsDirty
           
private  Music[] fMusic
           
private  boolean fMusicDirty
           
private  int fNBells
           
private  int fNextLeadHeadNumber
           
private  int fNextNodeNumber
           
private  int fNextTTLeadNumber
           
private  java.util.Vector fPNPerms
          All permuatations stored in these Vectors are Strings, but with bell numbers stored as bytes 1..nbells.
private  boolean fTablePass1Done
          Set to true when tables are built (one-time only - not populated
private  RowNode[] fTenorsTogetherLeads
           
 
Fields inherited from class org.pealfactory.bronze.Tracker
kDEFAULT_JOB_NAME, kRESPONSE_TIME
 
Fields inherited from interface org.pealfactory.bronze.Trackable
kERROR_NONE
 
Constructor Summary
Tables()
           
 
Method Summary
protected  int addLeadheadPerm(byte[] perm)
           
protected  int addPNPerm(byte[] perm)
           
 void buildNodeTable()
          Table build pass 1 - not dependent on methods or music, so we can do it once only.
private  void generateNodes(Row row, int n)
           
 Method[] getCompositeMethods()
           
protected  java.lang.String[] getLeadheadPerms()
           
 Method[] getMethods()
           
 int getNBells()
          Final for speed
 int getNCompositeMethods()
           
 int getNLeadheadNodes()
          Final for speed
 int getNMethods()
           
 int getNNodes()
          Final for speed
 RowNode getNode(Row row)
          Final for speed
protected  int getNPnPerms()
           
protected  java.lang.String[] getPNPerms()
           
 boolean isBuilt()
          Returns true when pass 1 of table building done.
protected  int newNodeNumber()
           
private  boolean populateNodeTable()
          This MUST be called ANY TIME the method list is changed.
 void prepareLeadMusic()
          Table build pass 3 - precalculates the lead music counts.
 void prepareMethods()
          Table build pass 2
 void prepareMusic()
          Music calculation (per row, not the lead-music tables).
 void prepareRegenPtrs(boolean tenorsTogether)
          Table build pass 4 - sets up the regen backtrack offsets in tenors-together nodes.
 void setMethods(Method[] methods)
           
 void setMusic(Music[] music)
           
private  byte[][] toPermutationArray(java.lang.String[] perms)
           
 
Methods inherited from class org.pealfactory.bronze.Tracker
abort, abortWorker, endDelegateJob, getErrorMsg, getJobName, getProgress, getProgress, isAborted, isError, isFinished, isPaused, pause, reset, resume, run, setErrorMsg, setJobName, setProgress, setTotalDuration, startDelegateJob, startWorker, waitForResume
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fNBells

private int fNBells

fMethods

private Method[] fMethods

fCompositeMethods

private Method[] fCompositeMethods

fMusic

private Music[] fMusic

fAllNodes

private java.util.Hashtable fAllNodes

fNextNodeNumber

private int fNextNodeNumber

fTenorsTogetherLeads

private RowNode[] fTenorsTogetherLeads

fNextTTLeadNumber

private int fNextTTLeadNumber

fLeadheadNodes

private RowNode[] fLeadheadNodes

fNextLeadHeadNumber

private int fNextLeadHeadNumber

fMethodsDirty

private boolean fMethodsDirty

fMusicDirty

private boolean fMusicDirty

fLeadMusicDirty

private boolean fLeadMusicDirty

fTablePass1Done

private boolean fTablePass1Done
Set to true when tables are built (one-time only - not populated


fPNPerms

private java.util.Vector fPNPerms
All permuatations stored in these Vectors are Strings, but with bell numbers stored as bytes 1..nbells.


fLeadheadPerms

private java.util.Vector fLeadheadPerms
Constructor Detail

Tables

public Tables()
Method Detail

getNBells

public final int getNBells()
Final for speed


getNNodes

public final int getNNodes()
Final for speed


getNLeadheadNodes

public final int getNLeadheadNodes()
Final for speed


getNode

public final RowNode getNode(Row row)
Final for speed


isBuilt

public boolean isBuilt()
Returns true when pass 1 of table building done.


getNMethods

public final int getNMethods()

getMethods

public Method[] getMethods()

getNCompositeMethods

public final int getNCompositeMethods()

getCompositeMethods

public Method[] getCompositeMethods()

setMethods

public void setMethods(Method[] methods)

setMusic

public void setMusic(Music[] music)

newNodeNumber

protected int newNodeNumber()

getPNPerms

protected java.lang.String[] getPNPerms()

getNPnPerms

protected int getNPnPerms()

getLeadheadPerms

protected java.lang.String[] getLeadheadPerms()

addPNPerm

protected int addPNPerm(byte[] perm)

addLeadheadPerm

protected int addLeadheadPerm(byte[] perm)

buildNodeTable

public void buildNodeTable()
Table build pass 1 - not dependent on methods or music, so we can do it once only. NB also does music preparation for default music.


generateNodes

private void generateNodes(Row row,
                           int n)

prepareMusic

public void prepareMusic()
Music calculation (per row, not the lead-music tables). Must be done every time the music defs are changed.


prepareMethods

public void prepareMethods()
Table build pass 2


populateNodeTable

private boolean populateNodeTable()
This MUST be called ANY TIME the method list is changed. Amongst other things, this is essential in order to clear out the node-music tables. Because some tables use method index numbers, they are dependent on the order of the methods!


toPermutationArray

private final byte[][] toPermutationArray(java.lang.String[] perms)

prepareLeadMusic

public void prepareLeadMusic()
Table build pass 3 - precalculates the lead music counts. Must be called whenever the music OR the method tables are changed (even reordered).


prepareRegenPtrs

public void prepareRegenPtrs(boolean tenorsTogether)
Table build pass 4 - sets up the regen backtrack offsets in tenors-together nodes. Note that the regen offset is used to reset the regen pointer when backtracking; normally it is set to 0. This must be called before every search, but is very quick (<1ms).