Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.idna.intranges Namespace Reference

Functions

Tuple[int,...] intranges_from_list (List[int] list_)
 
int _encode_range (int start, int end)
 
Tuple[int, int] _decode_range (int r)
 
bool intranges_contain (int int_, Tuple[int,...] ranges)
 

Detailed Description

Given a list of integers, made up of (hopefully) a small number of long runs
of consecutive integers, compute a representation of the form
((start1, end1), (start2, end2) ...). Then answer the question "was x present
in the original list?" in time O(log(# runs)).

Function Documentation

◆ _decode_range()

Tuple[int, int] _decode_range ( int  r)
protected

Definition at line 35 of file intranges.py.

35def _decode_range(r: int) -> Tuple[int, int]:
36 return (r >> 32), (r & ((1 << 32) - 1))
37
38

Referenced by pip._vendor.idna.intranges.intranges_contain().

Here is the caller graph for this function:

◆ _encode_range()

int _encode_range ( int  start,
int  end 
)
protected

Definition at line 32 of file intranges.py.

32def _encode_range(start: int, end: int) -> int:
33 return (start << 32) | end
34

Referenced by pip._vendor.idna.intranges.intranges_contain(), and pip._vendor.idna.intranges.intranges_from_list().

Here is the caller graph for this function:

◆ intranges_contain()

bool intranges_contain ( int  int_,
Tuple[int, ...]  ranges 
)
Determine if `int_` falls into one of the ranges in `ranges`.

Definition at line 39 of file intranges.py.

39def intranges_contain(int_: int, ranges: Tuple[int, ...]) -> bool:
40 """Determine if `int_` falls into one of the ranges in `ranges`."""
41 tuple_ = _encode_range(int_, 0)
42 pos = bisect.bisect_left(ranges, tuple_)
43 # we could be immediately ahead of a tuple (start, end)
44 # with start < int_ <= end
45 if pos > 0:
46 left, right = _decode_range(ranges[pos-1])
47 if left <= int_ < right:
48 return True
49 # or we could be immediately behind a tuple (int_, end)
50 if pos < len(ranges):
51 left, _ = _decode_range(ranges[pos])
52 if left == int_:
53 return True
54 return False
for i

References pip._vendor.idna.intranges._decode_range(), pip._vendor.idna.intranges._encode_range(), and i.

Here is the call graph for this function:

◆ intranges_from_list()

Tuple[int, ...] intranges_from_list ( List[int]  list_)
Represent a list of integers as a sequence of ranges:
((start_0, end_0), (start_1, end_1), ...), such that the original
integers are exactly those x such that start_i <= x < end_i for some i.

Ranges are encoded as single integers (start << 32 | end), not as tuples.

Definition at line 11 of file intranges.py.

11def intranges_from_list(list_: List[int]) -> Tuple[int, ...]:
12 """Represent a list of integers as a sequence of ranges:
13 ((start_0, end_0), (start_1, end_1), ...), such that the original
14 integers are exactly those x such that start_i <= x < end_i for some i.
15
16 Ranges are encoded as single integers (start << 32 | end), not as tuples.
17 """
18
19 sorted_list = sorted(list_)
20 ranges = []
21 last_write = -1
22 for i in range(len(sorted_list)):
23 if i+1 < len(sorted_list):
24 if sorted_list[i] == sorted_list[i+1]-1:
25 continue
26 current_range = sorted_list[last_write+1:i+1]
27 ranges.append(_encode_range(current_range[0], current_range[-1] + 1))
28 last_write = i
29
30 return tuple(ranges)
31

References pip._vendor.idna.intranges._encode_range(), and i.

Here is the call graph for this function: