Skip to main content

This is a package which will allow for easy implementation of basic Data Structures.

Project description

Pypeline

This is a python library for easy implementation of Data Structures and Algorithms. In future iterations, this library will include plugins for Data Analysis and Machine Learning, specifically for data collection and manipulation.

Future Work

On the next iteration of Pypeline, we will release a method to pass Python Data Structures to files for seamless integration with R graphing plugins.

Installation

Install Pypeline v1.0.1 using pip:

$ pip install python-pypeline

If version installed is <= v1.0.1 then you need to upgrade to the latest version of Pypeline:

$ pip install python-pypeline --upgrade

To test install, run the following line of code:

>>> import Pypeline

Development

Run all scripts from within the Pypeline folder as follows:

$ ./scripts/run_tests.sh

Data Structures Implemented


Sample Implementations

AVL Tree

from Pypeline.Pypes.AVLTree import AVL

# Instantiate AVL Tree
avl = AVL()

# Add Nodes to the Tree; the tree will automatically balance itself
for i in range(10):
  avl.insert(i)

# Display the AVL Tree using an In Order Traversal
avl.traverse() # will display numbers 1 - 10

# Remove nodes from the Tree
avl.remove(5)

Binary Search Tree

from Pypeline.Pypes.BinarySearchTree import BST

# Instantiate Binary Search Tree
bst = BST()

# Add Nodes to the Tree; the tree will NOT balance itself
for i in range(10):
  bst.insert(i)

# Get size of the Tree
bst_size = bst.getSize()

# Display the BST using an In Order Traversal; can also use preOrderTraversal and postOrderTraversal
bst.inOrderTraversal() # will display numbers 1 - 10

# Remove nodes from the Tree
bst.remove(5)

# Get min value and max value
bst_min, bst_max = bst.getMinValue(), bst.getMaxValue()

Max Heap

from Pypeline.Pypes.MaxHeap import MaxHeap

# Instantiate the Max Heap; the list can be passed in on instantiation or with a builtin method
maxheap = MaxHeap()

# Convert list to MaxHeap
maxheap.heapify([2, 4 , 10, 8])

# Merge heap with another list
maxheap.merge([1, 5, 3, 7])

# Pop largest value from the heap
_ = maxheap.heappop()

# Insert value (type int or float) into the Heap
maxheap.heappush(20)

# Convert heap into numpy array
np_maxheap = maxheap.to_array()

# Print the Max Heap Contents; Currently the Data Structure is not iterable
print(maxheap)

Min Heap

from Pypeline.Pypes.MinHeap import MinHeap

# Instantiate the Min Heap; the list can be passed in on instantiation or with a builtin method
minheap = MinHeap()

# Convert list to MinHeap
minheap.heapify([2, 4 , 10, 8])

# Merge heap with another list
minheap.merge([1, 5, 3, 7])

# Pop smallest value from the heap
_ = minheap.heappop()

# Insert value (type int or float) into the Heap
minheap.heappush(20)

# Convert heap into numpy array
np_minheap = minheap.to_array()

# Print the Min Heap Contents; Currently the Data Structure is not iterable
print(minheap)

Node

from Pypeline.Pypes.Node import Node

# Instantiation; However, this is meant to be a super class not a stand alone object
node = Node()

# Set Node value; This can be passed into object instantiation as well
node.setVal(10)

# Get value of the Node
_ = node.getVal()

# Set/Swap Visisted (if needed); default is false
node.setVisited() # visted -> true
node.swapVisited() # visited -> false

# Check if Node is Visited
_ = node.isVisited()

Linked List

from Pypeline.Pypes.LinkedList import LinkedList

# Instantiation
linked = LinkedList()

# Insert Value to list (dtype -> any); T.C -> O(1)
for i in range(10):
	linked.insert(i)

# Delete node from the linkedlist T.C -> O(N)
linked.remove(5)

# Get Size of the linkedlist
_ = linked.getSize()

# Traverse List: print all values in linkedlist; T.C -> O(N)
linked.traverseList()

# Convert linkedlist to numpy array; returns the converted array
nplinked = linked.to_array()

# Convert linkedlist to python list; return the converted list
regular_list = linked.to_list()

# Can print linked list and it will display the corresponding python list
print(linked)

Queue

from Pypeline.Pypes.Queue import Queue

# Instantiation of Queue; maxlen property specifies largest size for array
queue = Queue(maxlen=1e9)

# Enqueue data to the queue
for i in range(10):
	queue.enqueue(i)

# Dequeue data from the queue; FIFO
_ = queue.dequeue()

# Peek the front of the queue; returns the value without removing
front = queue.peek()

# Get the size of the queue
size = queue.sizeQueue()

# Check if queue is empty; returns -> type bool
_ = queue.isEmpty()

# Convert queue to numpy array
npqueue = queue.to_array()

# Convert queue to python list
list_queue = queue.to_list()

Stack

from Pypeline.Pypes.Stack import Stack

# Instantiation of Stack; maxlen property specifies largest size for array
stack = Stack(maxlen=1e9)

# Enqueue data to the stack
for i in range(10):
	stack.push(i)

# Dequeue data from the stack; LIFO
_ = stack.pop()

# Peek the top of the stack; returns the value without removing
front = stack.peek()

# Get the size of the queue
size = stack.sizeStack()

# Check if stack is empty; returns -> type bool
_ = stack.isEmpty()

# Convert stack to numpy array
npstack = stack.to_array()

# Convert queue to python list
list_stack = stack.to_list()

Trie

from Pypeline.Pypes.Trie import Trie

# Instantiation
tree = Trie()

# Insert word into the tree
tree.insert('word')
tree.insert('data structure')

# Search for a word in the tree
_ = tree.search('word') # -> returns true if word in tree
_ = tree.search('data') # -> returns false if word not in tree

Ternary Search Tree

from Pypeline.Pypes.TernarySearchTree import TST

# Instantiation
tst = TST()

# Put Key and value into the tree
tst.put("cat",5)
tst.put("dog",10)

# Get the value from the key of the tree
_ = tst.get('cat') # -> returns 5
_ = tst.get("bird") # -> returns -1 if key not in tree

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-pypeline-1.0.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_pypeline-1.0.1-py2.py3-none-any.whl (20.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python-pypeline-1.0.1.tar.gz.

File metadata

  • Download URL: python-pypeline-1.0.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for python-pypeline-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9b50a209d987a248401457ca64edd39815cb979a93dbc87198525aed6ec96da1
MD5 e1aeeda13b0ffe1448f268660245a9e9
BLAKE2b-256 d71e53d37e72481ec59fba9dfc641c20de13be68150ed1ef5a601b8e6ff0ae3d

See more details on using hashes here.

File details

Details for the file python_pypeline-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: python_pypeline-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for python_pypeline-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9868d96e53b10000e2625a41496d8adc1073d59a5cd7d8ef4bdd9a241200cdc6
MD5 2feb6696740e0ff45b6d02b9485d3f44
BLAKE2b-256 98ad2b72b8948adaf727e4c36b322dc1dd5785760735e9a9ca0d5669d882767d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page