You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
11 months ago
|
import random
|
||
|
BLOCK_NUM = 7
|
||
|
LAST_BLOCK = "FF"
|
||
|
FIRST_BLOCK = 8 # 第一块fat位置
|
||
|
|
||
|
|
||
|
def generate_chain_structure():
|
||
|
sim_fat = ["0"] * BLOCK_NUM # 文件块的大小
|
||
|
used_blocks = {"00", FIRST_BLOCK} # 用于存储已经被占用的块位置,且预置00块和第一块为已占用状态
|
||
|
|
||
|
for i in range(len(sim_fat) - 1):
|
||
|
while True:
|
||
|
location = random.randint(0, 99)
|
||
|
if location not in used_blocks: # 防止已经被占用的快被重新占用
|
||
|
sim_fat[i] = location
|
||
|
used_blocks.add(location) # 添加到已占用块集合
|
||
|
break
|
||
|
|
||
|
sim_fat[-1] = LAST_BLOCK
|
||
|
chain_structure = [] # 链结构
|
||
|
for i, value in enumerate(sim_fat):
|
||
|
if i == 0:
|
||
|
print(f"SimFAT[{FIRST_BLOCK}] -> {value}")
|
||
|
item = {FIRST_BLOCK: value} # 构建链结构
|
||
|
else:
|
||
|
print(f"SimFAT[{sim_fat[i - 1]}] -> {value}")
|
||
|
item = {sim_fat[i - 1]: value} # 构建链结构
|
||
|
chain_structure.append(item) #
|
||
|
return chain_structure
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print(generate_chain_structure())
|