aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/utils/priority_dict.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/priority_dict.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/priority_dict.py')
-rw-r--r--diplomacy/utils/priority_dict.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/diplomacy/utils/priority_dict.py b/diplomacy/utils/priority_dict.py
index acef8f9..66662e7 100644
--- a/diplomacy/utils/priority_dict.py
+++ b/diplomacy/utils/priority_dict.py
@@ -18,13 +18,15 @@
import heapq
# ------------------------------------------------
-# Adapted from (2018/03/14s): https://docs.python.org/3.6/library/heapq.html#priority-queue-implementation-notes
+# Adapted from (2018/03/14s):
+# https://docs.python.org/3.6/library/heapq.html#priority-queue-implementation-notes
# Unlicensed
class PriorityDict(dict):
""" Priority Dictionary Implementation """
def __init__(self, **kwargs):
""" Initialize the priority queue.
+
:param kwargs: (optional) initial values for priority queue.
"""
self.__heap = [] # Heap for entries. An entry is a triple (priority value, key, valid entry flag (boolean)).
@@ -36,6 +38,7 @@ class PriorityDict(dict):
def __setitem__(self, key, val):
""" Sets a key with his associated priority
+
:param key: The key to set in the dictionary
:param val: The priority to associate with the key
:return: None
@@ -48,7 +51,9 @@ class PriorityDict(dict):
heapq.heappush(self.__heap, entry)
def __delitem__(self, key):
- """ Removes key from dict and marks associated heap entry as invalid (False). Raises KeyError if not found. """
+ """ Removes key from dict and marks associated heap entry as invalid (False).
+ Raises KeyError if not found.
+ """
entry = self.pop(key)
entry[-1] = False
@@ -71,6 +76,7 @@ class PriorityDict(dict):
def smallest(self):
""" Finds the smallest item in the priority dict
+
:return: A tuple of (priority, key) for the item with the smallest priority, or None if dict is empty.
"""
while self.__heap and not self.__heap[0][-1]:
@@ -85,6 +91,7 @@ class PriorityDict(dict):
def copy(self):
""" Return a copy of this priority dict.
+
:rtype: PriorityDict
"""
return PriorityDict(**{key: entry[0] for key, entry in dict.items(self)})