MOAL.data_structures.abstract package¶
Submodules¶
MOAL.data_structures.abstract.array_and_linked_lists module¶
-
class
MOAL.data_structures.abstract.array_and_linked_lists.
AssociationList
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.array_and_linked_lists.DoubleNode
Our linked list already encapsulates all the behavior necessary. The required key and value properties are named title and cargo respectively. The association (lookup) can be evaluated by traversing the linked list and comparing the key, then returning the matching nodes value.
This behavior is already done with the setter, so we don’t need to re-define it here.
-
class
MOAL.data_structures.abstract.array_and_linked_lists.
DoubleNode
(title, cargo=None, prev=None, next=None)[source]¶ Bases:
MOAL.data_structures.abstract.array_and_linked_lists.SingleNode
A node represents a connection in the linked list. This extends the single node (linked list) to become a doubly-linked list - a list with connections going in both directions (forward and backwards).
-
class
MOAL.data_structures.abstract.array_and_linked_lists.
SingleNode
(title, cargo=None, next=None)[source]¶ Bases:
object
-
__contains__
(key)¶
-
__getitem__
(key)¶ Get an existing node
-
__init__
(title, cargo=None, next=None)¶
-
__iter__
()¶ Iterate over linked nodes
-
__len__
()¶
-
__repr__
()¶
-
__setitem__
(key, value)¶ Update the values of an existing node
-
__str__
()¶
-
last
()¶ Move forward in the list until the last node is found e.g. [N] –> [N + 1] –> [N + 2]
-
MOAL.data_structures.abstract.container module¶
-
class
MOAL.data_structures.abstract.container.
ContainerADT
[source]¶ Bases:
object
From wikipedia.org/wiki/Container_%28abstract_data_type%29: ” Container classes are expected to implement methods to do the following:
- create a new empty container,
- report the number of objects it stores (size),
- delete all the objects in the container (clear),
- insert new objects into the container,
- remove objects from it,
- provide access to the stored objects.
- containers are sometimes implemented in conjunction with iterators.
“
-
class
MOAL.data_structures.abstract.container.
ReferenceContainer
[source]¶ Bases:
MOAL.data_structures.abstract.container.ContainerADT
[Wikipedia] ” Store pointers or references to the object. If we access an object, the object returns a reference to it. If an external object is changed after it has been inserted in the container, it affects the content of the container. “
-
class
MOAL.data_structures.abstract.container.
ValueContainer
[source]¶ Bases:
MOAL.data_structures.abstract.container.ContainerADT
[Wikipedia] “Store copies of objects. If we access an object, the object returns a copy of it. If an external object is changed after it has been inserted in the container it will not affect the content of the container.”
-
class
MOAL.data_structures.abstract.container.
WindowWidget
(name)[source]¶ Bases:
MOAL.data_structures.abstract.container.ReferenceContainer
See wikipedia.org/wiki/Container_%28abstract_data_type%29 ... “Graphic containers” as inspiration.
MOAL.data_structures.abstract.list module¶
-
class
MOAL.data_structures.abstract.list.
ListADT
[source]¶ Bases:
object
From wikipedia.org/wiki/List_%28abstract_data_type%29#Operations ” Implementation of the list data structure may provide some of the following operations:
a constructor for creating an empty list;
an operation for testing whether or not a list is empty;
an operation for prepending an entity to a list
an operation for appending an entity to a list
- an operation for determining the first component
(or the “head”) of a list
- an operation for referring to the list consisting of all the
components of a list except for its first (this is called the “tail” of the list.)
“
MOAL.data_structures.abstract.map module¶
-
class
MOAL.data_structures.abstract.map.
BidirectionalMap
(*args, **kwargs)[source]¶ Bases:
dict
The bi-directional map uses a dictionary rather than an associative or linked list, since the main purposes is to stress the concept of bi-directional mapping, not the actual implementation. Besides, a dict would be a better implementation for real-world usage, at least in python.
-
class
MOAL.data_structures.abstract.map.
Enrollment
(students=[], classes=[], title='Enrollment-MultiMap')[source]¶ Bases:
MOAL.data_structures.abstract.map.MultiMap
-
__init__
(students=[], classes=[], title='Enrollment-MultiMap')¶
-
__setitem__
(student, klass)¶
-
_classes
()¶
-
enroll
(student, klass)¶
-
enroll_all
(schedules)¶
-
get_classes
(student)¶
-
schedules
()¶
-
-
class
MOAL.data_structures.abstract.map.
MapADT
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.array_and_linked_lists.AssociationList
From wikipedia.org/wiki/Associative_array:
- “Operations associated with this data type allow:
- The addition of pairs to the collection
- The removal of pairs from the collection
- The modification of the values of existing pairs
- The lookup of the value associated with a particular key”
While we could just use a dictionary (cheating), it would make sense to use a vanilla array and implement a custom & importantly, internal, function that does key lookups.
However, an associative array / map is purely abstract, and other data types use it as a template, either concretely or conceptually. A linked list is given as an example implementation, so we can use it here, providing some basic methods that act as a facade pattern over the internal implementation.
-
class
MOAL.data_structures.abstract.map.
MultiMap
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.map.MapADT
From wikipedia.org/wiki/Multimap (paraphrased): “In computer science, a multimap (sometimes also multihash) is a generalization of a map or associative array abstract data type in which more than one value may be associated with and returned for a given key.
Often the multimap is implemented as a map with lists/sets as the values.”
“Both map and multimap are particular cases of containers” (See abstract/container for an example of this ADT.)
Since our MapADT uses a linked list, and the linked list implementation does not prohibit certain types as values, we can simply use a list as mentioned above for the value.
We could enforce certain types on the original linked list, but that is arbitrary and unnecessary.
MOAL.data_structures.abstract.priority_queue module¶
-
class
MOAL.data_structures.abstract.priority_queue.
PriorityQueue
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.queues.Queue
-
__init__
(*args, **kwargs)¶
-
__str__
()¶
-
enqueue
(item, priority=0)¶
-
get_priority
(level)¶ Naive implementation - does not consider duplicate priority levels
-
pull_highest_priority_element
()¶
-
MOAL.data_structures.abstract.queues module¶
-
class
MOAL.data_structures.abstract.queues.
Dequeue
(direction)[source]¶ Bases:
MOAL.data_structures.abstract.queues.Queue
Represents a ‘double ended’ queue – a queue that can use either direction as the head/tail, but works the same way.
-
__init__
(direction)¶
-
dequeue
()¶
-
enqueue
(item)¶
-
-
class
MOAL.data_structures.abstract.queues.
HotPotatoSimulator
(names, num)[source]¶ Bases:
MOAL.data_structures.abstract.queues.Queue
-
__init__
(names, num)¶
-
adjust_position
()¶
-
move
()¶
-
-
class
MOAL.data_structures.abstract.queues.
PrinterQueue
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.queues.Queue
-
add_job
(name, doc)¶
-
print_job
()¶
-
MOAL.data_structures.abstract.queues_stdlib module¶
-
class
MOAL.data_structures.abstract.queues_stdlib.
CountThread
(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]¶ Bases:
threading.Thread
-
run
()¶
-
start
(name)¶
-
MOAL.data_structures.abstract.set module¶
-
class
MOAL.data_structures.abstract.set.
DynamicSet
(items=[])[source]¶ Bases:
MOAL.data_structures.abstract.set.SetADT
-
add
(value)¶
-
capacity
()¶
-
static
create
(args, capacity=100)¶
-
remove
(value)¶
-
room_left
()¶
-
set_capacity
(capacity)¶
-
-
class
MOAL.data_structures.abstract.set.
FrozenSetADT
(items)[source]¶ Bases:
MOAL.data_structures.abstract.set.SetADT
-
__init__
(items)¶
-
__setitem__
(*args)¶
-
-
class
MOAL.data_structures.abstract.set.
MultiSet
(items=[])[source]¶ Bases:
MOAL.data_structures.abstract.set.DynamicSet
-
__setitem__
(group, values)¶ Sets a single item in a multi-set group. Each group can be queried by individual values, but multiple values can be stored. e.g. mymset[‘foo’] = {‘bar’: 2, ‘bim’: True} ... myset.count(‘bar’) == 1
-
count
(prop, key=None)¶ Check the count of any given value or key (either scenario works seamlessly for ease-of-use) and user simplicity.
-
count_multi
(props, key=None)¶ Count multiple properties.
-
-
class
MOAL.data_structures.abstract.set.
SetADT
(items=[])[source]¶ Bases:
object
From wikipedia.org/wiki/Set_%28abstract_data_type%29
“The data may be booleans, numbers, characters, or other data structures. If one considers the structure yielded by packaging or indexing, there are four basic data structures:
- unpackaged, unindexed: bunch
- packaged, unindexed: set
- unpackaged, indexed: string (sequence)
- packaged, indexed: list (array)
In this view, the contents of a set are a bunch, and isolated data items are elementary bunches (elements). Whereas sets contain elements, bunches consist of elements.
MOAL.data_structures.abstract.stack module¶
-
class
MOAL.data_structures.abstract.stack.
Logger
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.stack.Stack
-
__init__
(*args, **kwargs)¶
-
add_message
(message, priority=0)¶
-
get_by_priority
(priority)¶
-
get_first_message
()¶
-
get_last_message
()¶
-
view_messages
()¶
-
-
class
MOAL.data_structures.abstract.stack.
NetworkLogger
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.stack.Logger
-
add_message
(message, priority=0)¶
-
-
class
MOAL.data_structures.abstract.stack.
Stack
[source]¶ Bases:
object
-
__init__
()¶
-
head
()¶
-
is_empty
()¶
-
peek
()¶
-
pop
()¶
-
push
(item)¶
-
size
()¶
-
tail
()¶
-
view
()¶
-
-
class
MOAL.data_structures.abstract.stack.
WebLogger
(*args, **kwargs)[source]¶ Bases:
MOAL.data_structures.abstract.stack.Logger
-
add_message
(message, priority=0)¶
-
MOAL.data_structures.abstract.stack_frame module¶
-
class
MOAL.data_structures.abstract.stack_frame.
StackFrame
(func, **kwargs)[source]¶ -
__init__
(func, **kwargs)¶
-