Skip to main content

avlset

GitHub repo size GitHub contributors GitHub stars GitHub forks PyPI

avlset is a Python package that provides a self-sorting, non-duplicating data structure using a custom AVL Tree implementation. The AVL Tree is a binary search tree with automatic tree balancing. The AVLSet object allows users to insert data with confidence that it will be returned sorted and unique. avlset also provides basic type hinting support in addition to support for multiple built-in Python operators.

Prerequisites

The avlset package requires Python 3.6+.

Installing avlset

avlset is nearly written using raw Python, except for pulling in the built-in typing module for type-hinting support in less modern Python versions. Downloading avlset.py and placing it in your project directory is to use. Alternatively, it can be installed from PyPI using pip:

pip install avlset

Using avlset

from avlset import AVLSet

# Create an instance of AVLSet. The type hint is optional, but recommended.
# Data must be comparable using <, =, and >.
# Using mismatched data types in the same set *will* cause issues.
# This will also work with more complex types like lists ans tuples, if the columns match.
# For example, (str, int) and (str, int) will compare just fine, but (str, str) and (str, int) will break everything.
# Using proper type hinting will help prevent this in larger applications.
myset: AVLSet[int] = AVLSet()

test_data = [3, 5, 2, 7, 2, 4, 2, 6, 2, 8, 7, 10]

# Insert data into set
for n in test_data:
    myset.insert(n)
print(list(myset))  # [2, 3, 4, 5, 6, 7, 8, 10]

# Remove specific data from set
myset.remove(6)
print(list(myset))  # [2, 3, 4, 5, 7, 8, 10]

# Remove and retrieve first (min) item in set
print(myset.pop())  # 2  # OR myset.pop_min()
print(list(myset))  # [3, 4, 5, 7, 8, 10]

# Remove and retrieve last (max) item in set
print(myset.pop_max())  # 10
print(list(myset))  # [3, 4, 5, 7, 8]

# Iterating through set, ascending and descending
for n in myset:
    print(n)
for n in reversed(myset):
    print(n)

# Checking if items exist in set
print(4 in myset)  # True
print(4 not in myset)  # False
print(17 in myset)  # False
print(17 not in myset)  # True

# AVLSet is falsy when empty, and truthy when not
print(bool(myset))  # True
while myset:  # Breaks when list is empty
    myset.pop()
print(bool(myset))  # False

Release files for avlset 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avlset 0.1.0
File Size Uploaded
avlset-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for avlset 0.1.0
File Interpreter ABI Platform
avlset-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / avlset-0.1.0.tar.gz

Download URL avlset-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ef2b600064ec7f4db2292ab241311a2271763b7ef345e3835f31a06e11e7dcf0
BLAKE2b-256 checksum
How to use checksums
9b4eddc8d3970fb49fe57cf9e1ba27eec82a069ce98395aec4d6a80155232cd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / avlset-0.1.0-py3-none-any.whl

Download URL avlset-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dc8f935b8c43d339ef25d3058824fbbe3cd79e887007dab3ae180d885c65c09
BLAKE2b-256 checksum
How to use checksums
43d9da1e3e111ce4c19469ed97f67d1b736c893acabfc841a3b6b6a6755039b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page