I'm writing an octree type thing in Python, and currently all it's able to store is an ID. However, I'd like to change it so it can store any number of things, and I'm not sure which way would be better taking into account this could be for thousands of values.
Would storing it as a normal list be fine, and hard code in the indexes as you add things to the code, or would it be better to store as a dictionary so it's easier to get the values you want?
=[ID, stuff1, stuff2...]
={'ID': num, 'stuff1': something, 'stuff2': something}
If you want the ID with the first way, you use voxel_info[0]
, but then as you add more values it may get more complicated, such as owner = voxel_info[4]; importantText = voxel_info[5]
(where you have to remember which index relates to what at all points in the code), or with the dictionary way, it'd be a lot easier to get the values if more things were added.
The dictionary way seems more usable, but it also seems like it'd slow the code down and use more memory as it's storing text keys for thousands of dictionaries. Which way would you probably recommend?
For an idea of how the data is stored, it's like this. Items will be grouped if all of the block info is the same, so you get the different depths. The BLOCKINFO
part is where the info is stored, which is what I'm asking about being a list or dictionary.
OctreeData={ Depth: 2
Nodes: (1,1,1): {Depth:1
Nodes: (1,1,1): BLOCKINFO
(1,1,-1): {Depth: 0
Nodes: (1,1,1): BLOCKINFO
(1,1,-1): BLOCKINFO
(1,-1,-1): BLOCKINFO
etc
(1,-1,-1): BLOCKINFO
(-1,-1,-1): BLOCKINFO
(-1,-1,1): {Depth: 0
Nodes: etc
etc
(1,1,-1): BLOCKINFO
etc
}