codesimian
Class CharTree

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.SimpleList
              extended by codesimian.CharTree
All Implemented Interfaces:
CodeSimian

public class CharTree
extends SimpleList

a tree of chars. For efficiency, the nodes directly above the leafs contain char[] arrays. Each leaf node is 1 char, not an object. THIS CLASS CONTAINS COPIED CODE FROM STRINGTREE.JAVA WHICH NEEDS TO BE REMOVED


Nested Class Summary
static class CharTree.CharTreeNode
          exactly 1 of nonLeafChilds[] or leafs[] is null at any 1 time.
 
Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Constructor Summary
CharTree()
           
 
Method Summary
static CharTree.CharTreeNode balancedCopyOf(CharTree.CharTreeNode anyRoot)
          Gets the tree as a char[] array and rebuilds it trying to get targetLeafSize and targetInternalNodeChilds in as many nodes as possible.
 int countP()
          Quantity of params.
 boolean deleteP(int index)
          WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.
 double DForProxy()
          returns this.countP().
 boolean insertC(int index, char value)
           
 boolean insertP(int index, CS value)
          same as setP(int,CS) but inserts instead of overwriting.
 byte isIllusion(int index)
          Describes if the CS in an index is an illusion or not.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int maxP()
          Maximum quantity of Params
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 CS P(int index)
          WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().
 CharTree.CharTreeNode[] pathToIndex(int index)
          index 0 in the returned array contains the root.
 char PC(int index)
           
 void possibleBalancing()
          call this function every time chars are added to this CharTree.
 boolean setC(int index, char value)
           
 boolean setP(int index, CS value)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 
Methods inherited from class codesimian.DefaultCS
B, C, decrementMyFuel, description, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, prevD, prevL, PType, S, setB, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setPrevExec, setPType, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, JForProxy, L, L, L, L, L, maxD, minD, overwrites, parent, parsePriority, PB, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharTree

public CharTree()
Method Detail

DForProxy

public double DForProxy()
Description copied from class: SimpleList
returns this.countP(). This list does nothing.

Overrides:
DForProxy in class SimpleList

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class SimpleList
See Also:
CS.parent(), CS.newInstance(), CS.name()

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class SimpleList

maxP

public int maxP()
Description copied from class: CS
Maximum quantity of Params

Overrides:
maxP in class SimpleList

countP

public int countP()
Description copied from class: CS
Quantity of params. Should be between minP() and maxP() inclusive when you EXECUTE this CS. Can be below minP() for a short time during compiling, but you must not EXECUTE this CS during that time.

Overrides:
countP in class DefaultCS

P

public CS P(int index)
Description copied from class: DefaultCS
WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().

Overrides:
P in class DefaultCS
Parameters:
index - range 0 (or neg?) to countP()-1 inclusive
See Also:
CS.heap()

PC

public char PC(int index)
Overrides:
PC in class CS
See Also:
CS.PD(int)

setP

public boolean setP(int index,
                    CS value)
Description copied from class: CS
Every CS is a list of other CSs, between size minP() and maxP() inclusive. setP overwrites one of those CSs or adds a new one at the end, depending on the index. If index is between 0 and countP()-1, overwrites. If it equals countP(), adds at end.

Overrides:
setP in class DefaultCS

setC

public boolean setC(int index,
                    char value)
Overrides:
setC in class DefaultCS
See Also:
CS.setD(int,double)

insertP

public boolean insertP(int index,
                       CS value)
Description copied from class: CS
same as setP(int,CS) but inserts instead of overwriting. All higher params slide up 1 index.

Overrides:
insertP in class DefaultCS

insertC

public boolean insertC(int index,
                       char value)
Overrides:
insertC in class DefaultCS
See Also:
CS.insertD(int,double)

deleteP

public boolean deleteP(int index)
Description copied from class: DefaultCS
WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.

Overrides:
deleteP in class DefaultCS

isIllusion

public byte isIllusion(int index)
Description copied from class: CS
Describes if the CS in an index is an illusion or not. Example (S extends CS): new S("8fakeCSs") contains a String containing 8 chars. It only appears to contain 8 CSs. new S("8fakeCSs").P(3) returns the same as Const.pool('k'); //P(4).C() == 'e' Therefore S should override isIllusion to return 1 for every index.

Since illusions are constantly overwritten (to give the illusion that they change), if isIllusion(x)==1 then it must be true that: overwrites(x)==1 or overwrites(x)==0. It may equal 0 because that says you dont know (even though it is true).

Overrides:
isIllusion in class CS
See Also:
CS.overwrites(int), S.isIllusion(int)

pathToIndex

public CharTree.CharTreeNode[] pathToIndex(int index)
index 0 in the returned array contains the root. Last index contains the target of index.


possibleBalancing

public void possibleBalancing()
call this function every time chars are added to this CharTree. There is a small chance it will call functions to balance the tree or parts of the tree. This prevents the tree from becoming too much like a linked-list (branching only in 1 direction).


balancedCopyOf

public static CharTree.CharTreeNode balancedCopyOf(CharTree.CharTreeNode anyRoot)
Gets the tree as a char[] array and rebuilds it trying to get targetLeafSize and targetInternalNodeChilds in as many nodes as possible.

This function is most efficiently used if you only balance sub-trees that are too deep. Its inefficient to call this on small subtrees. Better on medium sized subtrees.

Because I havent yet coded a gradual tree balancer, this function needs to be called when tree becomes too deep, which needs to be checked for every 100 chars inserted into the tree.