aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/utils/sorted_set.py
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2019-09-11 12:58:45 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-09-14 18:18:53 -0400
commitabb42dcd4886705d6ba8af27f68ef605218ac67c (patch)
tree9ae16f7a09fff539fa72e65198e284bca6ac3376 /diplomacy/utils/sorted_set.py
parenta954a00d263750c279dbb2c0a9ae85707022bcd7 (diff)
Added ReadtheDocs documentation for the public API
- Reformatted the docstring to be compatible - Added tests to make sure the documentation compiles properly - Added sphinx as a pip requirement Co-authored-by: Philip Paquette <pcpaquette@gmail.com> Co-authored-by: notoraptor <stevenbocco@gmail.com>
Diffstat (limited to 'diplomacy/utils/sorted_set.py')
-rw-r--r--diplomacy/utils/sorted_set.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/diplomacy/utils/sorted_set.py b/diplomacy/utils/sorted_set.py
index 01cfb34..0bd327c 100644
--- a/diplomacy/utils/sorted_set.py
+++ b/diplomacy/utils/sorted_set.py
@@ -21,15 +21,16 @@ from copy import copy
from diplomacy.utils import exceptions
from diplomacy.utils.common import is_sequence
-class SortedSet():
+class SortedSet:
""" Sorted set (sorted values, each value appears once). """
__slots__ = ('__type', '__list')
def __init__(self, element_type, content=()):
""" Initialize a typed sorted set.
+
:param element_type: Expected type for values.
:param content: (optional) Sequence of values to initialize sorted set with.
- """
+ """
if not is_sequence(content):
raise exceptions.TypeException('sequence', type(content))
self.__type = element_type
@@ -40,12 +41,15 @@ class SortedSet():
@staticmethod
def builder(element_type):
""" Return a function to build sorted sets from content (sequence of values).
- :param element_type: expected type for sorted set values.
- :return: callable
-
Returned function expects a content parameter like SortedSet initializer.
+
+ .. code-block:: python
+
builder_fn = SortedSet.builder(str)
my_sorted_set = builder_fn(['c', '3', 'p', '0'])
+
+ :param element_type: expected type for sorted set values.
+ :return: callable
"""
return lambda iterable: SortedSet(element_type, iterable)
@@ -104,9 +108,9 @@ class SortedSet():
return best_position
def get_next_value(self, element):
- """ Get lowest value in sorted set greater than given element, or None if such values does not exists
- in the sorted set. Given element may not exists in the sorted set.
- """
+ """ Get lowest value in sorted set greater than given element, or None if such values
+ does not exists in the sorted set. Given element may not exists in the sorted set.
+ """
assert isinstance(element, self.__type)
if self.__list:
best_position = bisect.bisect_right(self.__list, element)
@@ -118,8 +122,8 @@ class SortedSet():
return None
def get_previous_value(self, element):
- """ Get greatest value in sorted set less the given element, or None if such value does not exists
- in the sorted set. Given element may not exists in the sorted set.
+ """ Get greatest value in sorted set less the given element, or None if such value
+ does not exists in the sorted set. Given element may not exists in the sorted set.
"""
assert isinstance(element, self.__type)
if self.__list: