File: index.rst

package info (click to toggle)
python-procset 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 532 kB
  • sloc: python: 2,607; makefile: 22
file content (86 lines) | stat: -rw-r--r-- 2,372 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Overview
========

.. toctree::
   :hidden:
   :titlesonly:

   Overview <self>
   ProcSet API <api>
   tips


.. currentmodule:: procset


This package implements for Python a memory-efficient representation of
closed-interval sets.


The package provides the :mod:`procset` module.


A :class:`ProcSet` is an hybrid between a :class:`set` and a :class:`list` of
indexes.
More precisely, a :class:`ProcSet` object is an ordered collection of
unique non-negative :class:`int`.
It supports most of :class:`set` operations: notably membership testing,
mathematical operations such as intersection, union, and (symmetric)
difference; with the additional ability to access its elements by position.

The :class:`ProcSet` type is mutable, as its content can be modified using
methods such as :meth:`~ProcSet.insert()`.
Since it is mutable, it has no hash value and cannot be used as either a
dictionary key or as an element of another set.


Example use
-----------

You can get the library directly from PyPI:

.. code:: bash

   pip install procset


What does it look like to use ``procset``?  Here is a simple example program:

.. code:: python

   from procset import ProcSet


   free_cores = ProcSet((0, 7))  # I have 8 cores to work with

   job_cores = ProcSet((2, 5))  # let's use some cores for a job
   free_cores -= job_cores

   print('remaining cores:', str(free_cores))


And it looks like this when run:

.. code:: bash

   $ python example.py
   remaining cores: 0-1 6-7


.. _string-representation:

String representation of interval sets
--------------------------------------

In the scheduling community, interval sets often are encoded as strings where
the string ``'a-b'`` (middle symbol is a dash, ascii ``0x2d``) represents the
integer interval :math:`[a, b]`, with the convention that the string ``a``
represents the degenerate case of the singleton :math:`\{a\}`.
An interval set with many disjoint intervals is encoded by joining interval
representations with a space (ascii ``0x20``): for example ``a-b c d-e``
represents :math:`[a, b] \cup \{c\} \cup [d, e]`.

.. warning::
   There are many different strings representing the same interval set.
   For the description of a canonical representation, please refer to the
   `documentation of Batsim <https://batsim.readthedocs.io/en/latest/interval-set.html#canonical-string-representation>`_.