Skip to content

Commit

Permalink
Merge pull request #1 from warmachine028/v0.0.2
Browse files Browse the repository at this point in the history
Added changes for V0.0.2
  • Loading branch information
warmachine028 authored Dec 17, 2021
2 parents 6ae7164 + a6425a8 commit 4187d26
Show file tree
Hide file tree
Showing 27 changed files with 350 additions and 123 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Expand Down
125 changes: 120 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,134 @@
# datastax
updated: Friday, 17th December 2021

<div align=center>
<a href="https://github.com/warmachine028/datastax"><img width=200 src="assets/icon.png" alt="datastax"></a>
<p style="font-family: roboto, calibri; font-size:12pt; font-style:italic"> Simplicity meets intelligence</p>
<a href="https://github.com/warmachine028/datastax/releases/"> <img src="https://img.shields.io/github/v/release/warmachine028/datastax?color=brightgreen"></a>
<br>
<a href="https://github.com/warmachine028/datastax/releases/tag/V4.2.1-beta"> <img alt="" src="https://img.shields.io/github/v/release/warmachine028/datastax?color=lightgreen&include_prereleases&label=pre%20release"> </a>
<br>
<img src="https://img.shields.io/github/stars/warmachine028/datastax">
<a href= "https://github.com/warmachine028/datastax/blob/main/LICENSE"><img src="https://img.shields.io/github/license/warmachine028/datastax?color=orange"></a>
<a href="https://github.com/warmachine028/datastax/network/members"><img src="https://img.shields.io/github/forks/warmachine028/datastax?color=cyan"></a>
</div>

# [Datastax](https://github.com/warmachine028/datastax)

## What's New?

- Added terminal demo
- Improved type hinting using mypy static type checker
- Removed few bugs and potential errors
- Purified test_structure
- Improvised for uploading in PyPI

## Table of Contents

- [Introduction](#introduction)
- [Problem Statement](#problem-statement)
- [Benefits](#benefits)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

## Introduction

- This is a very simple yet powerful project to implement day to day data structures.
- This is a very simple yet powerful project to implement day to day abstract data structures.
- A pure implementation of Python in representing Trees and Linkedlists 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 in the beginning CS students face problems in understanding the internal architecture of 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.
- Often while writing a programs implementing 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.8+
- This Library requires no extra modules

## Installation

Use the python package manager [pip](https://pip.pypa.io/en/stable/) to install datastax.
1. Clone this repository locally
2. Reach base folder _datastax/_
3. Use the python package manager [pip](https://pip.pypa.io/en/stable/) to install datastax.

```bash
pip install datastax
pip install .
```

## Usage

### Demo

- To get a demo of the library use the following command
- **Windows**:

```bash
> py -m datastax
```
- **Unix based systems**:

```bash
$ python -m datastax
```
- _Result_
```bash
Available modules are:
1. LinkedLists
2. Trees

Usage
$ py datastax <data-structure> [data]
Data Structures:
trees Hierarchical DS
linkedlists Linear DS
```
- Then follow as the instruction guides

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

1. Singly Linked List:
Node[1] -> Node[2] -> Node[3] -> Node[4] -> NULL

2. Doubly Linked List:
NULL <-> Node[1] <-> Node[2] <-> Node[3] <-> Node[4] <-> NULL
...
```

### Practical Usage

```py
from datastax.trees import BinaryTree

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

## OUTPUT:
"""
1
┌─────┴─────┐
2 3
┌──┴──┐
4 5
"""
```

## Usage
Binary file added assets/datastax.ico
Binary file not shown.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions datastax/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# __init__.py

# Versioning of the datastax package
__version__ = "0.0.2"
__all__ = ['trees', 'linkedlists']
35 changes: 35 additions & 0 deletions datastax/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys

from datastax import linkedlists as ll, trees


def main():
if len(sys.argv) > 1:
data_structure = sys.argv[1].lower()
data = sys.argv[2:] if len(sys.argv) > 2 else [*range(5)] # take User given data or default
if data_structure in ('linkedlist', "linkedlists"):
print("Visuals for LinkedLists:\n\n"
f"1. Singly Linked List: \n{ll.LinkedList(data)}\n\n"
f"2. Doubly Linked List: \n{ll.DoublyLinkedList(data)}\n\n"
f"3. Circular Linked List: \n{ll.CircularLinkedList(data)}\n\n"
f"4. Doubly Circular List: \n{ll.DoublyCircularList(data)}\n\n")
elif data_structure in ('tree', 'trees'):
print("Visuals for Trees:\n\n"
f"1. Binary Tree \n{trees.BinaryTree(data)}\n\n"
f"2. Binary Search Tree \n{trees.BinarySearchTree(data)}\n\n"
f"3. AVL Tree \n{trees.AVLTree(data)}\n\n")
else:
print("This module is not available yet")
else:
print("Available modules are:\n"
"1. LinkedLists\n"
"2. Trees\n"
"\nUsage\n"
"$ py datastax <data-structure> [data]\n"
"Data Structures: \n"
" trees Hierarchical DS\n"
" linkedlists Linear DS")


if __name__ == '__main__':
main()
9 changes: 8 additions & 1 deletion datastax/linkedlists/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .circular_list import CircularLinkedList
from .circular_linked_list import CircularLinkedList
from .doubly_circular_list import DoublyCircularList
from .doubly_linked_list import DoublyNode, DoublyLinkedList
from .linked_list import LinkedList, Node

__all__ = [
'LinkedList', 'Node',
'DoublyLinkedList', 'DoublyNode',
'CircularLinkedList',
'DoublyCircularList'
]
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,3 @@ def __str__(self, node: Node = None):
if ref is head: break
string += f"┐\n{'<'.center(len(string) - 1, '─')}┘"
return string


if __name__ == '__main__':
CLL = CircularLinkedList([*range(5)])
CLL.insert(999)
CLL.append("ABQ")
print(CLL.__str__())
print(CLL.__str__(CLL.head.next))
print(CLL.__str__(CLL.head.next.next))
print(CLL.__str__(CLL.head.next.next.next))
print(CLL.__str__(CLL.head.next.next.next.next))
15 changes: 2 additions & 13 deletions datastax/linkedlists/doubly_circular_list.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Any

from datastax.linkedlists.circular_list import CircularLinkedList
from datastax.linkedlists.doubly_linked_list import DoublyLinkedList, DoublyNode


class DoublyCircularList(DoublyLinkedList, CircularLinkedList):
class DoublyCircularList(DoublyLinkedList):
def append(self, data: Any) -> None:
super().append(data)
self.head.prev, self.tail.next = self.tail, self.head
Expand All @@ -13,7 +12,7 @@ def insert(self, data: Any) -> None:
super().insert(data)
self.head.prev, self.tail.next = self.tail, self.head

def __str__(self, reverse: bool = False, node: DoublyNode = None):
def __str__(self, reverse=False, node: DoublyNode = None):
head = node or (self.tail if reverse else self.head)
if not head: return "NULL"
string = f"┌->"
Expand All @@ -24,13 +23,3 @@ def __str__(self, reverse: bool = False, node: DoublyNode = None):
if ref is head: break
string = f"{string[:-1]}\n{'<-->'.center(len(string) - 2, '─')}┘"
return string


if __name__ == '__main__':
DCLL = DoublyCircularList([1, 2, 3])
print(DCLL)
print(DCLL.__str__(True))
print(DCLL.__str__(False, DCLL.head.next))
print(DCLL.__str__(False, DCLL.head.next.next))
print()
print(DCLL.__str__(True, DCLL.head.prev))
31 changes: 13 additions & 18 deletions datastax/linkedlists/doubly_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from typing import Any
from typing import Any, Optional

from datastax.linkedlists.linked_list import Node, LinkedList


class DoublyNode(Node):
def __init__(self, data: Any, nex: Node = None, prev=None):
super().__init__(data, nex)
def __init__(self, data: Any, nex: DoublyNode = None, prev: DoublyNode = None):
super().__init__(data)
self.next = nex
self.prev = prev

def __str__(self):
Expand All @@ -17,6 +18,11 @@ def __str__(self):


class DoublyLinkedList(LinkedList):
def __init__(self, array: list[Any], head: DoublyNode = None):
self._head: Optional[DoublyNode] = head
self._tail = head
super().__init__(array, head)

def append(self, data) -> None:
node = DoublyNode(data, None, self.tail)
if not self.head: self._head = node
Expand All @@ -32,20 +38,9 @@ def insert(self, data: Any):
def __str__(self, reverse=False, node: DoublyNode = None):
string = "NULL"
if not self.head: return string
node = node or (self.tail if reverse else self.head)
while node:
string += f" <-> Node[{node.data}]"
node = node.prev if reverse else node.next
head = node or (self.tail if reverse else self.head)
while head:
string += f" <-> Node[{head.data}]"
head = head.prev if reverse else head.next
string += " <-> NULL"
return string


# __main__
if __name__ == '__main__':
D = DoublyLinkedList([*range(5)])
print("head -> ", D.head)
D.insert(10)
D.insert(20)
D.append(199)
print(D)
print(D.__str__(True))
7 changes: 5 additions & 2 deletions datastax/linkedlists/linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def __init__(self, data: Any, nex: Node = None):

def __str__(self):
return f'Node[{self.data}] -> ' \
f'Node[{self.next.data}]' if self.next else "NULL"
f"{f'Node[{self.next.data}]' if self.next else 'NULL'}"

def __repr__(self):
return self.__str__()


class LinkedList:
Expand All @@ -30,7 +33,7 @@ def tail(self): return self._tail
def append(self, data: Any) -> None:
node = Node(data)
if not self.head: self._head = node
else: self._tail.next = node
else: self.tail.next = node
self._tail = node

def insert(self, data: Any):
Expand Down
8 changes: 7 additions & 1 deletion datastax/trees/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from .avl_tree import AVLTree, AVLTreeNode
from .avl_tree import AVLTree, AVLNode
from .binary_search_tree import BinarySearchTree
from .binary_tree import BinaryTree, TreeNode

__all__ = [
"BinaryTree", "TreeNode",
"BinarySearchTree",
"AVLTree", "AVLNode"
]
Loading

0 comments on commit 4187d26

Please sign in to comment.