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


Python SortedList.index方法代码示例

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


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

示例1: test_index

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [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:sbagri,项目名称:sorted_containers,代码行数:20,代码来源:test_coverage_sortedlist.py

示例2: test_index_valueerror6

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror6():
    slt = SortedList(range(10), load=4)
    slt.index(3, 5)
开发者ID:sbagri,项目名称:sorted_containers,代码行数:5,代码来源:test_coverage_sortedlist.py

示例3: test_index_valueerror5

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

示例4: test_index_valueerror4

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror4():
    slt = SortedList([0] * 10, load=4)
    slt.index(1)
开发者ID:sbagri,项目名称:sorted_containers,代码行数:5,代码来源:test_coverage_sortedlist.py

示例5: test_index_valueerror2

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror2():
    slt = SortedList([0] * 10, load=4)
    slt.index(0, 0, -10)
开发者ID:sbagri,项目名称:sorted_containers,代码行数:5,代码来源:test_coverage_sortedlist.py

示例6: test_index_valueerror7

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror7():
    slt = SortedList([0] * 10 + [2] * 10, load=4)
    slt.index(1, 0, 10)
开发者ID:adamchainz,项目名称:sorted_containers,代码行数:5,代码来源:test_coverage_sortedlist.py

示例7: PriorityDict

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]

#.........这里部分代码省略.........
        Create a new dictionary with keys from `iterable` and values set to
        `value`. The default *value* is 0.
        """
        return PriorityDict((key, value) for key in iterable)

    def get(self, key, default=None):
        """
        Return the value for *key* if *key* is in the dictionary, else
        *default*.  If *default* is not given, it defaults to ``None``,
        so that this method never raises a KeyError.
        """
        return self._dict.get(key, default)

    def has_key(self, key):
        """Return True if and only in *key* is in the dictionary."""
        return key in self._dict

    def pop(self, key, default=_NotGiven):
        """
        If *key* is in the dictionary, remove it and return its value,
        else return *default*. If *default* is not given and *key* is not in
        the dictionary, a KeyError is raised.
        """
        if key in self._dict:
            value = self._dict[key]
            self._list.remove((value, key))
            return self._dict.pop(key)
        else:
            if default == _NotGiven:
                raise KeyError
            else:
                return default

    def popitem(self, index=-1):
        """
        Remove and return item at *index* (default: -1). Raises IndexError if
        dict is empty or index is out of range. Negative indices are supported
        as for slice indices.
        """
        value, key = self._list.pop(index)
        del self._dict[key]
        return key, value

    def setdefault(self, key, default=0):
        """
        If *key* is in the dictionary, return its value.  If not, insert *key*
        with a value of *default* and return *default*.  *default* defaults to
        ``0``.
        """
        if key in self._dict:
            return self._dict[key]
        else:
            self._dict[key] = default
            self._list.add((default, key))
            return default

    def elements(self):
        """
        Return an iterator over elements repeating each as many times as its
        count. Elements are returned in value sort-order. If an element’s count
        is less than one, elements() will ignore it.
        """
        values = (repeat(key, value) for value, key in self._list)
        return chain.from_iterable(values)

    def most_common(self, count=None):
开发者ID:arssivka,项目名称:naomech,代码行数:70,代码来源:prioritydict.py

示例8: test_index_valueerror7

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror7():
    slt = SortedList([0] * 10 + [2] * 10)
    slt._reset(4)
    with pytest.raises(ValueError):
        slt.index(1, 0, 10)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedlist.py

示例9: stress_index2

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [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:adamchainz,项目名称:sorted_containers,代码行数:7,代码来源:test_stress_sortedlist.py

示例10: test_index_valueerror6

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror6():
    slt = SortedList(range(10))
    slt._reset(4)
    with pytest.raises(ValueError):
        slt.index(3, 5)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedlist.py

示例11: test_index_valueerror5

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror5():
    slt = SortedList()
    with pytest.raises(ValueError):
        slt.index(1)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:6,代码来源:test_coverage_sortedlist.py

示例12: test_index_valueerror3

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def test_index_valueerror3():
    slt = SortedList([0] * 10)
    slt._reset(4)
    with pytest.raises(ValueError):
        slt.index(0, 7, 3)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedlist.py

示例13: prev_workspace_for_current_output_num

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
def prev_workspace_for_current_output_num():
    current_workspace, output_workspaces = workspaces_for_current_output()
    sorted_workspaces = SortedList(
        workspace["num"] for workspace in output_workspaces)
    current_num = sorted_workspaces.index(current_workspace["num"])
    return sorted_workspaces[(current_num - 1) % len(sorted_workspaces)]
开发者ID:rahulsalvi,项目名称:dotfiles,代码行数:8,代码来源:i3utils.py

示例14: SweepLine

# 需要导入模块: from sortedcontainers import SortedList [as 别名]
# 或者: from sortedcontainers.SortedList import index [as 别名]
class SweepLine(object):
	'''
	This class represents the vertical sweep line which sweeps over 
	the set of segments in the Bentley-Ottmann algorithm.

	At any moment, it contains a sorted list of all the 
	ComparableSegments which intersect with the sweep line in its 
	current position.

	Note that if 2 segments s1 and s2 are overlapping, you cannot 
	assume anything about their order in the sorted queue, as 
	s1 < s2 and s1 > s2 are both false

	Such sorted list would usually rely on a balanced binary search 
	tree data structure in order to have O(log(N)) insertion, 
	deletion and swapping.

	Instead, I chose to use a SortedList of Grant Jenks' SortedContainers 
	module, which has several advantages that you can discover by browsing
	its page. It allows O(log(N)) insertion, deletion and swapping, and I
	find it to be faster in practice.
	'''

	def __init__(self):
		'''
		Initializes an empty sweep line.
		'''
		self.l = SortedList()

	def isEmpty(self):
		'''
		Returns true if and only if the sweep line is empty.
		'''
		return len(self.l) == 0

	def addSegment(self, seg):
		'''
		Adds seg to the sweep line.
		'''
		ComparableSegment.currentX = seg.x1 
		self.l.add(seg)

	def removeSegment(self, seg):
		'''
		Removes seg from the sweep line.
		'''
		self.l.remove(seg)

	def belowSegments(self, seg):
		'''
		Returns a list containing :
		- The highest segment s_below contained in the sweep line 
		such as s_below.isBelow(seg)
		- All the segments s contained before s_below in the sweep 
		line but such as s.isBelow(s_below) is false, (i.e. which have the 
		same y-coordinate at ComparableSegment.currentX and gradient).
		'''
		res = []
		# i = index of seg
		i = self.l.index(seg)
		# Passes segments which have same y-coordinate and gradient
		# to find s_below
		while i-1 >= 0:
			prev = self.l[i-1]
			i -= 1
			if prev.isBelow(seg):
				res.append(prev)
				break
		# Appends all the segments which have same y-coordinate and 
		# gradient as s_below
		while i-1 >= 0:
			prev = self.l[i-1]
			if prev.isBelow(res[0]):
				break
			res.append(prev)
			i -= 1
		return res

	def aboveSegments(self, seg):
		'''
		Returns a list containing :
		- The lowest segment s_above contained in the sweep line 
		such as seg < s_above
		- All the segments s contained after s_above in the sweep 
		line but such as s_below < s is false, (i.e. which have the 
		same y-coordinate at ComparableSegment.currentX and gradient).
		'''
		res = []
		# i = index of seg
		i = self.l.index(seg)
		# Passes segments which have same y-coordinate and gradient
		# to find s_above
		while i+1 < len(self.l):
			succ = self.l[i+1]
			i += 1
			if seg.isBelow(succ):
				res.append(succ)
				break
		# Appends all the segments which have same y-coordinate and 
		# gradient as s_above
#.........这里部分代码省略.........
开发者ID:ethiery,项目名称:BentleyOttman,代码行数:103,代码来源:SweepLine.py


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