Data Types
This library contains various extra data types, based to a certain extend on MIT-licensed code from Peter Norvig, AI: A Modern Appproach : http://aima.cs.berkeley.edu/python/utils.html
-
class datatypes.FIFOQueue(data=[])
A First-In-First-Out Queue
-
append(item)
-
extend(items)
- Append all elements from items to the queue
-
pop()
- Retrieve the next element in line, this will remove it from the queue
-
class datatypes.PriorityQueue(data=[], f=<function <lambda> at 0x1aa65f0>, minimize=False, blockworse=False, blockequal=False)
A queue in which the maximum (or minumum) element is returned first,
as determined by either an external score function f (by default calling
the objects score() method). If minimize=True, the item with minimum f(x) is
returned first; otherwise is the item with maximum f(x) or x.score().
blockworse can be set to true if you want to prohibit adding worse-scoring items to the queue.
blockequal can be set to false if you also want to prohibit adding equally-scoring items to the queue.
(Both parameters default to False)
-
append(item)
- Adds an item to the priority queue (in the right place), returns True if successfull, False if the item was blocked (because of a bad score)
-
pop()
- Retrieve the next element in line, this will remove it from the queue
-
prune(n)
- prune all but the first (=best) n items
-
prunebyscore(score, retainequalscore=False)
- Deletes all items below/above a certain score from the queue, depending on whether minimize is True or False. Note: It is recommended (more efficient) to use blockworse=True / blockequal=True instead! Preventing the addition of ‘worse’ items.
-
score(i)
- Return the score for item x (cheap lookup), Item 0 is always the best item
-
class datatypes.Queue
- Queue is an abstract class/interface. There are three types:
- Python List: A Last In First Out Queue (no Queue object necessary).
FIFOQueue(): A First In First Out Queue.
PriorityQueue(lt): Queue where items are sorted by lt, (default <).
- Each type supports the following methods and functions:
- q.append(item) – add an item to the queue
q.extend(items) – equivalent to: for item in items: q.append(item)
q.pop() – return the top item from the queue
len(q) – number of items in q (also q.__len()).
-
extend(items)
- Append all elements from items to the queue