r/ComputerCraft • • Jun 29 '25

Simple but efficient storage system

https://www.youtube.com/watch?v=qZlIdvXmXKw

What's cool about it is that the storage and retrieval times don't increase as you add more chests to it. It is essentially just a hash map.

Next I want to add some better search code, but for now I am going to use it with some cc controlled Create farms, and I will hardcode the full item names in the code.

23 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/Trainzkid Jun 30 '25

Actually, I'm thinking of some Minecraft mods, Applied Energistics and Refined Storage. This reminds me of them, but without their fancy gui lol

Thanks for providing access to the code!! I know how to program but I'm not as familiar with Lua so I'm hoping to change that some by looking at this code, and I'm just genuinely curious how you managed to make it so quick, it's impressive

2

u/BookkeeperPlane8594 Jun 30 '25

Thanks! Feel free to ask about any bits, but it is essentially a hash map.

You hash the item's name, which gives you a number between 1 and the total count of all chests. With this number, you place the item in the corresponding numbered chest.

Then, when you want to get an item back you do the same hash and get the same number. you then only need to look in that numbered chest, so you do not need to scan through all chests. This means before you start looking, you know the exact position of the item in the sea of many chests. Due to this, you could have 15 billion chests all connected, and the look up time would be the exact same as if there were only 1.

Example:
total chest count: 5

put
hash("stone") -> 3
place item in chest 3

get
hash("stone") -> 3
ok I will look only in 3 (don't need to check 1, 2, 4, 5 this is the fast bit)