Libraries.Containers.TextTree Documentation

Inherits from: Libraries.Language.Object

Actions Documentation

Balance()

This action will create a new TextTree containing the balanced contents of this tree. This is typically handled automatically by the tree itself during other operations which return new TextTrees.

Return

Libraries.Containers.TextTree: A new TextTree which is balanced and contains the same text as this TextTree. use Libraries.Containers.TextTree TextTree tree tree:Initialize("Hello world!") boolean shouldRebalance = tree:NeedsBalancing() output "shouldRebalance is " + shouldRebalance if shouldRebalance tree:Balance() end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Concatenate(Libraries.Containers.TextTree textTree)

The Concatenate action creates a new TextTree where the provided tree is appended to the end of this tree. All text in the parameter tree will appear after the text from this tree inside the returned value. This tree will not change as a result of this action.

Parameters

Return

Libraries.Containers.TextTree: A new TextTree which contains the concatenation of the two trees.

Example

use Libraries.Containers.TextTree

TextTree tree1
tree1:Initialize("Hello ")

TextTree tree2
tree2:Initialize("world!")

TextTree result = tree1:Concatenate(tree2)
output result:GetText()

Concatenate(text value)

The Concatenate action creates a new TextTree where the provided text is appended to the end of this tree's text. This tree will not change as a result of this action.

Parameters

  • text value: The text to append onto the end of this tree's text.

Return

Libraries.Containers.TextTree: A new TextTree which contains the concatenation of this tree's text and the parameter text.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello ")

TextTree result = tree:Concatenate("world!")
output result:GetText()

Delete(integer startIndex, integer endIndex)

The Delete action creates a new TextTree which is a copy of this tree, then deletes all characters between the two given indices. The first index is inclusive (the character at the first index will be deleted) and the second index is exclusive (the character at the second index is not deleted). This action creates a new TextTree, and has no effect on this tree.

Parameters

  • integer startIndex: The beginning of the range of characters to delete. The character at this index is deleted.
  • integer endIndex: The end of the range of characters to delete. A character at this index is not deleted.

Return

Libraries.Containers.TextTree: A new TextTree containing this tree's text, minus the deleted portion.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")

TextTree deleteTree = tree:Delete(5, tree:GetLength() - 1)
output deleteTree:GetText()

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetCharacter(integer index)

This action retrieves a character at the given index from the tree.

Parameters

  • integer index: The index to retrieve a character from.

Return

text: A single character located at the given index.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")
text character = tree:GetCharacter(1)
output "The character at index 1 is '" + character + "'."

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetLeafSize()

This action returns how many characters can be stored in each leaf of the TextTree.

Return

integer: How many characters can be stored in each leaf.

Example

use Libraries.Containers.TextTree

TextTree defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

TextTree newTree
newTree:SetLeafSize(10)
newTree:Initialize("Hello world! What a lovely day!")
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

GetLength()

This action returns the length of the text stored in the TextTree.

Return

integer: The length of text in this TextTree.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")
output "The length of the text in the tree is " + tree:GetLength()

GetText(integer startIndex, integer endIndex)

This action returns the text between the two indices. The first index is inclusive (the character at the first index is part of the returned text) and the second index is exclusive (the character at the second index is not part of the returned text).

Parameters

  • integer startIndex: The beginning of the range of characters to return. This index is included in the returned value.
  • integer endIndex: The end of the range of characters to return. This index is not included in the returned value.

Return

text: The text between the two indices.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")
output tree:GetText(1, 10)

GetText()

This action returns all of the text stored in the TextTree.

Return

text: The text stored in this TextTree.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")
output tree:GetText()

Initialize(text value)

The Initialize action constructs the TextTree from a starting text value. The TextTree will store the given value, which may be retrieved or modified using the TextTree's other actions.

Parameters

  • text value: The value to be stored in this TextTree.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world! What a lovely day!")
output tree:GetText()

Initialize(text value, integer leafSize)

The Initialize action constructs the TextTree from a starting text value. The TextTree will store the given value, which may be retrieved or modified using the TextTree's other actions. The provided integer parameter will be used to set the maximum size of each leaf, in characters.

Parameters

  • text value: The value to be stored in this TextTree.
  • integer leafSize: How many characters should be stored in each leaf of the tree.

Example

use Libraries.Containers.TextTree

TextTree defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

TextTree newTree
newTree:Initialize("Hello world! What a lovely day!", 10)
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Insert(integer index, text value)

The Insert action creates a new TextTree and inserts the given text value into the tree at the provided index. The character that was previously located at that index will be positioned behind the newly inserted text. This action creates a new TextTree, and has no effect on this tree.

Parameters

  • integer index: The index to begin inserting text at in the new tree.
  • text value: The text to be inserted into the new tree.

Return

Libraries.Containers.TextTree: A new TextTree containing the inserted text.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")

TextTree insertTree = tree:Insert(11, " of tomorrow")
output insertTree:GetText()

NeedsBalancing()

This action returns true is the tree is imbalanced, or false if it is considered balanced. This is typically handled automatically by the tree itself.

Return

boolean: Whether or not the tree is currently imbalanced.

Example

use Libraries.Containers.TextTree

TextTree tree
tree:Initialize("Hello world!")
boolean shouldRebalance = tree:NeedsBalancing()
output "shouldRebalance is " + shouldRebalance

if shouldRebalance
    tree:Balance()
end

SetLeafSize(integer size)

This action sets how many characters should be stored in each leaf of the TextTree.

Parameters

  • integer size: How many characters to store in each leaf.

Example

use Libraries.Containers.TextTree

TextTree defaultTree
defaultTree:Initialize("Hello world! What a lovely day!")
output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

TextTree newTree
newTree:SetLeafSize(10)
newTree:Initialize("Hello world! What a lovely day!")
output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."