找到16G数据中最大的五个

#
# -*- coding: utf-8 -*-
" 10 t simulation "
__author__ = "chaos"
import numpy as np


class Find5max(object):
    def __init__(self):
        self.data = [float(0), float(0), float(0), float(0), float(0)]

    def sort_data(self):
        return self.data.sort(reverse=True)

    def number5max(self):
        return self.data[-1]


def data_gen(num, k=1):
    """ generate data file """
    index = 0
    with open(r"E:\data.txt", 'w') as f:
        while 1:
            if index >= int(2**31):
                break
            x = np.random.uniform(0, 1, size=(num, k))
            #  f.writelines(str(x[0][0])+'\n')
            f.write(str(x[0][0]) + '\n')
            index += 1
if __name__ == "__main__":
    data_gen(int(1))
    solution = Find5max()
    with open(r"E:\data.txt") as f:
        while 1:
            line = f.readline()
            if not line:
                print(solution.data)
                break
            line_float = float(line)
            for index, value in enumerate(solution.data):
                if line_float >= value:
                    solution.data.insert(index, line_float)
                    solution.data.pop()
                    break
            solution.sort_data()



你可能感兴趣的:(找到16G数据中最大的五个)