def _construct_index(self, table_name, index_name): ''' Construct a btree on a table and save. table_name -> table's name (needs to exist in database) index_name -> name of the created index ''' bt = Btree(3) # 3 is arbitrary # for each record in the primary key of the table, insert its value and index to the btree for idx, key in enumerate(self.tables[table_name].columns[self.tables[table_name].pk_idx]): bt.insert(key, idx) # save the btree self._save_index(index_name, bt)
def _construct_index(self, table_name, index_name): ''' Construct a btree on a table and save. Args: table_name: string. Table name (must be part of database). index_name: string. Name of the created index. ''' bt = Btree(3) # 3 is arbitrary # for each record in the primary key of the table, insert its value and index to the btree for idx, key in enumerate(self.tables[table_name].column_by_name(self.tables[table_name].pk)): bt.insert(key, idx) # save the btree self._save_index(index_name, bt)
print(f"Branching factor: {B}") insertcounter = 0 while len(lst) != NUM: new_v = randrange(100) if new_v not in lst: lst.append(new_v) insertcounter += 1 print(f"Inserted {insertcounter} items") bt = Btree(B) for ind, el in enumerate(lst): bt.insert(el, ind) delcounter = 0 listLength = len(lst) for i in range(len(lst)): delvalue = random.choice(lst) lst.remove(delvalue) bt.delete(delvalue) # if counter >= listLength/2: # break delcounter += 1 print(f"Deleted {delcounter} items") bt.plot()
print('format python3 main.py FILENAME') exit(0) filename = sys.argv[1] if not os.path.isfile(filename): print('"{}" file is not present'.format(filename)) exit(0) with open(filename, 'r') as fp: lines = fp.readlines() # create a Btree object btree = Btree() for line in lines: line = line.strip().split(' ') if line[0] == 'INSERT': val = float(line[1]) ret, new_key, new_node = btree.insert(btree.root, val) btree.change_root(ret, new_key, new_node) elif line[0] == 'FIND': val = float(line[1]) ret = btree.operate(btree.root, 'find', val, val) if ret == 0: print('NO') elif ret: print('YES') elif line[0] == 'COUNT': val = float(line[1]) ret = btree.operate(btree.root, 'count', val, val) print(ret)