Package netaddr :: Package ip :: Module intset :: Class IntSet |
[hide private]
[frames] | no frames]

# Class IntSet

    object --+
             |
            IntSet

Integer set class with efficient storage in a RLE format of ranges. Supports minus and plus infinity in the range.

Instance Methods | [hide private]
__init__(self, *args, **kwargs) Initialize an integer set. |
_iterranges(self, r1, r2, minval=None, maxval=None) |
_normalize(self) |
__coerce__(self, other) |
__and__(self, other) Intersection of two sets as a new set. |
__rand__(self, other) Intersection of two sets as a new set. |
intersection(self, other) Intersection of two sets as a new set. |
__or__(self, other) Union of two sets as a new set. |
__ror__(self, other) Union of two sets as a new set. |
union(self, other) Union of two sets as a new set. |
__sub__(self, other) Difference of two sets as a new set. |
__rsub__(self, other) Difference of two sets as a new set. |
difference(self, other) Difference of two sets as a new set. |
__xor__(self, other) Symmetric difference of two sets as a new set. |
__rxor__(self, other) Symmetric difference of two sets as a new set. |
symmetric_difference(self, other) Symmetric difference of two sets as a new set. |
__contains__(self, other) Returns true if self is superset of other. |
issubset(self, other) Returns true if self is subset of other. |
istruesubset(self, other) Returns true if self is true subset of other. |
issuperset(self, other) Returns true if self is superset of other. |
istruesuperset(self, other) Returns true if self is true superset of other. |
overlaps(self, other) Returns true if self overlaps with other. |
__eq__(self, other) Returns true if self is equal to other. |
__ne__(self, other) Returns true if self is different to other. |
inverse(self) Inverse of set as a new set. |
__invert__(self) Inverse of set as a new set. |
__hash__(self) Returns a hash value representing this integer set. |
__len__(self) Get length of this integer set. |
len(self) Returns the length of this integer set as an integer. |
__nonzero__(self) Returns true if this integer set contains at least one item. |
__iter__(self) Iterate over all values in this integer set. |
__repr__(self) Return a representation of this integer set. |
Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Properties | [hide private]
| _hash
| _max
| _min
| _ranges
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, *args, **kwargs) (Constructor) |
Initialize an integer set. The constructor accepts an unlimited number of arguments that may either be tuples in the form of (start, stop) where either start or stop may be a number or None to represent maximum/minimum in that direction. The range specified by (start, stop) is always inclusive (differing from the builtin range operator). Keyword arguments that can be passed to an integer set are min and max, which specify the minimum and maximum number in the set, respectively. You can also pass None here to represent minus or plus infinity, which is also the default. Overrides: object.__init__

### __hash__(self) (Hashing function) |
Returns a hash value representing this integer set. As the set is always stored normalized, the hash value is guaranteed to match for matching ranges. Overrides: object.__hash__

### __len__(self) (Length operator) |
Get length of this integer set. In case the length is larger than 2**31 (including infinitely sized integer sets), it raises an OverflowError. This is due to len() restricting the size to 0 <= len < 2**31.

### len(self) |
Returns the length of this integer set as an integer. In case the length is infinite, returns -1. This function exists because of a limitation of the builtin len() function which expects values in the range 0 <= len < 2**31. Use this function in case your integer set might be larger.

### __iter__(self) |
Iterate over all values in this integer set. Iteration always starts by iterating from lowest to highest over the ranges that are bounded. After processing these, all ranges that are unbounded (maximum 2) are yielded intermixed.

### __repr__(self) (Representation operator) |
Return a representation of this integer set. The representation is executable to get an equal integer set. Overrides: object.__repr__