Module crossutil
[hide private]
[frames] | no frames]

Module crossutil

source code

crossutil

Contains all sort of utilities to search and manipulate nested lists in the context of strongly-typed crossover.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Author: by Mehdi Khoury

Version: 1.20

Copyright: (c) 2009 Mehdi Khoury under the mit license http://www.opensource.org/licenses/mit-license.html

Functions [hide private]
 
BillSubtreeIndices(tree_rep)
gives the indexes of nested lists by depth original idea from bill at python-forum.org
source code
 
BillSubtreeIndices2(tree_rep)
gives the indexes of nested lists by depth original idea from bill at python-forum.org
source code
 
GetIndicesMappingFromTree(tree)
reuse bill's idea to gives the indexes of all nodes (may they be a sub tree or a single leaf) gives a list of indices of every sublist.
source code
 
GetDepthFromIndicesMapping(list_indices)
Gives the depth of the nested list from the index mapping
source code
 
GetPackedListIndicesAtDepth(list_indices, depth)
gives the indexes of nested lists at a specific depth.
source code
 
UnpackIndicesFromList(map_indices)
unpack_indices_from_list.
source code
 
GetDepth(tree_rep)
Gives the depth of the nested list.
source code
 
IndexLstToIndexStr(index)
transform a list into an index element e.g.
source code
 
IndexLstToIndexStr2(index)
transform a list into an index element this version is 15% faster transform a list into an index element e.g.
source code
Variables [hide private]
  __package__ = None
Function Details [hide private]

BillSubtreeIndices(tree_rep)

source code 

BillSubtreeIndices

gives the indexes of nested lists by depth original idea from bill at python-forum.org

Parameters:
  • tree_rep - a nested list representing a tree
Returns:
a list representing the indexes of the nested lists by depth

BillSubtreeIndices2(tree_rep)

source code 

BillSubtreeIndices2

gives the indexes of nested lists by depth original idea from bill at python-forum.org

Parameters:
  • tree_rep - a nested list representing a tree
Returns:
a dictionary representing the indexes of the nested lists by depth

GetIndicesMappingFromTree(tree)

source code 

GetIndicesMappingFromTree

reuse bill's idea to gives the indexes of all nodes (may they be a sub tree or a single leaf) gives a list of indices of every sublist. To do that, I add one thing: the last element of an index is the length of the present list. e.g.

  • get_indices_mapping_from_tree([1,2,3,4,5,6,7,8,9]) gives: [([0], 9)]
  • get_indices_mapping_from_tree([1,[2,3],4,5,6,7,8,9]) gives: [([0], 8), ([1], 2)]
  • get_indices_mapping_from_tree([1,[2,3,7],4,5,6,7,8,9]) gives: [([0], 8), ([1], 3)]
  • get_indices_mapping_from_tree([1,[2,3,7],4,[5,[6,[7,8,9]]]]) gives: [([0], 4), ([1], 3), ([3], 2), ([3, 1], 2), ([3, 1, 1], 3)]
Parameters:
  • tree - a nested list representing a tree
Returns:
a nested list representing the indexes of the nested lists by depth

GetDepthFromIndicesMapping(list_indices)

source code 

GetDepthFromIndicesMapping

Gives the depth of the nested list from the index mapping

Parameters:
  • list_indices - a nested list representing the indexes of the nested lists by depth
Returns:
depth

GetPackedListIndicesAtDepth(list_indices, depth)

source code 

GetPackedListIndicesAtDepth

gives the indexes of nested lists at a specific depth. Only works if the map of indices has been done

Parameters:
  • list_indices - a nested list representing the indexes of the nested lists by depth
  • depth - depth at which we wnat the indexes
Returns:
a nested list representing the indexes of the nested lists at a specific depth

UnpackIndicesFromList(map_indices)

source code 

UnpackIndicesFromList

unpack_indices_from_list. e.g. ([([1], 6), ([2], 4)]) gives: [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3]]

Parameters:
  • map_indices - a nested list representing the indexes of the nested lists by depth
Returns:
the indexes of different nodes in the tree as a flat list

GetDepth(tree_rep)

source code 

GetDepth

Gives the depth of the nested list. Slow recursive way.

Parameters:
  • tree_rep - a nested list representing a tree
Returns:
depth

IndexLstToIndexStr(index)

source code 

IndexLstToIndexStr

transform a list into an index element e.g. list named 'a' and index ref is [1,1,2], result is '[1][1][2]'

Parameters:
  • index - a flat list of indexes
Returns:
a string

IndexLstToIndexStr2(index)

source code 

IndexLstToIndexStr2

transform a list into an index element this version is 15% faster transform a list into an index element e.g. list named 'a' and index ref is [1,1,2], result is '[1][1][2]'

Parameters:
  • index - a flat list of indexes
Returns:
a string