• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sortedcontainers.SortedSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_delitem_slice

def test_delitem_slice():
    vals = list(range(100))
    temp = SortedSet(vals)
    temp._reset(7)
    del vals[20:40:2]
    del temp[20:40:2]
    assert temp == set(vals)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例2: test_union

def test_union():
    temp = SortedSet(range(0, 50), load=7)
    that = SortedSet(range(50, 100), load=9)
    result = temp.union(that)
    assert all(result[val] == val for val in range(100))
    assert all(temp[val] == val for val in range(50))
    assert all(that[val] == (val + 50) for val in range(50))
开发者ID:Muon,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例3: test_copy

def test_copy():
    temp = SortedSet(range(100))
    temp._reset(7)
    that = temp.copy()
    that.add(1000)
    assert len(temp) == 100
    assert len(that) == 101
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例4: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """

    pagenames = SortedSet()
    for link in BeautifulSoup(html, "html.parser", parse_only=SoupStrainer('a')):
        if link.has_attr('href'):
            name = link['href'].split('/')[-1]
            if name in names:
                pagenames.add(name)
    return pagenames
开发者ID:setr,项目名称:cs429,代码行数:25,代码来源:pagerank.py


示例5: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    soup = BeautifulSoup(html,"html.parser")
    list = [l['href'] for l in soup.find_all('a') if l.get('href')]
    res = SortedSet()
    for l in list:
        if l.startswith('/wiki/'):
            tokens = l.split('/')
            if tokens[2] in names:
                res.add(tokens[2])
    
    return res
开发者ID:deulgaonkaranup,项目名称:WebSearchEngine-API,代码行数:27,代码来源:pagerank.py


示例6: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    ###TODO
    found = SortedSet()
    bs = BeautifulSoup(html, "html.parser")
    for link in bs.find_all('a'):
        if link.get('href'):
            href = link.get('href')
            nl = re.split('|'.join(['/', '=', '&', ':', '/d+_']), href)
            cleared_nl = [n for n in nl if n != '']
            found = found.union([name for name in names if name in cleared_nl])
    return found
    pass
开发者ID:mickokenter,项目名称:flyingmatt,代码行数:28,代码来源:pagerank.py


示例7: __init__

 def __init__(self, root_path):
     self.code_graph = nx.MultiDiGraph()
     self.metrics = {}
     self.root_path = Path(root_path)
     self.root_arch_ids = []
     self.entity_kinds = SortedSet()
     self.ref_kinds = SortedSet()
开发者ID:ashapochka,项目名称:saapy,代码行数:7,代码来源:scitools_client.py


示例8: test_eq

def test_eq():
    alpha = SortedSet(range(100), load=7)
    beta = SortedSet(range(100), load=17)
    assert alpha == beta
    assert alpha == beta._set
    beta.add(101)
    assert not (alpha == beta)
开发者ID:gzgujs,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例9: test_ne

def test_ne():
    alpha = SortedSet(range(100), load=7)
    beta = SortedSet(range(99), load=17)
    assert alpha != beta
    beta.add(100)
    assert alpha != beta
    assert alpha != beta._set
开发者ID:gzgujs,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例10: test_delitem_key

def test_delitem_key():
    temp = SortedSet(range(100), key=modulo)
    temp._reset(7)
    values = sorted(range(100), key=modulo)
    for val in range(10):
        del temp[val]
        del values[val]
    assert list(temp) == list(values)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py


示例11: test_symmetric_difference

def test_symmetric_difference():
    temp = SortedSet(range(0, 75), load=7)
    that = SortedSet(range(25, 100), load=9)
    result = temp.symmetric_difference(that)
    assert all(result[val] == val for val in range(25))
    assert all(result[val + 25] == (val + 75) for val in range(25))
    assert all(temp[val] == val for val in range(75))
    assert all(that[val] == (val + 25) for val in range(75))
开发者ID:Muon,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py


示例12: test_pickle

def test_pickle():
    import pickle
    alpha = SortedSet(range(10000), key=negate)
    alpha._reset(500)
    data = pickle.dumps(alpha)
    beta = pickle.loads(data)
    assert alpha == beta
    assert alpha._key == beta._key
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py


示例13: test_copy_copy

def test_copy_copy():
    import copy
    temp = SortedSet(range(100))
    temp._reset(7)
    that = copy.copy(temp)
    that.add(1000)
    assert len(temp) == 100
    assert len(that) == 101
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py


示例14: DictGraph

class DictGraph(Graph):
    """Graph that supports nonconsecutive vertex ids."""

    def __init__(self, nodes: Set[int]=None, r: int=1) -> None:
        """Make a new graph."""
        if nodes is None:
            self.nodes = SortedSet()  # type: Set[int]
        else:
            self.nodes = nodes
        self.radius = r
        self.inarcs_by_weight = [defaultdict(SortedSet) for _ in range(self.radius)]

    def __len__(self):
        """len() support."""
        return len(self.nodes)

    def __iter__(self):
        """Iteration support."""
        return iter(self.nodes)

    def __contains__(self, v):
        """Support for `if v in graph`."""
        return v in self.nodes

    def add_node(self, u: int):
        """Add a new node."""
        self.nodes.add(u)

    def arcs(self, weight: int=None):
        """
        Return all the arcs in the graph.

        restrict to a given weight when provided
        """
        if weight:
            return [(x, y) for x in self.nodes
                    for y in self.inarcs_by_weight[weight-1][x]]
        else:
            return [(x, y, w+1) for w, arc_list in
                    enumerate(self.inarcs_by_weight)
                    for x in self.nodes
                    for y in arc_list[x]]

    def remove_isolates(self) -> List[int]:
        """
        Remove all isolated vertices and return a list of vertices removed.

        Precondition:  the graph is bidirectional
        """
        isolates = [v for v in self if self.in_degree(v, 1) == 0]
        for v in isolates:
            self.nodes.remove(v)
            for N in self.inarcs_by_weight:
                if v in N:
                    del N[v]
        return isolates
开发者ID:spacegraphcats,项目名称:spacegraphcats,代码行数:56,代码来源:graph.py


示例15: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    ###TODO
    #remove BeautifulSoap - later


    listofHrefs = []
    listofHrefTexts = []
    FinalSortedSet = SortedSet()
    splice_char = '/'
    #getting all the tags using the BeautifulSoup
    #soup = BeautifulSoup(html, "html.parser") 
    #fectching all the links in anchor tags
    #for link in soup.find_all('a'):
        #listofHrefs.append(link.get('href'))
    for i in range(0,len(listofHrefs)):
        value = listofHrefs[i][6:]
        listofHrefTexts.append(value)
    listofHrefTexts = re.findall(r'href="([^"]*)', html)
    #print(listofHrefTexts)
    for i in listofHrefTexts:
        #print(i)
        value = i[6:]
        listofHrefs.append(value)
    #print(listofHrefs)
    listofHrefs = list(set(listofHrefs))
    #print(len(listofHrefs))
    for href in listofHrefs:
        for name in names:
            #windows OS handling
            if(name == "Guy_L._Steele,_Jr"):
                names.remove(name)
                names.add("Guy_L._Steele,_Jr.")
            if(href == name):
                FinalSortedSet.add(name)
            
    
    return FinalSortedSet
    
    pass
开发者ID:BrindaRao,项目名称:IR_Assignments,代码行数:55,代码来源:pagerank.py


示例16: test_add

def test_add():
    temp = SortedSet(range(100))
    temp._reset(7)
    temp.add(100)
    temp.add(90)
    temp._check()
    assert all(val == temp[val] for val in range(101))
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py


示例17: compute_domset

def compute_domset(graph: Graph, radius: int):
    """
    Compute a d-dominating set using Dvorak's approximation algorithm
    for dtf-graphs (see `Structural Sparseness and Complex Networks').
    Graph needs a distance-d dtf augmentation (see rdomset() for usage).
    """
    domset = SortedSet()
    infinity = float('inf')
    # minimum distance to a dominating vertex, obviously infinite at start
    domdistance = defaultdict(lambda: infinity)  # type: Dict[int, float]
    # counter that keeps track of how many neighbors have made it into the
    # domset
    domcounter = defaultdict(int)  # type: Dict[int, int]
    # cutoff for how many times a vertex needs to have its neighbors added to
    # the domset before it does.  We choose radius^2 as a convenient "large"
    # number
    c = (2*radius)**2

    # Sort the vertices by indegree so we take fewer vertices
    order = sorted([v for v in graph], key=lambda x: graph.in_degree(x),
                   reverse=True)
    # vprops = [(v,graph.in_degree(v)) for v in nodes]
    # vprops.sort(key=itemgetter(1),reverse=False)
    # order = map(itemgetter(0),vprops)

    for v in order:
        # look at the in neighbors to update the distance
        for r in range(1, radius + 1):
            for u in graph.in_neighbors(v, r):
                domdistance[v] = min(domdistance[v], r+domdistance[u])

        # if v is already dominated at radius, no need to work
        if domdistance[v] <= radius:
            continue

        # if v is not dominated at radius, put v in the dominating set
        domset.add(v)
        domdistance[v] = 0

        # update distances of neighbors of v if v is closer if u has had too
        # many of its neighbors taken into the domset, include it too.
        for r in range(1, graph.radius + 1):
            for u in graph.in_neighbors(v, r):
                domcounter[u] += 1
                domdistance[u] = min(domdistance[u], r)
                if domcounter[u] > c and u not in domset:
                    # add u to domset
                    domset.add(u)
                    domdistance[u] = 0
                    for x, rx in graph.in_neighbors(u):
                        domdistance[x] = min(domdistance[x], rx)
                # only need to update domdistance if u didn't get added

    return domset
开发者ID:spacegraphcats,项目名称:spacegraphcats,代码行数:54,代码来源:rdomset.py


示例18: __init__

    def __init__(self, software_system, logical_name, size):
        """
        Constructs a new feature specification, initially with no corresponding chunks in the system.
        """
        self._logical_name = logical_name

        self.software_system = software_system
        self.size = size

        self.chunks = SortedSet(key=lambda c: c.logical_name)
        self.tests = SortedSet(key=lambda t: t.logical_name)
开发者ID:twsswt,项目名称:softdev-workflow,代码行数:11,代码来源:feature.py


示例19: __init__

    def __init__(self, logical_name, feature, local_content=None):
        self.logical_name = logical_name

        self.feature = feature

        self.local_content = local_content

        self.dependencies = SortedSet(key=lambda d: d.fully_qualified_name)
        self.bugs = SortedSet(key=lambda b: b.logical_name)

        self.bug_count = 0
开发者ID:twsswt,项目名称:softdev-workflow,代码行数:11,代码来源:chunk.py


示例20: test_discard

def test_discard():
    temp = SortedSet(range(100), load=7)
    temp.discard(0)
    temp.discard(99)
    temp.discard(50)
    temp.discard(1000)
    temp._check()
    assert len(temp) == 97
开发者ID:Muon,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sortedsets.set函数代码示例发布时间:2022-05-27
下一篇:
Python sortedcontainers.SortedListWithKey类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap