CedarBackup2.util.UnorderedList

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

# Class UnorderedList

source code

    object --+
             |
          list --+
                 |
                UnorderedList

Known Subclasses:
  - AbsolutePathList
  - , ObjectTypeList
  - , RegexList
  - , RegexMatchList
  - , 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.

Instance Methods | [hide private]
__eq__(self, other) Definition of `==` operator for this class. | source code
__ne__(self, other) Definition of `!=` operator for this class. | source code
__ge__(self, other) Definition of ≥ operator for this class. | source code
__gt__(self, other) Definition of `>` operator for this class. | source code
__le__(self, other) Definition of ≤ operator for this class. | source code
__lt__(self, other) Definition of `<` operator for this class. | source code
Inherited from `list`: `__add__`, `__contains__`, `__delitem__`, `__delslice__`, `__getattribute__`, `__getitem__`, `__getslice__`, `__iadd__`, `__imul__`, `__init__`, `__iter__`, `__len__`, `__mul__`, `__new__`, `__repr__`, `__reversed__`, `__rmul__`, `__setitem__`, `__setslice__`, `__sizeof__`, `append`, `count`, `extend`, `index`, `insert`, `pop`, `remove`, `reverse`, `sort` Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`, `__subclasshook__`

Class Variables | [hide private]
Inherited from `list`: `__hash__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __eq__(self, other) (Equality operator) | source code
Definition of `==` operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self == other`. Overrides: list.__eq__

### __ne__(self, other) | source code
Definition of `!=` operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self != other`. Overrides: list.__ne__

### __ge__(self, other) (Greater-than-or-equals operator) | source code
Definition of ≥ operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self >= other`. Overrides: list.__ge__

### __gt__(self, other) (Greater-than operator) | source code
Definition of `>` operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self > other`. Overrides: list.__gt__

### __le__(self, other) (Less-than-or-equals operator) | source code
Definition of ≤ operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self <= other`. Overrides: list.__le__

### __lt__(self, other) (Less-than operator) | source code
Definition of `<` operator for this class. Parameters: `other` - Other object to compare to. Returns: True/false depending on whether `self < other`. Overrides: list.__lt__