A package for performing operations on numeric sets
Project description
numeric_sets
Allows you to perform all operations on sets of numeric intervals.
Usage example
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]
Methods description
Interval class
get_formatted
Returns formatted interval as a string.
my_interval = Interval(2, 5, is_start_inclusive=True)
my_interval.get_formatted()
Return
Interval as a formatted string.
is_overlapping
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)
Arguments
- interval a numeric interval
Return
True if intervals overlap, False otherweise.
is_almost_overlapping
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.
Arguments
- interval a numeric interval
Return
True if intervals almost overlap, False otherweise.
includes
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)
Arguments
- point a numeric point
Return
True if the interval includes the given point, False otherweise.
copy
Copies the interval.
my_interval_1 = Interval(2, 5)
my_interval_2 = my_interval_1.copy()
Return
A copy of the interval.
difference [static]
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)
Arguments
- interval_1 a numeric interval
- interval_2 a numeric interval
Return
Difference between two given intervals.
intersection [static]
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)
Arguments
- interval_1 a numeric interval
- interval_2 a numeric interval
Return
Intersection of two given intervals.
union [static]
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)
Arguments
- interval_1 a numeric interval
- interval_2 a numeric interval
Return
Union of two given intervals.
NumericSet methods
get_left_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))
Arguments
- interval a numeric interval
Return
A list of intervals to the left from the interval.
get_right_intervals
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))
Arguments
- interval a numeric interval
Return
A list of intervals to the right from the interval.
add
Adds a numeric interval to the set.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
Arguments
- interval a numeric interval
clear
Clears the set from all numeric intervals.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
myset.clear()
copy
Copies the numeric set.
myset = NumericSet()
myset.add(Interval(3, 5))
myset.add(Interval(10, 12))
copy = myset.copy()
Return
A copy of the numric set.
difference
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)
Arguments
- numeric_set a numeric set
Return
The difference between the set and the given set.
difference_update
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)
Arguments
- numeric_set a numeric set
intersection
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)
Arguments
- numeric_set a numeric set
Return
The intersection of the set and the given set.
intersection_update
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)
Arguments
- numeric_set a numeric set
issubset
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)
Arguments
- numeric_set a numeric set
Return
True if the interval is a subset of the given interval, False otherweise.
issuperset
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)
Arguments
- numeric_set a numeric set
Return
True if the interval is a superset of the given interval, False otherweise.
pop
Removes the rightmost interval if such exists.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
last_interval = myset.pop()
Return
The rightmost interval if such exists, None otherwise.
remove
Removes a numeric interval from the numeric set.
myset = NumericSet([Interval(3, 5), Interval(10, 12)])
myset.remove(Interval(2, 4))
Arguments
- interval a numeric interval
symmetric_difference
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)
Arguments
- numeric_set a numeric set
Return
The symmetric difference of the set and the given set.
symmetric_difference_update
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)
Arguments
- numeric_set a numeric set
union
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)
Arguments
- numeric_set a numeric set
Return
The union of the set and the given set.
update
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)
Arguments
- numeric_set a numeric set
is_empty
Determines whether a set of intervals is empty.
myset = NumericSet([Interval(3, 5))])
is_empty = myset_1.is_empty()
Return
True if the set is empty, False otherweise.
save
Saves a set of numeric intervals in the given file.
myset = NumericSet([Interval(3, 5))])
myset_1.save('myset_1.txt')
Arguments
- filename the name of the file
read [static]
Reads a set of numerical intervals from the given file.
myset = NumericSet.read('myset_1.txt')
Arguments
- filename the name of the file
Meta
Dmytro Yaroshevych – dyaroshevych@gmail.com
Distributed under the MIT license. See LICENSE for more information.
https://github.com/dyaroshevych/numeric_sets
Contributing
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numeric_sets_dyaroshevych-0.0.3.tar.gz.
File metadata
- Download URL: numeric_sets_dyaroshevych-0.0.3.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b4a587d6002544d868fb9ada106d2cb0d0107df6c03cf7654a7d84ac04728e
|
|
| MD5 |
e8ab6c3acbc77a09aa36b99258139bb7
|
|
| BLAKE2b-256 |
ed5549a6622d2e774385377d0f00b7c38c345b5cc71ca32e0861ca03ba0cb9dd
|
File details
Details for the file numeric_sets_dyaroshevych-0.0.3-py3-none-any.whl.
File metadata
- Download URL: numeric_sets_dyaroshevych-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77f956ed809446042b4bd3e3d6772853177b8ae8b898d6166f46c3b5d4faaf48
|
|
| MD5 |
f75ee4c13d6b48628b853ca4ea0b9d2e
|
|
| BLAKE2b-256 |
83eece9770fe1f79dcdff7271bc17d4405150ddebd5bd7826bce4683a4ea3a03
|