Allows you to perform all operations on sets of numeric intervals.
Import classes from the main module of the package into your Python script.
from numeric_sets.main import Interval, NumericSet
main.main()
Feel free to perform any operation!
myset_1 = NumericSet()
myset_1.add(Interval(2, 4, True, True)) # [2, 4]
myset_1.add(Interval(5, 7)) # (5, 7)
myset_1.add(Interval(8, 10, is_end_inclusive=True)) # (8, 10]
myset_2 = NumericSet()
myset_2.add(Interval(2, 5)) # (2, 5)
myset_2.add(Interval(6, 9)) # (6, 9)
union = myset_1.union(
myset_2) # [2, 5) + (5, 10]
Returns formatted interval as a string.
my_interval = Interval(2, 5, is_start_inclusive=True)
my_interval.get_formatted()
Interval as a formatted string.
Determines whether the interval overlaps with the given interval.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
my_interval_1.is_overlapping(my_interval_2)
- interval a numeric interval
True if intervals overlap, False otherweise.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
my_interval_1.is_almost_overlapping(my_interval_2)
Determines whether the interval almost overlaps with the given interval.
- interval a numeric interval
True if intervals almost overlap, False otherweise.
Determines whether the interval includes the given point.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
my_interval_1.includes(my_interval_2)
- point a numeric point
True if the interval includes the given point, False otherweise.
Copies the interval.
my_interval_1 = Interval(2, 5)
my_interval_2 = my_interval_1.copy()
A copy of the interval.
Returns the difference between two given intervals.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
diff = Interval.difference(my_interval_1, my_interval_2)
- interval_1 a numeric interval
- interval_2 a numeric interval
Difference between two given intervals.
Returns the intersection of two given intervals.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
intersection = Interval.intersection(my_interval_1, my_interval_2)
- interval_1 a numeric interval
- interval_2 a numeric interval
Intersection of two given intervals.
Returns the union of two given intervals.
my_interval_1 = Interval(2, 5)
my_interval_2 = Interval(4, 8)
union = Interval.union(my_interval_1, my_interval_2)
- interval_1 a numeric interval
- interval_2 a numeric interval
Union of two given intervals.
Constructs a list of intervals to the left from the interval.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
left = myset.get_left_intervals((6, 8))
- interval a numeric interval
A list of intervals to the left from the interval.
Constructs a list of intervals to the right from the interval.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
right = myset.get_right_intervals((6, 8))
- interval a numeric interval
A list of intervals to the right from the interval.
Adds a numeric interval to the set.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
- interval a numeric interval
Clears the set from all numeric intervals.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
myset.clear()
Copies the numeric set.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
copy = myset.copy()
A copy of the numric set.
Constructs a set representing the difference between the set and the given set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
diff = myset_1.difference(myset_2)
- numeric_set a numeric set
The difference between the set and the given set.
Constructs a set representing the difference between the set and the given set and updates the set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
myset_1.difference_update(myset_2)
- numeric_set a numeric set
Constructs a set representing the intersection of the set and the given set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
intersection = myset_1.intersection(myset_2)
- numeric_set a numeric set
The intersection of the set and the given set.
Constructs a set representing the intersection of the set and the given set and updates the set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
myset_1.intersection_update(myset_2)
- numeric_set a numeric set
Determines whether the set is a subset of the given set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4)])
is_subset = myset_2.is_subset(myset_1)
- numeric_set a numeric set
True if the interval is a subset of the given interval, False otherweise.
Determines whether the set is a superset of the given set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4)])
is_superset = myset_1.is_superset(myset_2)
- numeric_set a numeric set
True if the interval is a superset of the given interval, False otherweise.
Removes the rightmost interval if such exists.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
last_interval = myset.pop()
The rightmost interval if such exists, None otherwise.
Removes a numeric interval from the numeric set.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
myset.remove(Interval(2, 4))
- interval a numeric interval
Constructs a set representing the symmetric difference of two sets.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
symmetric_diff = myset_1.symmetric_difference(myset_2)
- numeric_set a numeric set
The symmetric difference of the set and the given set.
Constructs a set representing the symmetric difference of the set and the given set and updates the set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
myset_1.symmetric_difference_update(myset_2)
- numeric_set a numeric set
Constructs a set representing the union of two sets.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
union = myset_1.union(myset_2)
- numeric_set a numeric set
The union of the set and the given set.
Constructs a set representing the union of the set and the given set and updates the set.
myset_1 = NumericSet([Interval(3, 5), Interval(10, 12)])
myset_2 = NumericSet([Interval(2, 4), Interval(11, 15)])
myset_1.update(myset_2)
- numeric_set a numeric set
Determines whether a set of intervals is empty.
myset = NumericSet([Interval(3, 5))])
is_empty = myset_1.is_empty()
True if the set is empty, False otherweise.
Saves a set of numeric intervals in the given file.
myset = NumericSet([Interval(3, 5))])
myset_1.save('myset_1.txt')
- filename the name of the file
Reads a set of numerical intervals from the given file.
myset = NumericSet.read('myset_1.txt')
- filename the name of the file
Dmytro Yaroshevych – dyaroshevych@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/dyaroshevych/numeric_sets
- Fork it (https://github.com/dyaroshevych/numeric_sets/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request