
    "/a'              	       H    d Z ddlmZ ddlmZ  G d d edg d            Zy)	a  
intervaltree: A mutable, self-balancing interval tree for Python 2 and 3.
Queries may be by point, by range overlap, or by range envelopment.

Interval class

Copyright 2013-2018 Chaim Leib Halbert
Modifications copyright 2014 Konstantin Tretyakov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    )Number)
namedtuplec                        e Zd ZdZd fd	ZddZddZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeZd Zd Z xZS )Interval c                 0    t         t        |   | |||      S N)superr   __new__)clsbeginenddata	__class__s       5lib/python3.12/site-packages/intervaltree/interval.pyr   zInterval.__new__!   s    Xs+CTBB    c                     | || j                   k  xr || j                  kD  S 	 | j                  |j                  |j                         S #  | j                  |      cY S xY w)a$  
        Whether the interval overlaps the given point, range or Interval.
        :param begin: beginning point of the range, or the point, or an Interval
        :param end: end point of the range. Optional if not testing ranges.
        :return: True or False
        :rtype: bool
        )r   r   overlapscontains_point)selfr   r   s      r   r   zInterval.overlaps$   s^     ? 488#8djj(88	.==eii88	.&&u--s   %A
 
Ac                    | j                  ||      }|sy|1t        | j                  |      }t        | j                  |      }||z
  S t        | j                  |j                        }t        | j                  |j                        }||z
  S )a  
        Return the overlap size between two intervals or a point
        :param begin: beginning point of the range, or the point, or an Interval
        :param end: end point of the range. Optional if not testing ranges.
        :return: Return the overlap size, None if not overlap is found
        :rtype: depends on the given input (e.g., int will be returned for int interval and timedelta for
        datetime intervals)
        r   )r   maxr   minr   )r   r   r   r   i0i1s         r   overlap_sizezInterval.overlap_size8   sy     ==,?TZZ'BTXXs#B7NU[[)599%Bwr   c                 J    | j                   |cxk  xr | j                  k  S c S )z
        Whether the Interval contains p.
        :param p: a point
        :return: True or False
        :rtype: bool
        r   r   )r   ps     r   r   zInterval.contains_pointO   s"     zzQ)))))r   c                 j    | j                   |j                   k(  xr | j                  |j                  k(  S )z
        Whether the begins equal and the ends equal. Compare __eq__().
        :param other: Interval
        :return: True or False
        :rtype: bool
        r   r   others     r   range_matcheszInterval.range_matchesX   .     JJ%++% "HH		!	
r   c                 j    | j                   |j                   k  xr | j                  |j                  k\  S )z
        Whether other is contained in this Interval.
        :param other: Interval
        :return: True or False
        :rtype: bool
        r   r!   s     r   contains_intervalzInterval.contains_intervald   r$   r   c                 *   | j                  |      ry	 | j                  |j                  k  r|j                  | j                  z
  S | j                  |j                  z
  S #  | j                  |k  r|| j                  z
  cY S | j                  |z
  cY S xY w)z
        Returns the size of the gap between intervals, or 0 
        if they touch or overlap.
        :param other: Interval or point
        :return: distance
        :rtype: Number
        r   )r   r   r   r!   s     r   distance_tozInterval.distance_top   s     ==		*zzEKK'{{TXX--zzEII--	*xx5 txx''zzE))s   1A A  BBc                 4    | j                   | j                  k\  S )z~
        Whether this equals the null interval.
        :return: True if end <= begin else False
        :rtype: bool
        r   r   s    r   is_nullzInterval.is_null   s     zzTXX%%r   c                 V    | j                         ry| j                  | j                  z
  S )zf
        The distance covered by this Interval.
        :return: length
        :type: Number
        r   )r+   r   r   r*   s    r   lengthzInterval.length   s#     <<>xx$**$$r   c                 D    t        | j                  | j                  f      S )z]
        Depends on begin and end only.
        :return: hash
        :rtype: Number
        )hashr   r   r*   s    r   __hash__zInterval.__hash__   s     TZZ*++r   c                     | j                   |j                   k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )z
        Whether the begins equal, the ends equal, and the data fields
        equal. Compare range_matches().
        :param other: Interval
        :return: True or False
        :rtype: bool
        r   r   r   r!   s     r   __eq__zInterval.__eq__   sC     JJ%++% $HH		!$II#	
r   c                 v   | dd }	 |dd }||k7  r	||k  rdS dS 	 | j                   |j                   k(  ry| j                   |j                   k  rdS dS #  |f}Y MxY w# t        $ rS t        | j                         j                  }t        |j                         j                  }||k(  rY y||k  rdcY S dcY S w xY w)a^  
        Tells whether other sorts before, after or equal to this
        Interval.

        Sorting is by begins, then by ends, then by data fields.

        If data fields are not both sortable types, data fields are
        compared alphabetically by type name.
        :param other: Interval
        :return: -1, 0, 1
        :rtype: int
        r         )r   	TypeErrortype__name__)r   r"   sos       r   __cmp__zInterval.__cmp__   s     1I	a
A 6Q2%A%		&yyEJJ&UZZ/26Q6	A  	&TYY((AUZZ ))AAvQ2%A%	&s4   A A A A AAB8*B83B87B8c                 *    | j                  |      dk  S )z
        Less than operator. Parrots __cmp__()
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   r=   r!   s     r   __lt__zInterval.__lt__        ||E"Q&&r   c                 *    | j                  |      dkD  S )z
        Greater than operator. Parrots __cmp__()
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   r?   r!   s     r   __gt__zInterval.__gt__   rA   r   c                     | j                         rt        d      t        |d      r|j                         rt        d      yy)zP
        :raises ValueError: if either self or other is a null Interval
        zCannot compare null Intervals!r+   N)r+   
ValueErrorhasattrr!   s     r   _raise_if_nullzInterval._raise_if_null   s?     <<>=>>5)$=>> *9$r   c                 X    | j                  |       | j                  t        |d|      k  S )a  
        Strictly less than. Returns True if no part of this Interval
        extends higher than or into other.
        :raises ValueError: if either self or other is a null Interval
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   rG   r   getattrr!   s     r   ltzInterval.lt   s*     	E"xx75'5999r   c                 X    | j                  |       | j                  t        |d|      k  S )a  
        Less than or overlaps. Returns True if no part of this Interval
        extends higher than other.
        :raises ValueError: if either self or other is a null Interval
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   rI   r!   s     r   lezInterval.le   s*     	E"xx75%777r   c                     | j                  |       t        |d      r| j                  |j                  k\  S | j                  |kD  S )a  
        Strictly greater than. Returns True if no part of this Interval
        extends lower than or into other.
        :raises ValueError: if either self or other is a null Interval
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   )rG   rF   r   r   r!   s     r   gtzInterval.gt   s>     	E"5% ::**::%%r   c                 X    | j                  |       | j                  t        |d|      k\  S )a  
        Greater than or overlaps. Returns True if no part of this Interval
        extends lower than other.
        :raises ValueError: if either self or other is a null Interval
        :param other: Interval or point
        :return: True or False
        :rtype: bool
        r   )rG   r   rJ   r!   s     r   gezInterval.ge  s*     	E"zzWUGU;;;r   c                     | j                   #| j                  | j                  | j                   fS | j                  | j                  fS )z
        Used by str, unicode, repr and __reduce__.

        Returns only the fields necessary to reconstruct the Interval.
        :return: reconstruction info
        :rtype: tuple
        )r   r   r   r*   s    r   _get_fieldszInterval._get_fields  s:     99 ::txx22::txx''r   c                 h   t        | j                  t              r+t        | j                        }t        | j                        }n*t        | j                        }t        | j                        }| j                  dj                  ||      S dj                  ||t        | j                              S )z
        Executable string representation of this Interval.
        :return: string representation
        :rtype: str
        zInterval({0}, {1})zInterval({0}, {1}, {2}))
isinstancer   r   strr   reprr   format)r   s_begins_ends      r   __repr__zInterval.__repr__'  s     djj&)$**oGME4::&GNE99'..w>>,33GUDOTTr   c                 X    t        | j                  | j                  | j                        S )zV
        Shallow copy.
        :return: copy of self
        :rtype: Interval
        )r   r   r   r   r*   s    r   copyzInterval.copy:  s     

DHHdii88r   c                 .    t         | j                         fS )zT
        For pickle-ing.
        :return: pickle data
        :rtype: tuple
        )r   rS   r*   s    r   
__reduce__zInterval.__reduce__B  s     ))+++r   r	   )r:   
__module____qualname__	__slots__r   r   r   r   r#   r&   r(   r+   r-   r0   r3   r=   r@   rC   rG   rK   rM   rO   rQ   rS   r[   __str__r]   r_   __classcell__)r   s   @r   r   r      s    IC.(.*



**&%,
&>''?
:
8&
<(U" G9,r   r   IntervalBaser2   N)__doc__numbersr   collectionsr   r   r   r   r   <module>ri      s(   *  "j,z.*BC j,r   