Hey, I see people that struggle with Item Container shift bugs so I'm here to give you 2 (4) ways of shifting your items without bugs!
This is just some simple code that allows you to shift all of your items LEFT. An example usage would be the bank. Take out the first item, all items now shift left. That's what this does.
ItemContainer is a super simple container that literally only has the shift functions. A much more fully featured Container is coming soonish.
The two shifts:
- Memory Friendly
- This one is much more memory friendly but also much slower (~twice as slow) for Containers over 155 items.
- Fast Shift
- This one is much faster (~twice as fast) for containers over 155 items but also uses a lot more memory (because of the partitionJoin mainly).
In reality, the time difference is not big at all. As long as you aren't doing hundreds of shifts per second on randomly distributed Containers, performance shouldn't be too big of a problem for you if you aren't worried about memory.
Bank size (450-500 items) is ~0.03ms for memory friendly, ~0.0065ms for fast shift
Sorry if the java is sloppy, what I wrote is more than I've written in the last year. Juck Fava.
Repo: [Only registered and activated users can see links. ]
The performance test was written in kotlin, executed on amd64 Ubuntu 18.04, R7 1800X.
Performance Graph - Plot.ly: [Only registered and activated users can see links. ]
Spoiler for New kt Container Peek:
How can you know that it has no bugs when it has no tests
There are no bugs as far as I have tested in the scope of what I have provided using the default JVM for its intended use, which is shifting all BaseItem in an Array of BaseItem left.
This doesn't account for null because I don't think null should be used in this scenario (Array of BaseItem) where I have provided a much more friendly and compatible alternative in INVALID_ITEM.
If someone wants to point out bugs in the code and how to reproduce it reliably, I'd gladly look in to fixing them.
That said, I do have some tests in my Container code, which will be coming with the Container post. It's not a large amount of tests but it does test expected behaviour using multiple Result types (testing for a known possible partial addition of an item returning Success.PartialAddItem(Item(itemId, remainingItemAmount), testing for an invalid safe get returning a Failiure.BadIndex, etc.). It's probably not completely bug free, no sizeable codebase ever REALLY is, but I'm just 1 guy writing stuff for fun (for now) so there's a limit to how far I can test and how far I want to test. There are currently bugs in other parts of the code, but not any I could find in the item shift part of the code which is why I released it claiming it to be "bug free".
|« [Elvarg] Wardrobe: Drop-in configurable dialogue based robe set spawning object. | [RUSE] Player Owned Shops. »|
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
|Tags for this Thread|