jmath.abstract package¶
Submodules¶
jmath.abstract.heaps module¶
Implementation of Heap types
- class jmath.abstract.heaps.BinaryHeap¶
Bases:
object
Implementation of a Generic Binary Heap
- compare¶
Defines the comparison operator for the heap, should take a set of values and return one per an ordering. For example the comparison operator for a min heap is the min function.
- Type
Callable
- children_of(index)¶
Calculates the locations of the children of a node
- Parameters
index (int) – The index of to find the children of
- Return type
An iterable containing the indices of the child nodes
- compare = None¶
- parent_of(index)¶
Calculates the location of the parent of a node
- Parameters
index (int) – The index to calculate the parent of
- Return type
The index of the parent node or None if it does not have a parent
- pop()¶
Pops a value from the heap
- push(value)¶
Pushes a value onto the heap
- Parameters
value – The value to push on
- sift_down(index)¶
Performs a sift down operation on a given index
- Parameters
index (int) – The index to perform the sift down operation on
- sift_up(index)¶
Performs a sift up operation on a given index
- Parameters
index (int) – The index to perform the sift up operation on
- class jmath.abstract.heaps.MaxBinaryHeap¶
Bases:
jmath.abstract.heaps.BinaryHeap
Binary Heap with maximum value stored at root.
- compare()¶
max(iterable, *[, default=obj, key=func]) -> value max(arg1, arg2, *args, *[, key=func]) -> value
With a single iterable argument, return its biggest item. The default keyword-only argument specifies an object to return if the provided iterable is empty. With two or more arguments, return the largest argument.
- class jmath.abstract.heaps.MinBinaryHeap¶
Bases:
jmath.abstract.heaps.BinaryHeap
Binary Heap with minimum value stored at root.
- compare()¶
min(iterable, *[, default=obj, key=func]) -> value min(arg1, arg2, *args, *[, key=func]) -> value
With a single iterable argument, return its smallest item. The default keyword-only argument specifies an object to return if the provided iterable is empty. With two or more arguments, return the smallest argument.
jmath.abstract.lists module¶
List data types.
- class jmath.abstract.lists.BiNode(data, next=None, prev=None)¶
Bases:
jmath.abstract.lists.Node
Node that can refer to objects in front and behind it.
- Parameters
- append(node)¶
Appends a node to the back of this node.
- Parameters
node (jmath.abstract.lists.BiNode) – Node to be appended.
- prepend(node)¶
Prepends a node to the front of this node.
- Parameters
node (jmath.abstract.lists.BiNode) – Node to be prepended.
- class jmath.abstract.lists.DoubleLinkedList¶
Bases:
jmath.abstract.lists.LinkedList
Double Linked List implementation.
- NODE¶
alias of
jmath.abstract.lists.BiNode
- class jmath.abstract.lists.LinkedList¶
Bases:
object
Linked List abstract data type.
- NODE¶
alias of
jmath.abstract.lists.Node
- append(data)¶
Appends a node to the end of the list. O(1).
- Parameters
data (Any) – The data to be appended.
- Return type
Returns the node object created in the append.
- extend(list)¶
Extends list. O(1).
- Parameters
list (jmath.abstract.lists.LinkedList) – List to be appended onto this list.
- insert(index, data)¶
Inserts data at the specified index into the list. O(index) operation. Negative indices other than -1 unsupported.
- Parameters
index (int) – Index for data to be inserted at.
data (Any) – Data to be inserted.
- Return type
Returns the node object created in the insertion process.
- list()¶
Returns an equivalent Python List.
- Return type
List[Any]
- class jmath.abstract.lists.MultiNode(data, nodes={})¶
Bases:
object
Node that refers to a set of adjoining nodes
- Parameters
data (Any) – The data value associated with the node.
nodes (set) – Set of neighbours this node is attached to.
- append(node)¶
Appends a node to the set of nodes related to this node.
- Parameters
node (jmath.abstract.lists.MultiNode) – Node to be appended.
- class jmath.abstract.lists.Node(data, next=None)¶
Bases:
object
Node of a list.
- Parameters
data (Any) – Data stored by the node.
next (Node) – Reference to next piece node of the list.
- append(node)¶
Appends a node to the back of this node.
- Parameters
node (jmath.abstract.lists.Node) – Node to be appended.
jmath.abstract.queues module¶
Queue data types.
- class jmath.abstract.queues.Queue¶
Bases:
jmath.abstract.lists.LinkedList
Queue Abstract Data Type
- dequeue()¶
Returns and removes the first queue item.
- Return type
Any
- enqueue(data)¶
Enqueues a piece of data onto the queue.
- data
The piece of data to enqueue.
- Parameters
data (Any) –
jmath.abstract.stacks module¶
Stack Abstract Data Type
- class jmath.abstract.stacks.Stack¶
Bases:
object
Stack Abstract Data Type
- peek()¶
Returns the top item of the stack without removing.
- pop()¶
Removes and returns the top item from the stack.
- Return type
Any
- push(item)¶
Adds a new item on top of the stack.
- Parameters
item (Any) – The item to be added to the stack
Module contents¶
Abstract Data Types from Computer Science.