Skip to main content

A python library to handle dataStructures

Project description

updated: Thursday, 24th February 2022
datastax

Simplicity meets intelligence

PyPI PyPI Downloads


dataStax

What's New?

  • Added Sum Segment Tree
  • Added Min Segment Tree
  • Added Huffman Tree
    • data encoder
    • data decoder
    • Huffman Code
    • Huffman Table
    • compression ratio
    • space saved
  • Added Red Black Tree - ๐Ÿ—ธ TESTED
  • Added Splay Tree - ๐Ÿ—ธ TESTED
  • Added Delete methods in: ๐Ÿ—ธ TESTED
    • BinaryTree
    • BinarySearchTree
    • AVLTree
  • Enhanced string representation of all LinkedLists
  • Added Custom Comparator for PriorityQueue
  • Added name-mangler function for items with multiline string representations
  • Added HuffmanTable object for storing and visualizing huffman-table

Table of Contents

Introduction

  • This is a very simple yet powerful project to implement day to day abstract data structures
  • A pure implementation of Python in representing Tree, Linkedlist and Array based datastructures in basic command prompt
  • It helps visualize each data structure for better understanding
  • Students can be beneficial in using this Package
  • This project is still under construction

Problem Statement

  • Often at the beginning of B.Tech Course, CS students face a lot of problems understanding the internal architecture of complex ADTs.
  • While solving coding challenges locally where test cases have to be written using these ADTs, it becomes really cumbersome to write these data structures from scratch.
  • Also, when writing programs which implements these ADS, we encounter lots of errors just because we are unable to preview what's actually going on under the hood.

Benefits

  • Instant installation
  • Quick Updates
  • Very small size
  • No extra modules required
  • Written purely from scratch
  • Easy Documentation [Upcoming]
  • Command Line Demo

Requirements

  • Runs on latest Python 3.7+
  • (WARNING: Though the module might run on py 3.7 error free, but it has been tested for 3.9+)
  • (Suggesting you to always update to the latest python version)
  • This Library requires no extra modules

Installation

  1. Use the python package manager pip to install datastax.
pip install datastax

Usage

Demo

  • To get a demo of the library use the following command

    • Windows:
    > py -m datastax 
    
    • Unix based systems:
    $ python3 -m datastax
    
    • Result
    Available modules are:
    1. LinkedLists
    2. Trees
    3. Arrays
    
    Usage
    > py datastax <data-structure> [data]
    Data Structures:
    ->  trees          Hierarchical DS
    ->  linkedlists    Linear DS
    ->  arrays         Fixed Size Linear DS
    
  • Then follow as the instruction guides

> py -m datastax linkedlist 1 2 3 4
  Visuals for LinkedLists:

  1. Singly Linked List:
     HEAD                                         TAIL
 โ”Œโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”
 โ”‚  1  โ•‘  ----->โ”‚  2  โ•‘  ----->โ”‚  3  โ•‘  ----->โ”‚  4  โ•‘  -----> NULL
 โ””โ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜


  2. Doubly Linked List:
               HEAD                                                        TAIL
         โ”Œโ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”
 NULL <-----  โ•‘  1  โ•‘  <------->  โ•‘  2  โ•‘  <------->  โ•‘  3  โ•‘  <------->  โ•‘  4  โ•‘  -----> NULL
         โ””โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”˜
  ...

Practical Usage

  • Queue
from datastax.arrays import Queue

# Building a Queue Data Structure with fixed capacity
queue = Queue(capacity=5)

# Enqueueing items inside queue
for item in ('item 1', 'item 2'):
    queue.enqueue(item)

# Performing Dequeue Operation 
queue.dequeue()

queue.enqueue('item 3')
print(queue)
$ OUTPUT:

         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฅโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
FRONT -> โ”‚    โ•ณ     โ•‘  item 2  โ”‚  item 3  โ”‚ <- REAR
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•จโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      

  • BinaryTree
from datastax.trees import BinaryTree

bt = BinaryTree([1, 2, 3, 4, 5])
print(bt)
$ OUTPUT:

             1           
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”     
       2           3     
    โ”Œโ”€โ”€โ”ดโ”€โ”€โ”              
    4     5              

  • MinHeapTree
from datastax.trees import MinHeapTree

MiHT = MinHeapTree([1, 2, 4, 2, 6, 5, 9, 18, 3, 2])
print(MiHT)
$ OUTPUT

                        1                       
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           
            2                       4           
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”     
      2           2           5           9     
   โ”Œโ”€โ”€โ”ดโ”€โ”€โ”     โ”Œโ”€โ”€โ”˜                             
  18     3     6    

  • ThreadedBinaryTree
from datastax.trees import ThreadedBinaryTree as Tbt

logic = str("BinaryTree")
tbt = Tbt(['a', 'b', 'c', 'd', 'e'], insertion_logic=logic)
print(tbt)
$ OUTPUT               
                                   โ”Œโ”€โ”€โ”€โ”
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> DUMMY โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚                           โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜               โ”‚
   โ”‚                           a                       โ”‚        
   โ”‚           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚        
   โ”‚           b           โ”‚           โ”‚       c       โ”‚        
   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        
   โ”‚   d   โ”‚       โ”‚   e   โ”‚                                    
   โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜                                    

  • SumSegmentTree
from datastax.trees import SumSegmentTree

sst = SumSegmentTree([1, 3, 5, 7, 9, 11])
print(sst)
print(sst.preorder_print())
$ OUTPUT        
                                                
                       36                       
                      [0:5]                     
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           
            9                      27           
          [0:2]                   [3:5]         
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”     
      4           5          16          11     
    [0:1]                   [3:4]               
   โ”Œโ”€โ”€โ”ดโ”€โ”€โ”                 โ”Œโ”€โ”€โ”ดโ”€โ”€โ”              
   1     3                 7     9              


36 [0:5]
โ”œโ”€โ–ถ 9 [0:2]
โ”‚   โ”œโ”€โ–ถ 4 [0:1]
โ”‚   โ”‚   โ”œโ”€โ–ถ 1 
โ”‚   โ”‚   โ””โ”€โ–ถ 3 
โ”‚   โ””โ”€โ–ถ 5 
โ””โ”€โ–ถ 27 [3:5]
    โ”œโ”€โ–ถ 16 [3:4]
    โ”‚   โ”œโ”€โ–ถ 7 
    โ”‚   โ””โ”€โ–ถ 9 
    โ””โ”€โ–ถ 11             
                  

  • HuffmanTree
from datastax.trees import HuffmanTree

string = str("Espresso Express")
hft = HuffmanTree(string)
print(hft)
$ OUTPUT
                                               16                                               
                         0                      โ”‚                      1                        
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       
                        7                                               9                       
             0          โ”‚          1                         0          โ”‚          1            
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           
            3                       4                       4                       s           
       0    โ”‚    1             0    โ”‚    1             0    โ”‚    1                  5           
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”                             
      x           2           e           r           E           p                             
      1         0 โ”‚ 1         2           2           2           2                             
               โ”Œโ”€โ”€โ”ดโ”€โ”€โ”                                                                          
               o                                                                                
               1     1       

  • RedBlackTree
from datastax.trees import RedBlackTree

rbt = RedBlackTree([500, 236, 565, 105, 842, 497, 312, 612, 80])
rbt.delete(236)
print(rbt)
$ OUTPUT                                                                         
                                   500                                      
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                     
                 105                                 612                    
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            
        80                497               565               842           
                       โ”Œโ”€โ”€โ”€โ”˜                                                
                     312
                                                                                                                                    

What's Next

  • Enhanced Documentation
  • Better TestCases for Huffman Tree
  • Better TestCases for Segment Trees
  • Test Cases for Fibonacci Tree
  • Adding of images of trees instead of trees themselves in README

Download files

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

Source Distribution

datastax-0.3.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

datastax-0.3.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file datastax-0.3.0.tar.gz.

File metadata

  • Download URL: datastax-0.3.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for datastax-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d37582a56778fb0a67307f39aa6bc8fe69d5051685e50340f60358e792d2150d
MD5 e4bb87eb918f1762fc2c30a828c7b93e
BLAKE2b-256 f684aa6174e420ecf9e0e9c3675974e4a69d6dc848534172d3842de8f05177ef

See more details on using hashes here.

File details

Details for the file datastax-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: datastax-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for datastax-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 027f1059cda8fdbdd47bc0925dd250d52ba94460af0809ea4b33b2e136a0208e
MD5 9c28815bc76193c9f785aefa1b0f5865
BLAKE2b-256 09a09d0cbcbec71e018b2791ae5f11dc461fa5c21b8f33e957945dd490c62f88

See more details on using hashes here.

Supported by

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