Package CedarBackup2 :: Module util :: Class UnorderedList
[show private | hide private]
[frames | no frames]

Type UnorderedList

object --+    
         |    
      list --+
             |
            UnorderedList

Known Subclasses:
AbsolutePathList, ObjectTypeList, RestrictedContentList

Class representing an "unordered list".

An "unordered list" is a list in which only the contents matter, not the order in which the contents appear in the list.

For instance, we might be keeping track of set of paths in a list, because it's convenient to have them in that form. However, for comparison purposes, we would only care that the lists contain exactly the same contents, regardless of order.

I have come up with two reasonable ways of doing this, plus a couple more that would work but would be a pain to implement. My first method is to copy and sort each list, comparing the sorted versions. This will only work if two lists with exactly the same members are guaranteed to sort in exactly the same order. The second way would be to create two Sets and then compare the sets. However, this would lose information about any duplicates in either list. I've decided to go with option #1 for now. I'll modify this code if I run into problems in the future.

We override the original __eq__, __ne__, __ge__, __gt__, __le__ and __lt__ list methods to change the definition of the various comparison operators. In all cases, the comparison is changed to return the result of the original operation but instead comparing sorted lists. This is going to be quite a bit slower than a normal list, so you probably only want to use it on small lists.
Method Summary
  __eq__(self, other)
Definition of == operator for this class.
  __ge__(self, other)
Definition of ≥ operator for this class.
  __gt__(self, other)
Definition of > operator for this class.
  __le__(self, other)
Definition of ≤ operator for this class.
  __lt__(self, other)
Definition of < operator for this class.
  __ne__(self, other)
Definition of != operator for this class.
    Inherited from list
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __add__(x, y)
x.__add__(y) <==> x+y
  __contains__(x, y)
x.__contains__(y) <==> y in x
  __delitem__(x, y)
x.__delitem__(y) <==> del x[y]
  __delslice__(x, i, j)
Use of negative indices is not supported.
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __getitem__(x, y)
x.__getitem__(y) <==> x[y]
  __getslice__(x, i, j)
Use of negative indices is not supported.
  __hash__(x)
x.__hash__() <==> hash(x)
  __iadd__(x, y)
x.__iadd__(y) <==> x+=y
  __imul__(x, y)
x.__imul__(y) <==> x*=y
  __iter__(x)
x.__iter__() <==> iter(x)
  __len__(x)
x.__len__() <==> len(x)
  __mul__(x, n)
x.__mul__(n) <==> x*n
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __repr__(x)
x.__repr__() <==> repr(x)
  __rmul__(x, n)
x.__rmul__(n) <==> n*x
  __setitem__(x, i, y)
x.__setitem__(i, y) <==> x[i]=y
  __setslice__(x, i, j, y)
Use of negative indices is not supported.
  append(...)
L.append(object) -- append object to end
  count(L, value)
L.count(value) -> integer -- return number of occurrences of value
  extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
  index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
  insert(...)
L.insert(index, object) -- insert object before index
  pop(L, index)
L.pop([index]) -> item -- remove and return item at index (default last)
  remove(...)
L.remove(value) -- remove first occurrence of value
  reverse(...)
L.reverse() -- reverse *IN PLACE*
  sort(...)
L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

__eq__(self, other)
(Equality operator)

Definition of == operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self == other.
Overrides:
__builtin__.list.__eq__

__ge__(self, other)
(Greater-than-or-equals operator)

Definition of ≥ operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self >= other.
Overrides:
__builtin__.list.__ge__

__gt__(self, other)
(Greater-than operator)

Definition of > operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self > other.
Overrides:
__builtin__.list.__gt__

__le__(self, other)
(Less-than-or-equals operator)

Definition of ≤ operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self <= other.
Overrides:
__builtin__.list.__le__

__lt__(self, other)
(Less-than operator)

Definition of < operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self < other.
Overrides:
__builtin__.list.__lt__

__ne__(self, other)

Definition of != operator for this class.
Parameters:
other - Other object to compare to.
Returns:
True/false depending on whether self != other.
Overrides:
__builtin__.list.__ne__

Generated by Epydoc 2.1 on Thu Dec 22 20:45:14 2005 http://epydoc.sf.net