Skip to main content

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


Download files

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

Source Distribution

oven-0.1.0.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

oven-0.1.0-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

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