Caching arrays describing rectangulars with position

Discussion in 'Plugin Development' started by mncat77, Aug 11, 2013.

Thread Status:
Not open for further replies.
  1. I have a very resource intensive method that returns an onedimensional array for the parameters x, z, width and length
    Code:java
    1. public int[] getValues(int x, int z, int width, int length) {/*...*/}

    The values at each coordinate never change, but in my code I have to check the same value several times which makes it really slow. I want to solve this through caching, so that a value at a coordinate is never calculated more than once.
    Does anyone know how I could cache that effectively with as little resources used as possible or just hint me in the right direction?
    I think I would need to save every request that is made and if a new one is made get the saved request that is closest to the currently requested, but that would take an awful lot of time too (my grid is very big).
     
  2. I am not requesting/calculating the values in order though - also I don't calculate all of them, so it would be just as good using a regular HashMap, I don't see the point?

    EDIT:
    The best solution I see to this atm is to create two HashMaps: one with the actual request and an other one with position data pointing to the request, but shouldn't there be a faster method?
     
Thread Status:
Not open for further replies.

Share This Page