Skip to content

Commit

Permalink
improved and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
velocitatem committed Jan 8, 2024
1 parent 621e6e7 commit 2eb207b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
59 changes: 59 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# BigONavigator Documentation

Welcome to the documentation for BigONavigator, your comprehensive guide to analyzing computational complexity in Python.

## Introduction

BigONavigator is a Python package developed initially as a university project. It's designed to estimate and track the computational complexity of functions, providing a clear overview of performance in Big O notation.

## Installation

To install BigONavigator, run the following command in your terminal:

```bash
pip install BigONavigator
```

Ensure you have Python version 3.8 or higher installed. Ideally 3.11.

## Getting Started

To begin using BigONavigator, import the package and use the decorators on your functions.

Example:

```python
from bigonavigator import O

@O['n']
def sample_function(data):
# Your code here
pass
```

## Using BigONavigator

### Decorators

BigONavigator provides decorators corresponding to different complexity classes. Here's how to use them:

- `@O['1']`: For constant time complexity.
- `@O['n']`: For linear time complexity.
- `@O['n^2']`: For quadratic time complexity.
- `@O['log(n)']`: For logarithmic time complexity.
- `@O['nlog(n)']`: For linearithmic time complexity.
- `@O['nlog(n)^2']`: For linearithmic time complexity.
- `@O['2^n']`: For exponential time complexity.
- `@O['n!']`: For factorial time complexity.


### Tracking and Displaying Complexity

After decorating your functions, you can display their complexities:

```python
from bigonavigator import show_complexity
show_complexity_table() # tracked statically across all instances
```

This function prints a table showing each function's name and its estimated complexity.
2 changes: 1 addition & 1 deletion bigonavigator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_input(annotation, size):
def decorator(func, comp=c):
tracker[func.__name__] = comp
def wrapper(*args, **kwargs):
func(*args, **kwargs)
return func(*args, **kwargs)
return wrapper
# create a copy of the decorator for each method
O[complexity.value] = decorator
Expand Down
5 changes: 4 additions & 1 deletion bigonavigator/example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from ohno import O, show_complexity_table
# import O from same dire __init__.py
from __init__ import O, show_complexity_table

@O["1"]
def hello_world():
print("Hello World!")
return "Hello World!"

@O["n"]
def hello_world_n(n : int):
Expand All @@ -15,4 +17,5 @@ def hello_world_nfact(n : int):
for j in range(n):
print("Hello World!")

print(hello_world())
show_complexity_table()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "BigONavigator"
version = "0.2.1"
version = "0.2.2"
authors = [
{ name = "Daniel Rosel", email = "[email protected]" }
]
Expand Down

0 comments on commit 2eb207b

Please sign in to comment.