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


Python bisect.bisect_left方法代码示例

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


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

示例1: intranges_contain

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def intranges_contain(int_, ranges):
    """Determine if `int_` falls into one of the ranges in `ranges`."""
    tuple_ = _encode_range(int_, 0)
    pos = bisect.bisect_left(ranges, tuple_)
    # we could be immediately ahead of a tuple (start, end)
    # with start < int_ <= end
    if pos > 0:
        left, right = _decode_range(ranges[pos-1])
        if left <= int_ < right:
            return True
    # or we could be immediately behind a tuple (int_, end)
    if pos < len(ranges):
        left, _ = _decode_range(ranges[pos])
        if left == int_:
            return True
    return False 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:18,代码来源:intranges.py

示例2: contains

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def contains(self, *args):
        if len(args) == 1 and isinstance(args[0], Cell):
            return self.contains(args[0].id())
        elif len(args) == 1 and isinstance(args[0], CellId):
            cell_id = args[0]
            index = bisect.bisect_left(self.__cell_ids, cell_id)
            if index < len(self.__cell_ids) \
                    and self.__cell_ids[index].range_min() <= cell_id:
                return True
            return index != 0 \
                    and self.__cell_ids[index - 1].range_max() >= cell_id
        elif len(args) == 1 and isinstance(args[0], Point):
            return self.contains(CellId.from_point(args[0]))
        elif len(args) == 1 and isinstance(args[0], self.__class__):
            cell_union = args[0]
            for i in xrange(cell_union.num_cells()):
                if not self.contains(cell_union.cell_id(i)):
                    return False
            return True
        else:
            raise NotImplementedError() 
开发者ID:qedus,项目名称:sphere,代码行数:23,代码来源:sphere.py

示例3: intersects

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def intersects(self, *args):
        if len(args) == 1 and isinstance(args[0], CellId):
            cell_id = args[0]
            index = bisect.bisect_left(self.__cell_ids, cell_id)
            if index != len(self.__cell_ids) \
                and self.__cell_ids[index].range_min() <= cell_id.range_max():
                return True
            return index != 0 \
                and self.__cell_ids[index - 1].range_max() \
                                                    >= cell_id.range_min()
        elif len(args) == 1 and isinstance(args[0], CellUnion):
            cell_union = args[0]
            for cell_id in cell_union.__cell_ids:
                if self.intersects(cell_id):
                    return True
            return False
        else:
            raise NotImplementedError() 
开发者ID:qedus,项目名称:sphere,代码行数:20,代码来源:sphere.py

示例4: bisect_left

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def bisect_left(self, value):
        """Return an index to insert `value` in the sorted-key list.

        If the `value` is already present, the insertion point will be before
        (to the left of) any existing values.

        Similar to the `bisect` module in the standard library.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> from operator import neg
        >>> skl = SortedKeyList([5, 4, 3, 2, 1], key=neg)
        >>> skl.bisect_left(1)
        4

        :param value: insertion index of value in sorted-key list
        :return: index

        """
        return self._bisect_key_left(self._key(value)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:sortedlist.py

示例5: bisect_right

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def bisect_right(self, value):
        """Return an index to insert `value` in the sorted-key list.

        Similar to `bisect_left`, but if `value` is already present, the
        insertion point with be after (to the right of) any existing values.

        Similar to the `bisect` module in the standard library.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> from operator import neg
        >>> skl = SortedList([5, 4, 3, 2, 1], key=neg)
        >>> skl.bisect_right(1)
        5

        :param value: insertion index of value in sorted-key list
        :return: index

        """
        return self._bisect_key_right(self._key(value)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:sortedlist.py

示例6: find_longest_prefix

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def find_longest_prefix(self, target, sep):
    """Identifies a known resource path which would contain the `target` path.

    sep must be the current path separator (can vary from os.path.sep when
    running under simulation).

    Returns (str(Path), Path) if the prefix path is found, or (None, None) if no
    such prefix exists.
    """
    idx = bisect.bisect_left(self.path_strings, target)
    if idx == len(self.paths):
      return (None, None) # off the end

    sPath, path = self.path_strings[idx], self.paths[idx]
    if target == sPath :
      return sPath, path

    if idx > 0:
      sPath, path = self.path_strings[idx-1], self.paths[idx-1]
      if target.startswith(sPath+sep):
        return sPath, path

    return (None, None) 
开发者ID:luci,项目名称:recipes-py,代码行数:25,代码来源:recipe_api.py

示例7: binary_search

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def binary_search(ls, x, sort=False):
    """二分查找算法

    >>> s = [1, 2, 3, 4, 5, 6, 10, 7]
    >>> print(binary_search(s, 7, True))

    :param ls: 列表。
    :param x: 被查找的数。
    :param sort: 是否要启动排序,False表示不启动排序,默认是不启动。
    :return: 找到返回True,反之亦然
    """
    if sort:
        ls = sorted(ls)
    v = bisect.bisect_left(ls, x)
    if v != len(ls) and ls[v] == x:
        return True
    return False 
开发者ID:jtyoui,项目名称:Jtyoui,代码行数:19,代码来源:SearchAlgorithm.py

示例8: keys

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def keys(self, prefix=None):
        if prefix is None or prefix == "" or not self._keys:
            return set(self._keys)

        if prefix.startswith(self._cachestr):
            lo, hi = self._cachepoints
            start = i = bisect_left(self._keys, prefix, lo, hi)
        else:
            start = i = bisect_left(self._keys, prefix)

        keys = set()
        if start == len(self._keys):
            return keys

        while self._keys[i].startswith(prefix):
            keys.add(self._keys[i])
            i += 1

        self._cachestr = prefix
        self._cachepoints = (start, i)

        return keys 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:py.py

示例9: seek

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def seek(self, key):
        self._idx = bisect.bisect_left(self._data, (key, "")) 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:4,代码来源:leveldb.py

示例10: put

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def put(self, key, val, **_kwargs):
        if self._is_snapshot:
            raise TypeError("cannot put on leveldb snapshot")
        assert isinstance(key, str)
        assert isinstance(val, str)
        with self._lock:
            idx = bisect.bisect_left(self._data, (key, ""))
            if 0 <= idx < len(self._data) and self._data[idx][0] == key:
                self._data[idx] = (key, val)
            else:
                self._data.insert(idx, (key, val)) 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:13,代码来源:leveldb.py

示例11: delete

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def delete(self, key, **_kwargs):
        if self._is_snapshot:
            raise TypeError("cannot delete on leveldb snapshot")
        with self._lock:
            idx = bisect.bisect_left(self._data, (key, ""))
            if 0 <= idx < len(self._data) and self._data[idx][0] == key:
                del self._data[idx] 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:9,代码来源:leveldb.py

示例12: get

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def get(self, key, **_kwargs):
        with self._lock:
            idx = bisect.bisect_left(self._data, (key, ""))
            if 0 <= idx < len(self._data) and self._data[idx][0] == key:
                return self._data[idx][1]
            return None

    # pylint: disable=W0212 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:10,代码来源:leveldb.py

示例13: get_item

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def get_item(self, i, d=None):
        """Finds out how many repeats this index implies, then picks strings."""
        if i < self.offset_break:
            by_bisect = bisect.bisect_left(self.offsets, (i, -1), hi=self.index_of_offset)
        else:
            by_bisect = bisect.bisect_left(self.offsets, (i, -1), lo=self.index_of_offset)

        if by_bisect == len(self.offsets) or self.offsets[by_bisect][0] > i:
            by_bisect -= 1

        num = i - self.offsets[by_bisect][0]
        count = self.offsets[by_bisect][1]

        if count > 100 and self.content_length < 1000:
            content = list(self.content)
        else:
            content = self.content

        result = []

        if count == 0:
            return ''

        for modulus in fastdivmod.divmod_iter(num, self.content_length):
            result.append(content[modulus])

        leftover = count - len(result)
        if leftover:
            assert leftover > 0
            result.extend([content[0]] * leftover)

        # smallest place value ends up on the right
        return ''.join(result[::-1]) 
开发者ID:girishramnani,项目名称:hacking-tools,代码行数:35,代码来源:__init__.py

示例14: _update_tag_positions

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def _update_tag_positions(self, rule):
        """
        Update _tag_positions to reflect the changes to tags that are
        made by *rule*.
        """
        # Update the tag index.
        for pos in self._positions_by_rule[rule]:
            # Delete the old tag.
            old_tag_positions = self._tag_positions[rule.original_tag]
            old_index = bisect.bisect_left(old_tag_positions, pos)
            del old_tag_positions[old_index]
            # Insert the new tag.
            new_tag_positions = self._tag_positions[rule.replacement_tag]
            bisect.insort_left(new_tag_positions, pos) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:16,代码来源:brill_trainer.py

示例15: uts46_remap

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_left [as 别名]
def uts46_remap(domain, std3_rules=True, transitional=False):
    """Re-map the characters in the string according to UTS46 processing."""
    from .uts46data import uts46data
    output = u""
    try:
        for pos, char in enumerate(domain):
            code_point = ord(char)
            uts46row = uts46data[code_point if code_point < 256 else
                bisect.bisect_left(uts46data, (code_point, "Z")) - 1]
            status = uts46row[1]
            replacement = uts46row[2] if len(uts46row) == 3 else None
            if (status == "V" or
                    (status == "D" and not transitional) or
                    (status == "3" and not std3_rules and replacement is None)):
                output += char
            elif replacement is not None and (status == "M" or
                    (status == "3" and not std3_rules) or
                    (status == "D" and transitional)):
                output += replacement
            elif status != "I":
                raise IndexError()
        return unicodedata.normalize("NFC", output)
    except IndexError:
        raise InvalidCodepoint(
            "Codepoint {0} not allowed at position {1} in {2}".format(
            _unot(code_point), pos + 1, repr(domain))) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:28,代码来源:core.py


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