misc Package

misc Package

This module contains several useful functions and classes that dont fit in any other modules.

progress_display Module

Displays the progress during the computing.

class ABXpy.misc.progress_display.ProgressDisplay[source]

Bases: object

add(name, message, total)[source]
display()[source]
update(name, amount)[source]

tinytree Module

class ABXpy.misc.tinytree.Tree(children=None)[source]

Bases: object

A simple implementation of an ordered tree

addChild(node)[source]

Add a child to this node.

:child A Tree object

addChildrenFromList(children)[source]

Add children to this node.

:children A nested list specifying a tree of children

attrsToRoot(attr)[source]

Traverses the path from this node to the root of the tree, and yields a value for each attribute. Nodes that do not have the attribute and attribute values that test false are ignored.

:attr A string attribute name

clear()[source]

Clear all the children of this node. Return a list of the removed children.

count()[source]

Number of nodes in this tree, including the root.

dump(outf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Dump a formatted representation of this tree to the specified file descriptor.

:outf Output file descriptor.

findAttr(attr, default=None)[source]

Traverses the path to the root of the tree, looking for the specified attribute. If it is found, return it, else return default.

:attr A string attribute name :default Arbitrary default return value

findBackwards(*func, **kwargs)[source]

Search backwards in a preOrder traversal of the whole tree (not this node’s subnodes). Return None if object not found.

:func A list of selector functions, that accept a node, and return a boolean.

:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.

findChild(*func, **kwargs)[source]

Find the first child matching all specified selectors in a pre-order traversal of this node’s subnodes. Return None if no matching object is found.

:func A list of selector functions, that accept a node, and return a boolean.

:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.

findForwards(*func, **kwargs)[source]

Search forwards in a preOrder traversal of the whole tree (not this node’s subnodes). Return None if object not found.

:func A list of selector functions, that accept a node, and return a boolean.

:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.

findParent(*func, **kwargs)[source]

Find the first node matching func in a traversal to the root of the tree. Return None if no matching object is found.

:func A list of selector functions, that accept a node, and return a boolean.

:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.

getDepth()[source]

Return the depth of this node, i.e. the number of nodes on the path to the root.

getNext()[source]

Find the next node in the preOrder traversal of the tree.

getPrevious()[source]

Find the previous node in the preOrder traversal of the tree.

getRoot()[source]

Return the topmost node in the tree.

index()[source]

Return the index of this node in the parent child list, based on object identity.

inject(node)[source]

Inserts a node between the current node and its children. Returns the specified parent node.

:node A Tree object

isDescendantOf(node)[source]

Returns true if this node lies on the path to the root from the specified node.

:node A Tree object

isSiblingOf(node)[source]

Returns true if this node is a sibling of the specified node.

:node A Tree object

pathFromRoot()[source]

Generator yielding all nodes on the path to this node from the root of the tree, including this node itself.

pathToRoot()[source]

Generator yielding all objects on the path from this node to the root of the tree, including this node itself.

postOrder()[source]

Return a list of the subnodes in PostOrder.

preOrder()[source]

Return a list of subnodes in PreOrder.

register(parent)[source]

Called after a node has been added to a parent.

:child A Tree object

remove()[source]

Remove this node from its parent. Returns the index this node had in the parent child list.

reparent(node)[source]

Inserts a node between the current node and its parent. Returns the specified parent node.

:node A Tree object

replace(*nodes)[source]

Replace this node with a sequence of other nodes. This is equivalent to deleting this node from the child list, and then inserting the specified sequence in its place.

:nodes A sequence of Tree objects

siblings()[source]

Generator yielding all siblings of this node, including this node itself.

static treeProp(name)[source]

Define a property whose value should be looked up on nodes between this node and the root, inclusive. Returns the first matching attribute. Raises ValueError if no matching attribute is found.

:name Property name

ABXpy.misc.tinytree.constructFromList(lst)[source]

:lst a nested list of Tree objects

Returns a list consisting of the nodes at the base of each tree. Trees are constructed “bottom-up”, so all parent nodes for a particular node are guaranteed to exist when “addChild” is run.

type_fitting Module

ABXpy.misc.type_fitting.fit_integer_type(n, is_signed=True)[source]

Returns the minimal space needed to store integers of maximal value n