Skip to main content

Search trees.

Project description

dendroid

Github Actions Codecov License PyPI

In what follows python is an alias for python3.10 or pypy3.10 or any later version (python3.11, pypy3.11 and so on).

Installation

Prerequisites

Install the latest pip & setuptools packages versions

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

python -m pip install --upgrade dendroid

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/dendroid.git
cd dendroid

Install

python -m pip install -e '.'

Usage

>>> from dendroid import avl, red_black, splay
>>> from random import sample
>>> min_value, max_value = -100, 100
>>> size = (max_value - min_value) // 2
>>> values = sample(range(min_value, max_value), size)
>>> avl_set, red_black_set, splay_set = (avl.set_(*values),
...                                      red_black.set_(*values),
...                                      splay.set_(*values))
>>> len(avl_set) == len(red_black_set) == len(splay_set) == size
True
>>> (
...     max_value not in avl_set
...     and max_value not in red_black_set
...     and max_value not in splay_set
... )
True
>>> list(avl_set) == list(red_black_set) == list(splay_set) == sorted(values)
True
>>> avl_set.add(max_value)
>>> red_black_set.add(max_value)
>>> splay_set.add(max_value)
>>> len(avl_set) == len(red_black_set) == len(splay_set) == size + 1
True
>>> max_value in avl_set and max_value in red_black_set and max_value in splay_set
True
>>> (
...     list(avl_set)
...     == list(red_black_set)
...     == list(splay_set)
...     == sorted(values) + [max_value]
... )
True
>>> prev_max_value = max(values)
>>> (
...     avl_set.prev(max_value)
...     == red_black_set.prev(max_value)
...     == splay_set.prev(max_value)
...     == prev_max_value
... )
True
>>> (
...     avl_set.next(prev_max_value)
...     == red_black_set.next(prev_max_value)
...     == splay_set.next(prev_max_value)
...     == max_value
... )
True
>>> avl_set.remove(max_value)
>>> red_black_set.remove(max_value)
>>> splay_set.remove(max_value)
>>> len(avl_set) == len(red_black_set) == len(splay_set) == len(values)
True
>>> (
...     max_value not in avl_set
...     and max_value not in red_black_set
...     and max_value not in splay_set
... )
True
>>> list(avl_set) == list(red_black_set) == list(splay_set) == sorted(values)
True
>>> avl_set.max() == red_black_set.max() == splay_set.max() == max(values)
True
>>> avl_set.min() == red_black_set.min() == splay_set.min() == min(values)
True
>>> avl_set.max() == red_black_set.max() == splay_set.max() == max(values)
True
>>> avl_set.min() == red_black_set.min() == splay_set.min() == min(values)
True
>>> avl_set.add(max_value)
>>> red_black_set.add(max_value)
>>> splay_set.add(max_value)
>>> avl_set.popmax() == red_black_set.popmax() == splay_set.popmax() == max_value
True
>>> avl_set.add(min_value)
>>> red_black_set.add(min_value)
>>> splay_set.add(min_value)
>>> avl_set.popmin() == red_black_set.popmin() == splay_set.popmin() == min_value
True
>>> min_key, max_key = min_value, max_value
>>> keys = sample(range(min_key, max_key), size)
>>> items = list(zip(keys, values))
>>> avl_map, red_black_map, splay_map = (avl.map_(*items),
...                                      red_black.map_(*items),
...                                      splay.map_(*items))
>>> len(avl_map) == len(red_black_map) == len(splay_map) == size
True
>>> max_key not in avl_map and max_key not in red_black_map and max_key not in splay_map
True
>>> list(avl_map) == list(red_black_map) == list(splay_map) == sorted(keys)
True
>>> avl_map[max_key] = red_black_map[max_key] = splay_map[max_key] = max_value
>>> len(avl_map) == len(red_black_map) == len(splay_map) == size + 1
True
>>> max_key in avl_map and max_key in red_black_map and max_key in splay_map
True
>>> avl_map[max_key] == red_black_map[max_key] == splay_map[max_key] == max_value
True
>>> list(avl_map) == list(red_black_map) == list(splay_map) == sorted(keys) + [max_key]
True
>>> prev_max_key, prev_max_value = items[max(range(size), key=keys.__getitem__)]
>>> (
...     avl_map.prev(max_key)
...     == red_black_map.prev(max_key)
...     == splay_map.prev(max_key)
...     == prev_max_value
... )
True
>>> (
...     avl_map.next(prev_max_key)
...     == red_black_map.next(prev_max_key)
...     == splay_map.next(prev_max_key)
...     == max_value
... )
True
>>> del avl_map[max_key], red_black_map[max_key], splay_map[max_key]
>>> len(avl_map) == len(red_black_map) == len(splay_map) == size
True
>>> max_key not in avl_map and max_key not in red_black_map and max_key not in splay_map
True
>>> list(avl_map) == list(red_black_map) == list(splay_map) == sorted(keys)
True
>>> (
...     avl_map.max()
...     == red_black_map.max()
...     == splay_map.max()
...     == values[max(range(size), key=keys.__getitem__)]
... )
True
>>> (
...     avl_map.min()
...     == red_black_map.min()
...     == splay_map.min()
...     == values[min(range(size), key=keys.__getitem__)]
... )
True
>>> avl_map[max_key] = red_black_map[max_key] = splay_map[max_key] = max_value
>>> avl_map.popmax() == red_black_map.popmax() == splay_map.popmax() == max_value
True
>>> avl_map[min_key] = red_black_map[min_key] = splay_map[min_key] = min_value
>>> avl_map.popmin() == red_black_map.popmin() == splay_map.popmin() == min_value
True

Development

Bumping version

Prerequisites

Install bump-my-version.

Release

Choose which version number category to bump following semver specification.

Test bumping version

bump-my-version bump --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump-my-version bump --verbose $CATEGORY

This will set version to major.minor.patch.

Running tests

Plain

Install with dependencies

python -m pip install -e '.[tests]'

Run

pytest

Docker container

Run

  • with CPython

    docker-compose --file docker-compose.cpython.yml up
    
  • with PyPy

    docker-compose --file docker-compose.pypy.yml up
    

Bash script

Run

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script

Run

  • with CPython

    .\run-tests.ps1
    

    or

    .\run-tests.ps1 cpython
    
  • with PyPy

    .\run-tests.ps1 pypy
    

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

dendroid-2.1.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dendroid-2.1.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file dendroid-2.1.0.tar.gz.

File metadata

  • Download URL: dendroid-2.1.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dendroid-2.1.0.tar.gz
Algorithm Hash digest
SHA256 7b8adb4f7d38608d62a2f4fb515f98e80c17bd1fe2d045a54c9cea575117d024
MD5 4738a7cbde1610edae2defc1cac76c73
BLAKE2b-256 7160884855fe5654a7f9127fc8b2dfa0ffb4ab001ea63aee95f056ea7563f0ae

See more details on using hashes here.

File details

Details for the file dendroid-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: dendroid-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dendroid-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27259eb8ba37232dd1f85716e22459f05d5ee1f69332137be7fbf1d78e5d8599
MD5 dfb96c371158b1eb0ffdfaee720a07a5
BLAKE2b-256 e0bbdacf2e7070f26eab7843348ac1efa53734ec83c7dabd621488fef41dac3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page