How to use sortedcontainers - 10 common examples

To help you get started, we’ve selected a few sortedcontainers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grantjenks / python-sortedcontainers / tests / test_coverage_sortedlist.py View on Github external
def test_init():
    slt = SortedList()
    assert slt.key is None
    slt._check()

    slt = SortedList()
    slt._reset(10000)
    assert slt._load == 10000
    slt._check()

    slt = SortedList(range(10000))
    assert all(tup[0] == tup[1] for tup in zip(slt, range(10000)))

    slt.clear()
    assert slt._len == 0
    assert slt._maxes == []
    assert slt._lists == []
    slt._check()
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedkeylist_negate.py View on Github external
def test_init():
    slt = SortedKeyList(key=negate)
    slt._check()

    slt = SortedKeyList(key=negate)
    slt._reset(10000)
    assert slt._load == 10000
    slt._check()

    slt = SortedKeyList(range(10000), key=negate)
    assert all(tup[0] == tup[1] for tup in zip(slt, reversed(range(10000))))

    slt.clear()
    assert slt._len == 0
    assert slt._maxes == []
    assert slt._lists == []
    slt._check()
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedkeylist_modulo.py View on Github external
def test_init():
    slt = SortedKeyList(key=modulo)
    assert slt.key == modulo
    slt._check()

    slt = SortedKeyList(key=modulo)
    slt._reset(10000)
    assert slt._load == 10000
    slt._check()

    slt = SortedKeyList(range(10000), key=modulo)
    assert all(tup[0] == tup[1] for tup in zip(slt, sorted(range(10000), key=modulo)))

    slt.clear()
    assert slt._len == 0
    assert slt._maxes == []
    assert slt._lists == []

    assert isinstance(slt, SortedList)
    assert isinstance(slt, SortedKeyList)

    slt._check()
github grantjenks / python-sortedcontainers / tests / test_coverage_sorteddict.py View on Github external
def test_popitem():
    mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
    temp = SortedDict(mapping)
    assert temp.popitem() == ('z', 25)
github grantjenks / python-sortedcontainers / tests / test_coverage_sorteddict.py View on Github external
def test_reversed_key():
    temp = SortedDict(modulo, ((val, val) for val in range(100)))
    temp._reset(7)
    values = sorted(range(100), key=modulo)
    assert all(lhs == rhs for lhs, rhs in zip(reversed(temp), reversed(values)))
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedlist.py View on Github external
def test_discard():
    slt = SortedList()

    assert slt.discard(0) == None
    assert len(slt) == 0
    slt._check()

    slt = SortedList([1, 2, 2, 2, 3, 3, 5])
    slt._reset(4)

    slt.discard(6)
    slt._check()
    slt.discard(4)
    slt._check()
    slt.discard(2)
    slt._check()

    assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedkeylist_negate.py View on Github external
def test_delitem():
    random.seed(0)
    slt = SortedKeyList(range(100), key=negate)
    slt._reset(17)
    while len(slt) > 0:
        del slt[random.randrange(len(slt))]
        slt._check()
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedkeylist_negate.py View on Github external
def test_index_valueerror4():
    slt = SortedKeyList([0] * 10, key=negate)
    slt._reset(4)
    with pytest.raises(ValueError):
        slt.index(1)
github grantjenks / python-sortedcontainers / tests / benchmark_sortedlist.py View on Github external
# Setups.

def do_nothing(obj, size):
    pass

def fill_values(obj, size):
    obj.update(sorted(lists[size]))

# Implementation imports.

from .context import sortedcontainers
from sortedcontainers import SortedList
kinds['SortedList'] = SortedList

from sortedcontainers import SortedKeyList
kinds['SortedKeyList'] = SortedKeyList

try:
    from blist import sortedlist
    kinds['B-Tree'] = sortedlist
except ImportError:
    warnings.warn('No module named blist', ImportWarning)

try:
    from .sortedcollection import SortedCollection
    kinds['List'] = SortedCollection
except ImportError:
    warnings.warn('No module named sortedcollection', ImportWarning)

# Implementation configuration.

for name in tests:
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedkeylist_modulo.py View on Github external
def test_index_valueerror1():
    slt = SortedKeyList([0] * 10, key=modulo)
    slt._reset(4)
    with pytest.raises(ValueError):
        slt.index(0, 10)