當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。