HWRF  trunk@4391
Public Member Functions | Public Attributes | List of all members
hwrf.numerics.partial_ordering Class Reference

Sorts a pre-determined list of objects, placing unknown items at a specified location. More...

Detailed Description

Sorts a pre-determined list of objects, placing unknown items at a specified location.

This class is a drop-in replacement for cmp in sorting routines. It represents a partial ordering of objects by specifying the order of a known subset of those objects, and inserting all unknown objects in a specified location in the that list (at the end, by default) in an order determined by cmp(a,b). Example:

1 p=partial_ordering([3,2,1]) # list is ordered as [3,2,1] with
2  # everything else after that
3 
4 sorted([0,1,2,3,6,4,5],p) # = [3, 2, 1, 0, 4, 5, 6]
5 p(1,-99) # = -1, so -99 goes after 1 since -99 is not
6  # in the partial ordering
7 p(1,3) # = 1, so 3 goes before 1 since 3 is before 1
8  # in the partial ordering
9 p(5,10) # = -1 since cmp(5,10)=-1

Definition at line 21 of file numerics.py.

Inheritance diagram for hwrf.numerics.partial_ordering:

Public Member Functions

def __init__
 partial_ordering constructor. More...
 
def __call__ (self, a, b)
 Determine the ordering of a and b. More...
 

Public Attributes

 order
 Internal ordering information.
 
 backupcmp
 Backup comparison function for tiebreaking.
 
 unordered
 Unordered element index.
 

Constructor & Destructor Documentation

def hwrf.numerics.partial_ordering.__init__ (   self,
  ordering,
  unordered = None,
  backupcmp = cmp 
)

partial_ordering constructor.

Creates a partial ordering. The subset that is ordered is specified by the ordered iterable "ordered" while the index at which to place unordered values is optionally specified by "unordered", which can be anything that can be cmp()'ed to an int. If "unordered" is missing, then all objects not in "ordered" will be placed at the end of any list. To place at the beginning of the list, give unordered=0. To insert between the first and second elements, specify 1, between second and third elements: specify unordered=2, and so on. Specify another tiebreaker "cmp" function with "backupcmp" (default: cmp).

Parameters
orderingthe ordering of known objects
unorderedOptional: where to put other objects
backupcmpTiebreaker comparison function.

Definition at line 42 of file numerics.py.

Member Function Documentation

def hwrf.numerics.partial_ordering.__call__ (   self,
  a,
  b 
)

Determine the ordering of a and b.

Parameters
a,bthe objects to order
Returns
-1 if b>a, 1 if b<a, 0 if b and a belong in the same index.

Definition at line 86 of file numerics.py.


The documentation for this class was generated from the following file: