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


Python FastRBTree.pop_max方法代码示例

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


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

示例1: range

# 需要导入模块: from bintrees import FastRBTree [as 别名]
# 或者: from bintrees.FastRBTree import pop_max [as 别名]
    for x in range(0, 3000):
        alert = []
        for y in range(0, 6):
            alert.append(repr(randint(0, 8 - 1)) + "test")
        for c in hcombinations:
            label = []
            key = alert[:]
            for x in range(2):
                key[c[x]] = "*"
                label.append(alert[c[x]])

            hyperkey = tuple(key)
            hlabel = tuple(label)
            if hyperkey in hyper_dict:
                hyper_dict[hyperkey].nalerts += 1
                result = hyper_dict[hyperkey].get_alert(hlabel)
                if result is not None:
                    hyper_dict[hyperkey].insert_alert(hlabel, result + 1)
                else:
                    hyper_dict[hyperkey].insert_alert(hlabel, 1)
            else:
                hyper_dict[hyperkey] = Hyperedge(key, c, hlabel)

    for hyperedge in hyper_dict.values():
        hypersize_list.insert((hyperedge.nalerts, hyperedge.hyperkey), hyperedge)

    while not hypersize_list.is_empty():
        (key, hyperedge) = hypersize_list.pop_max()
        hyperedge.foreach_alert(treeloop)
    print("Completed iteration %d of 10" % z)
开发者ID:doctorpangloss,项目名称:bintrees,代码行数:32,代码来源:007_FastRBTree_error2.py

示例2: MINPolicy

# 需要导入模块: from bintrees import FastRBTree [as 别名]
# 或者: from bintrees.FastRBTree import pop_max [as 别名]
class MINPolicy(object):
    def __init__(self, cache_size_limit, trace, csv_suffix=".csv"):
        self.cache_size_limit = cache_size_limit
        self.cache = {}
        self.hits = 0.0
        self.requests = 0.0
        self.ts_order = ['row', 'hit']
        self.ts_datapoint = {key: None for key in self.ts_order}
        self.ts_datapoint['row'] = 0
        self.ts_file = open("csv/min" + csv_suffix, "w")
        self.ts_writer = csv.writer(self.ts_file)
        self.ts_writer.writerow(self.ts_order)

        self.clairvoyance = FastRBTree()

        self.precog = FastRBTree()
        last_time = time.time()
        for i, page_opcode in enumerate(trace):
            if time.time() > last_time + 0.1:
                last_time = time.time()
                print '1', i, '\r',
            sys.stdout.flush()
            page, _ = page_opcode
            try:
                self.precog[page].append(i)
            except KeyError:
                self.precog[page] = collections.deque()
                self.precog[page].append(i)

            known_max = i
        known_max += 2
        for times in self.precog.values():
            times.append(known_max)
            known_max += 1
        print
        print 'Done loading.'

    def hit_rate(self):
        return self.hits / self.requests

    def request(self, page):
        self.requests += 1
        if page in self.cache:
            was_hit = True
            self.hits += 1
        else:
            was_hit = False

        self.cache[page] = self.precog[page].popleft()
        # This happens on startup.
        if self.cache[page] < self.requests:
            self.cache[page] = self.precog[page].popleft()
        self.clairvoyance[self.cache[page]] = page
        self.ts_datapoint['row'] += 1

        if was_hit:
            self.ts_datapoint['hit'] = 1
        else:
            self.ts_datapoint['hit'] = 0

        self.ts_writer.writerow(
                [self.ts_datapoint[key] for key in self.ts_order])
        self.ts_file.flush()

        if len(self.cache) > self.cache_size_limit:
            next_use, page = self.clairvoyance.pop_max()
            del self.cache[page]
开发者ID:LoganEvans,项目名称:MMC,代码行数:69,代码来源:min_policy.py


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