UnweightedSearchTree

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjadext/nauert/../../abjad/system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph "cluster_abjadext.nauert" { graph [label="abjadext.nauert"]; node [color=2]; "abjadext.nauert.SearchTree.SearchTree" [URL="../api/abjadext/nauert/SearchTree.html#abjadext.nauert.SearchTree.SearchTree", label="Search\nTree", shape=oval, style=bold, target=_top]; "abjadext.nauert.UnweightedSearchTree.UnweightedSearchTree" [URL="../api/abjadext/nauert/UnweightedSearchTree.html#abjadext.nauert.UnweightedSearchTree.UnweightedSearchTree", color=black, fontcolor=white, label="Unweighted\nSearch\nTree", target=_top]; "abjadext.nauert.SearchTree.SearchTree" -> "abjadext.nauert.UnweightedSearchTree.UnweightedSearchTree"; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } "abjad.system.AbjadObject.AbjadObject" -> "abjadext.nauert.SearchTree.SearchTree"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; }

class abjadext.nauert.UnweightedSearchTree.UnweightedSearchTree(definition=None)

Unweighted search tree based on Paul Nauert’s model.

>>> search_tree = abjadext.nauert.UnweightedSearchTree()
>>> abjad.f(search_tree)
abjadext.nauert.UnweightedSearchTree(
    definition={
        2: {
            2: {
                2: {
                    2: None,
                    },
                3: None,
                },
            3: None,
            5: None,
            7: None,
            },
        3: {
            2: {
                2: None,
                },
            3: None,
            5: None,
            },
        5: {
            2: None,
            3: None,
            },
        7: {
            2: None,
            },
        11: None,
        13: None,
        },
    )

The search tree defines how nodes in a QGrid may be subdivided, if they happen to contain QEvents (or, in actuality, QEventProxy instances which reference QEvents, but rescale their offsets between 0 and 1).

In the default definition, the root node of the QGrid may be subdivided into 2, 3, 5, 7, 11 or 13 equal parts. If divided into 2 parts, the divisions of the root node may be divided again into 2, 3, 5 or 7, and so forth.

This definition is structured as a collection of nested dictionaries, whose keys are integers, and whose values are either the sentinel None indicating no further permissable divisions, or dictionaries obeying these same rules, which then indicate the possibilities for further division.

Calling a UnweightedSearchTree with a QGrid instance will generate all permissable subdivided QGrids, according to the definition of the called search tree:

>>> q_event_a = abjadext.nauert.PitchedQEvent(130, [0, 1, 4])
>>> q_event_b = abjadext.nauert.PitchedQEvent(150, [2, 3, 5])
>>> proxy_a = abjadext.nauert.QEventProxy(q_event_a, 0.5)
>>> proxy_b = abjadext.nauert.QEventProxy(q_event_b, 0.667)
>>> q_grid = abjadext.nauert.QGrid()
>>> q_grid.fit_q_events([proxy_a, proxy_b])
>>> q_grids = search_tree(q_grid)
>>> for grid in q_grids:
...     print(grid.rtm_format)
(1 (1 1))
(1 (1 1 1))
(1 (1 1 1 1 1))
(1 (1 1 1 1 1 1 1))
(1 (1 1 1 1 1 1 1 1 1 1 1))
(1 (1 1 1 1 1 1 1 1 1 1 1 1 1))

A custom UnweightedSearchTree may be defined by passing in a dictionary, as described above. The following search tree only permits divisions of the root node into 2s and 3s, and if divided into 2, a node may be divided once more into 2 parts:

>>> definition = {2: {2: None}, 3: None}
>>> search_tree = abjadext.nauert.UnweightedSearchTree(definition)
>>> q_grids = search_tree(q_grid)
>>> for grid in q_grids:
...     print(grid.rtm_format)
(1 (1 1))
(1 (1 1 1))

Attributes Summary

default_definition The default search tree definition, based on the search tree given by Paul Nauert:

Special methods

(SearchTree).__call__(q_grid)

Calls search tree.

(SearchTree).__eq__(argument)

Is true when argument is a search tree with definition equal to that of this search tree. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(SearchTree).__hash__()

Hashes search tree.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Read-only properties

default_definition

The default search tree definition, based on the search tree given by Paul Nauert:

>>> import pprint
>>> search_tree = abjadext.nauert.UnweightedSearchTree()
>>> pprint.pprint(search_tree.default_definition)
{2: {2: {2: {2: None}, 3: None}, 3: None, 5: None, 7: None},
    3: {2: {2: None}, 3: None, 5: None},
    5: {2: None, 3: None},
    7: {2: None},
    11: None,
    13: None}

Returns dictionary.

(SearchTree).definition

The search tree definition.

Returns dictionary.