An util package that includes features from other languages' stdlib.
Project description
Oven
An util package that includes algorithms, functions and IO similar to that of other languages' standard library.
Installation
Installation with pip is recommended.
pip install oven
Table of Contents
Standard I/O
The stdio package includes convient functions to redefine basic I/O.
from oven.stdio import *
Creating Session
The stdio session is required in order to call any I/O functions. A session is created as such:
set_io(IO_STREAM, 'path/to/file', METHOD)
The IO_STREAM can be any of:
- stdio.FILE: Redirect the IO stream to a file
- stdio.CONSOLE: Redirect the IO stream to the console
The METHOD can be any of:
- r : Read from a file
- w : Write to a file, create/override if nessesary
- a : Append to a file, create if nessesary
Method w overrides the file and dump all output from the session, while a append all output from the session to the end of the file.
If the IO_STREAM is set to CONSOLE, then the path argument will be ignored.
Note that the stdio session is created on the global scope, therefore one session will always suffice for one method of IO action.
An example is given below. This code reads a line of input from a file and print it to the screen.
from oven.stdio import *
set_io(FILE, 'text.in', 'r')
set_io(CONSOLE, None, 'w')
text = cin()
cout(text)
Calling cin/cout
Despite the name, the cin/cout also applies to file IO.
cin() # Read one line.
cout('Hello World') # Write. Note that \n is not added at the end.
Pointer
The Pointer package includes a pointer object.
from oven.pointer import Pointer
Instantiating Pointers
A Pointer is created as such:
ptr_1 = Pointer()
ptr_2 = Pointer(INIT_VALUE)
Calling Pointers
Getting value from pointer:
value = ptr()
Assigning value to pointer:
ptr(value)
Structs
The structs package features some data structures.
from oven.structs import *
Stack
from oven.structs import Stack
The Stack class is a subclass of python's list, its methods are:
- push : Push a value to the stack
- pop : Remove and return the ending element of the stack
Queue
from oven.structs import Queue
The Queue class is a subclass of python's list, its methods are:
- push : Push a value to the queue
- pop : Remove and return the starting element of the queue
Tree
from oven.structs import Tree
The Tree class is a recursive node of a tree. The value of the node can be assigned either in the constructor or by calling the value attribute (variable).
# Both nodes are tree nodes with the value 42
node_1 = Tree(42)
node_2 = Tree()
node_2.value = 42
A child can be added to a node by calling the addChild method and passing the child as the parameter. The children of a node can be accessed by calling the children attribute (variable).
Other methods include:
- dfs : Returns a list of the tree's nodes in depth first search order.
- bfs : Returns a list of the tree's nodes in breadth first search order.
BinaryTree
from oven.structs import BinaryTree
The BinaryTree class is a subclass of the Tree class. The left and right children can be accessed by:
node.left() # Returns the left node
node.right() # Returns the right node
node.left(newNode) # Sets the left node
node.right(newNode) # Sets the right node
Due to this, the addChild method is removed.
All other methods are identical to that of the Tree class except the dfs method, which is tweaked so that the calling of it becomes:
node.dfs(MODE)
The MODE can be any of:
- PREORDER
- INORDER
- POSTORDER
All of the above modes are imported as such:
from oven.structs import PREORDER, INORDER, POSTORDER
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file oven-0.1.0.tar.gz
.
File metadata
- Download URL: oven-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df6876b446809e1fb319c1e213d210a464c9de5a84eddaf2b7a4167f581ee251 |
|
MD5 | e9c14eeaa73927b367743af84b84f225 |
|
BLAKE2b-256 | 27595bfef19cb6699e51a2af1f9d161ea14805744720ed5ddf987a3bfa5c2c79 |
File details
Details for the file oven-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: oven-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 115b8958a9d1ca501e1e6ec48798ef4f9d3103afe07f15bd3a92fcf16317c8ac |
|
MD5 | d507882f0c2ca499d26a2fd06f0dda5d |
|
BLAKE2b-256 | 0866aa65b3128ca0ececec4a4601d292d69e9e87d531456c11c08b89c37abc16 |