当前位置: 首页>>代码示例>>Python>>正文


Python sortedcontainers.SortedList方法代码示例

本文整理汇总了Python中sortedcontainers.SortedList方法的典型用法代码示例。如果您正苦于以下问题:Python sortedcontainers.SortedList方法的具体用法?Python sortedcontainers.SortedList怎么用?Python sortedcontainers.SortedList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sortedcontainers的用法示例。


在下文中一共展示了sortedcontainers.SortedList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getOpcodeAddrs

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def _getOpcodeAddrs(self):
        # TODO: lazy load?
        addrs = SortedList()

        funcs = self.getFunctions()

        for f in funcs:
            print('addrs for', f['name'])
            ofs = f['offset']
            sz = f['size']
            end = ofs + sz

            self.seek(ofs)
            cur = ofs
            while cur < end:
                addrs.add(cur)

                self.cmd('so')
                cur = self.tell()

        return addrs 
开发者ID:sapir,项目名称:sonare,代码行数:23,代码来源:main.py

示例2: test_init

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_init():
    slt = SortedList()
    slt._check()

    slt = SortedList(load=10000)
    assert slt._load == 10000
    assert slt._twice == 20000
    assert slt._half == 5000
    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() 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:20,代码来源:test_coverage_sortedlist.py

示例3: test_add

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_add():
    random.seed(0)
    slt = SortedList()
    for val in range(1000):
        slt.add(val)
        slt._check()

    slt = SortedList()
    for val in range(1000, 0, -1):
        slt.add(val)
        slt._check()

    slt = SortedList()
    for val in range(1000):
        slt.add(random.random())
        slt._check() 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:18,代码来源:test_coverage_sortedlist.py

示例4: test_discard

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
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], load=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])) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:19,代码来源:test_coverage_sortedlist.py

示例5: test_islice

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_islice():
    sl = SortedList(load=7)

    assert [] == list(sl.islice())

    values = list(range(53))
    sl.update(values)

    for start in range(53):
        for stop in range(53):
            assert list(sl.islice(start, stop)) == values[start:stop]

    for start in range(53):
        for stop in range(53):
            assert list(sl.islice(start, stop, reverse=True)) == values[start:stop][::-1]

    for start in range(53):
        assert list(sl.islice(start=start)) == values[start:]
        assert list(sl.islice(start=start, reverse=True)) == values[start:][::-1]

    for stop in range(53):
        assert list(sl.islice(stop=stop)) == values[:stop]
        assert list(sl.islice(stop=stop, reverse=True)) == values[:stop][::-1] 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:25,代码来源:test_coverage_sortedlist.py

示例6: test_insert

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_insert():
    slt = SortedList(range(10), load=4)
    slt.insert(-1, 9)
    slt._check()
    slt.insert(-100, 0)
    slt._check()
    slt.insert(100, 10)
    slt._check()

    slt = SortedList(load=4)
    slt.insert(0, 5)
    slt._check()

    slt = SortedList(range(5, 15), load=4)
    for rpt in range(8):
        slt.insert(0, 4)
        slt._check()

    slt = SortedList(range(10), load=4)
    slt.insert(8, 8)
    slt._check() 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:23,代码来源:test_coverage_sortedlist.py

示例7: test_index

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_index():
    slt = SortedList(range(100), load=17)

    for val in range(100):
        assert val == slt.index(val)

    assert slt.index(99, 0, 1000) == 99

    slt = SortedList((0 for rpt in range(100)), load=17)

    for start in range(100):
        for stop in range(start, 100):
            assert slt.index(0, start, stop + 1) == start

    for start in range(100):
        assert slt.index(0, -(100 - start)) == start

    assert slt.index(0, -1000) == 0 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:20,代码来源:test_coverage_sortedlist.py

示例8: test_init

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_init():
    slt = SortedListWithKey(key=modulo)
    slt._check()

    slt = SortedListWithKey(load=10000, key=modulo)
    assert slt._load == 10000
    assert slt._twice == 20000
    assert slt._half == 5000
    slt._check()

    slt = SortedListWithKey(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, SortedListWithKey)

    slt._check() 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:24,代码来源:test_coverage_sortedlistwithkey_modulo.py

示例9: get_lowest_probable_prepared_certificate_in_view

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def get_lowest_probable_prepared_certificate_in_view(
            self, view_no) -> Optional[int]:
        """
        Return lowest pp_seq_no of the view for which can be prepared but
        choose from unprocessed PRE-PREPAREs and PREPAREs.
        """
        # TODO: Naive implementation, dont need to iterate over the complete
        # data structures, fix this later
        seq_no_pp = SortedList()  # pp_seq_no of PRE-PREPAREs
        # pp_seq_no of PREPAREs with count of PREPAREs for each
        seq_no_p = set()

        for (v, p) in self._ordering_service.prePreparesPendingPrevPP:
            if v == view_no:
                seq_no_pp.add(p)
            if v > view_no:
                break

        for (v, p), pr in self._ordering_service.preparesWaitingForPrePrepare.items():
            if v == view_no and len(pr) >= self.quorums.prepare.value:
                seq_no_p.add(p)

        for n in seq_no_pp:
            if n in seq_no_p:
                return n
        return None 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:28,代码来源:replica.py

示例10: l_get_lowest_probable_prepared_certificate_in_view

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def l_get_lowest_probable_prepared_certificate_in_view(
            self, view_no) -> Optional[int]:
        """
        Return lowest pp_seq_no of the view for which can be prepared but
        choose from unprocessed PRE-PREPAREs and PREPAREs.
        """
        # TODO: Naive implementation, dont need to iterate over the complete
        # data structures, fix this later
        seq_no_pp = SortedList()  # pp_seq_no of PRE-PREPAREs
        # pp_seq_no of PREPAREs with count of PREPAREs for each
        seq_no_p = set()

        for (v, p) in self.prePreparesPendingPrevPP:
            if v == view_no:
                seq_no_pp.add(p)
            if v > view_no:
                break

        for (v, p), pr in self.preparesWaitingForPrePrepare.items():
            if v == view_no and len(pr) >= self._data.quorums.prepare.value:
                seq_no_p.add(p)

        for n in seq_no_pp:
            if n in seq_no_p:
                return n
        return None 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:28,代码来源:ordering_service.py

示例11: stress_index2

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def stress_index2(slt):
    values = list(slt)[:3] * 200
    slt = SortedList(values)
    for idx, val in enumerate(slt):
        assert slt.index(val, idx) == idx 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:7,代码来源:test_stress_sortedlist.py

示例12: stress_lt

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def stress_lt(slt):
    values = list(slt)
    assert not (values < slt)
    values = SortedList(value - 1 for value in values)
    assert values < slt
    values = []
    assert values < slt
    assert not (slt < values) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:10,代码来源:test_stress_sortedlist.py

示例13: test_contains

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_contains():
    slt = SortedList()
    assert 0 not in slt

    slt.update(range(10000))

    for val in range(10000):
        assert val in slt

    assert 10000 not in slt

    slt._check() 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:14,代码来源:test_coverage_sortedlist.py

示例14: test_remove

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_remove():
    slt = SortedList()

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

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

    slt.remove(2)
    slt._check()

    assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5])) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:15,代码来源:test_coverage_sortedlist.py

示例15: test_remove_valueerror1

# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_remove_valueerror1():
    slt = SortedList()
    slt.remove(0) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:5,代码来源:test_coverage_sortedlist.py


注:本文中的sortedcontainers.SortedList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。