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.

__getitem__(key)[source]

Get an existing node, returning only the value.

__init__(*args, **kwargs)[source]
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).

__delitem__(key)[source]

Delete a node, purge any references, and update the adjacent links

__init__(title, cargo=None, prev=None, next=None)[source]
append(key, value)[source]

Add a new node to the very end of the list.

first()[source]

Move backward in the list until the first node is found e.g. [N - 2] <– [N - 1] <– [N]

prepend(key, value)[source]

Add a new node to the very beginning of the list.

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.array_and_linked_lists.build_list(length, head=None)[source]
MOAL.data_structures.abstract.array_and_linked_lists.print_nodes(node)[source]

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.

__contains__(element)[source]
__delitem__(key)[source]
__getitem__(key)[source]
__init__()[source]
__iter__()[source]
__len__()[source]
__setitem__(key, value)[source]
__str__()[source]
access(key)[source]
clear()[source]
insert(key, value)[source]
static new(*args, **kwargs)[source]
remove(key, value)[source]
size()[source]
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.

__init__(name)[source]
__str__()[source]
attach(*args, **kwargs)[source]
detach(*args, **kwargs)[source]
retrieve(*args, **kwargs)[source]
show()[source]

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.)

__init__()[source]
__iter__()[source]
__str__()[source]
append(item)[source]
static create(*args, **kwargs)[source]
empty()[source]
head()[source]
prepend(item)[source]
tail()[source]

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.

__contains__(key)[source]
__getitem__(key, value)[source]
__init__(*args, **kwargs)[source]
__setitem__(key, val)[source]

The idea here is that a key and a value are interchangeable, but either direction should still enforce the rules of a traditional map (or dictionary, in this case.)

__str__()[source]
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.

__str__()[source]
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.

__setitem__(key, value)[source]

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()
class MOAL.data_structures.abstract.queues.Queue(*args, **kwargs)[source]

Bases: MOAL.data_structures.abstract.stack.Stack

__init__(*args, **kwargs)
__len__()
dequeue()
enqueue(item)
move_to_end()
out_of_range()

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)
class MOAL.data_structures.abstract.queues_stdlib.Producer[source]
__init__()
__iter__()
add()
make()
class MOAL.data_structures.abstract.queues_stdlib.Worker(queue, num_threads=2)[source]
__init__(queue, num_threads=2)
do_work(item)
process_all()
worker()

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)
exception MOAL.data_structures.abstract.set.ImmutableSetError[source]

Bases: exceptions.Exception

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.

__contains__(value)[source]
__init__(items=[])[source]
__iter__()[source]
__len__()[source]
__setitem__(_, value)[source]
__str__()[source]
class MOAL.data_structures.abstract.set.StaticSet(items=[])[source]

Bases: MOAL.data_structures.abstract.set.SetADT

static build(*args, **kwargs)
cardinality()
static create_from(collection)
enumerate()
is_element_of(value)
is_empty(value)
size()

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)
class MOAL.data_structures.abstract.stack_frame.StackTrace[source]

Bases: MOAL.data_structures.abstract.stack.Stack

__init__()
call(func, **kwargs)
view()
MOAL.data_structures.abstract.stack_frame.init()[source]

MOAL.data_structures.abstract.stream module

class MOAL.data_structures.abstract.stream.Stream[source]

Bases: Queue.Queue

__init__()
__setitem__(item)
add(item)
not_empty()

Report if the stream still has items - this is nonsensical in some cases since a stream by definition is potentially infinite.

read()
MOAL.data_structures.abstract.stream.process_with_lock(func)[source]

MOAL.data_structures.abstract.string_adt module

class MOAL.data_structures.abstract.string_adt.StringADT(value)[source]

Bases: MOAL.data_structures.abstract.list.ListADT

“Implements the conceptual notion of a string; a list of characters.

__init__(value)[source]
__setitem__(value, _)[source]
__str__()[source]

MOAL.data_structures.abstract.tree module