Exemple #1
0
    blk_number_ = write_data(write_data_, int(ceil(len(write_data_) / 5.0)), 5,
                             blk_number_)
    return blk_number_


if __name__ == '__main__':
    blk_number = 0  # 磁盘文件号
    blk_numbers_of_R = 6  # 关系R的磁盘块数
    blk_numbers_of_S = 4  # 关系S的磁盘块数
    blk_dict = {}  # 用于记录关系和关系存放的第一个文件块的编号

    # 创建缓冲区
    # 元组为8个字节,所以我就设计块大小为8个元组,缓冲区大小为64个元组
    # 题目要求的520 = 512 + 8 ,8是每个缓冲区有一个标志位,我的缓冲区中不需要为它预留位置
    buffer_ = extmem.Buffer(64, 8)  # bufsize = 64, blksize = 8

    # 首先产生数据
    r = []
    s = []
    generate_data(r, s)

    # 将r写入到磁盘中
    # blk_dict['R'] = 0
    print '关系R'
    blk_dict['R'] = blk_number
    blk_number = write_relation(r, blk_numbers_of_R, blk_number)

    # 将s写入到磁盘中
    # blk_dict['S'] = 16
    print '关系S'
Exemple #2
0
                    print(a, b, d)
                    cnt += 4
                    if cnt % 12 == 0:
                        buffer.writeBlockToDisk("hash_join_result" + str((cnt - 1) // 12), k)
                        k = buffer.getNewBlockInBuffer()
                buffer.freeBlockInBuffer(n)
            buffer.freeBlockInBuffer(m)
    # 保存最后一块
    if cnt % 12 != 0:
        buffer.writeBlockToDisk("hash_join_result" + str((cnt - 1) // 12), k)
    buffer.freeBlockInBuffer(k)


if __name__ == '__main__':
    # 构造buffer
    buffer = extmem.Buffer(520, 64)

    # 构造数据
    R, S = generator()
    WriteRtoDisk(buffer, R)
    WriteStoDisk(buffer, S)

    # 线性查询
    liner_select(buffer)

    # 二分查询
    binary_selection(buffer)

    # 投影
    project(buffer, "R", "A")
Exemple #3
0
        blk_number = JoinOperationAlgorithm.hash_join('R', 'S', 5, 16, ui)


def savetofile():
    with open('result.txt', 'w') as file_handle:  # .txt可以不自己新建,代码会自动新建
        file_handle.write(ui.res.toPlainText())  # 写入
        file_handle.write('\n')  # 有时放在循环里面需要自动转行,不然会覆盖上一条数据


if __name__ == '__main__':
    blk_number = 0  # 磁盘文件号
    blk_numbers_of_R = 16  # 关系R的磁盘块数
    blk_numbers_of_S = 32  # 关系S的磁盘块数
    blk_dict = {}  # 用于记录关系和关系存放的第一个文件块的编号

    buffer = extmem.Buffer(64, 8)  #块大小

    # 首先产生数据
    r = []
    s = []
    generate_data(r, s)

    # 将r写入到磁盘中
    # blk_dict['R'] = 0
    print('关系R写入磁盘')
    blk_dict['R'] = blk_number
    blk_number = write_relation(r, blk_numbers_of_R, blk_number)
    print('关系S写入磁盘')
    blk_dict['S'] = blk_number
    # print(blk_number)
    blk_number = write_relation(s, blk_numbers_of_S, blk_number)
Exemple #4
0
        if len(data) == 0:
            print("没有对应的数据")
            return blk_number

        blk_number = write_data(data, int(ceil(len(data) / 7.0)), 7, blk_number)

        return blk_number


if __name__ == '__main__':
    blk_number = 0  # 磁盘文件号
    blk_numbers_of_R = 16  # 关系R的磁盘块数
    blk_numbers_of_S = 32  # 关系S的磁盘块数
    blk_dict = {}  # 用于记录关系和关系存放的第一个文件块的编号

    buffer = extmem.Buffer(512, 65)

    # 首先产生数据
    r = []
    s = []
    generate_data(r, s)

    # 将r写入到磁盘中
    # blk_dict['R'] = 0
    print('关系R: ',  blk_number)
    blk_dict['R'] = blk_number
    blk_number = write_relation(r, blk_numbers_of_R, blk_number)
    # print('START: ', blk_dict['R'])

    # 将s写入到磁盘中
    # blk_dict['S'] = 16