Thread: [KT/JAVA] Efficiently shift your Item arrays (also complementary item class)

Results 1 to 4 of 4
  1. #1 [KT/JAVA] Efficiently shift your Item arrays (also complementary item class) 
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    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:

    Container will promote safe usage and error handling rather than try catching everything using something similar to Java's Result.
    This is meant to be used in Kotlin (it will look and feel nicer in kotlin), though you can use it in Java if you really must.







    For those of you who like to live dangerously

    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member

    Join Date
    Aug 2012
    Posts
    2,366
    Thanks given
    226
    Thanks received
    401
    Rep Power
    218
    Neat thanks
    Reply With Quote  
     

  4. #3  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!


    S Quare Quxx's Avatar
    Join Date
    Jun 2007
    Posts
    8,884
    Thanks given
    1,860
    Thanks received
    4,711
    Rep Power
    5000
    How can you know that it has no bugs when it has no tests



    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    Quote Originally Posted by S Quare Quxx View Post
    How can you know that it has no bugs when it has no tests
    You can write code without bugs while not using tests, it just takes longer because theres nothing to really test the code against other than what your mind thinks should happen.
    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".
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 06-15-2012, 09:08 PM
  2. Updating Item Array
    By The Wanderer in forum Help
    Replies: 2
    Last Post: 11-25-2011, 11:32 AM
  3. Replies: 8
    Last Post: 10-11-2009, 10:37 AM
  4. Replies: 42
    Last Post: 01-05-2009, 01:31 AM
  5. Item array interfaces
    By Palidino in forum Configuration
    Replies: 14
    Last Post: 11-16-2008, 05:34 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •