Skip to content

Commit

Permalink
write some doc for query.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Python-in-China committed Dec 17, 2024
1 parent d89d6e7 commit c468945
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions cyaron/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def __str__(self):
return self.to_str()

def to_str(self):
"""
Return a string to output the queries.
The string contains all the queries with l and r in a row, splits with "\\n".
"""
res = ''
for l, r, in self.result:
l_to_str = [str(x) for x in l]
Expand All @@ -57,14 +61,14 @@ def random(
position_range: Optional[List[Union[int, Tuple[int, int]]]] = None,
mode: RangeQueryRandomMode = RangeQueryRandomMode.allow_equal,
):
"""random(num, position_range, mode) -> RangeQuery
Generate `num` random queries with dimension limit.
Args:
num: the number of queries
position_range: a list of limits for each dimension
single number x represents range [1, x]
list [x, y] or tuple (x, y) represents range [x, y]
mode: the mode queries generate, see Enum Class RangeQueryRandomMode
"""
Generate `num` random queries with dimension limit.
Args:
num: the number of queries
position_range: a list of limits for each dimension
single number x represents range [1, x]
list [x, y] or tuple (x, y) represents range [x, y]
mode: the mode queries generate, see Enum Class RangeQueryRandomMode
"""
if position_range is None:
position_range = [10]
Expand All @@ -83,6 +87,23 @@ def get_one_query(
position_range: Optional[List[Union[int, Tuple[int, int]]]] = None,
mode: RangeQueryRandomMode = RangeQueryRandomMode.allow_equal,
) -> Tuple[List[int], List[int]]:
"""
Generate a pair of query lists (query_l, query_r) based on the given position ranges and mode.
Args:
position_range (Optional[List[Union[int, Tuple[int, int]]]]): A list of position ranges. Each element can be:
- An integer, which will be treated as a range from 1 to that integer.
- A tuple of two integers, representing the lower and upper bounds of the range.
mode (RangeQueryRandomMode): The mode for generating the queries. It can be:
- RangeQueryRandomMode.allow_equal: Allow the generated l and r to be equal.
- RangeQueryRandomMode.less: Ensure that l and r are not equal.
Returns:
Tuple[List[int], List[int]]: A tuple containing two lists:
- query_l: A list of starting positions.
- query_r: A list of ending positions.
Raises:
ValueError: If the upper-bound is smaller than the lower-bound.
ValueError: If the mode is set to less but the upper-bound is equal to the lower-bound.
"""
dimension = len(position_range)
query_l: List[int] = []
query_r: List[int] = []
Expand Down

0 comments on commit c468945

Please sign in to comment.