// 从索引文件中读取数据,创建b+树 extern BPTree CreatBPTree(BPTree T) { int fd; int i = 0, ret = -1; unsignedlong file_len = -1; structstatstatbuff; KeyType temp = 0; KeyType *q; Record t_record = 0; Record *p;
q = &temp; p = &t_record;
file_len = get_file_size(INDEX_NAME);
if ((fd = open(INDEX_NAME, O_RDONLY)) == -1) { printf("Open index file failled!\n"); returnNULL; }
while (i < file_len) { if ((ret = pread(fd, q, 4, i)) == -1) { close(fd); returnNULL; } if ((ret = pread(fd, p, 4, i + 4)) == -1) { close(fd); returnNULL; } T = Insert(T, *q, *p); i = i + 8; } close(fd);