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
A First-In-First-Out Queue
Append all elements from items to the queue
Retrieve the next element in line, this will remove it from the queue
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().
length can be set to an integer > 0. Items will only be added to the queue if they’re better or equal to the worst scoring item. If set to zero, length is unbounded. blockworse can be set to true if you want to prohibit adding worse-scoring items to the queue. Only items scoring better than the BEST one are added. blockequal can be set to false if you also want to prohibit adding equally-scoring items to the queue. (Both parameters default to False)
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)
Retrieve the next element in line, this will remove it from the queue
prune all but the first (=best) n items
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.
prune down to n items at random, disregarding their score
Return the score for item x (cheap lookup), Item 0 is always the best item
prune down to n items, chance of an item being pruned is reverse proportional to its score
Append all elements from items to the queue
Simple tree structure. Nodes are themselves trees.
Add an item to the Tree
Is this a leaf node or not?
Simple trie structure. Nodes are themselves tries, values are stored on the edges, not the nodes.
Returns the depth of the current node
Is this a leaf node or not?
Returns the path to the current node
Returns True if this is the root of the Trie
Size is number of nodes under the trie, including the current node
Depth-first search, walking through trie, returning all encounterd nodes (by default only leaves)