Per-chunk data

Discussion in 'Plugin Development' started by psychic94, May 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    psychic94

    When I was brainstorming how I would implement my new plugin, I found there was one component I couldn't think of how to approach. I want to store data for each chunk in a way similar to a 2 dimensional array. I would access the data with the x and y coordinates of the chunk.

    However, since I have no way of knowing the size of the map, I can't instantiate a basic array without risking making it too small. I could create to use the maximum size a map can be (3.75 million x 3.75 million chunks) but that would be a lot of data to work with. Even if each item in the array was only 1 bit, that would still be 1.6 terabytes.

    Does anyone know a way I can do this? Some ideas I've considered are ArrayList or HashMap. Note that I plan to wrap this data in a class that implements java.io.Serializable. Thanks.

    Is this possible?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    minoneer

    Without knowing what exactly you want to save, this question is kind of hard to answer.

    One approach would be a "2 dimensional" ArrayList. But depending on the Size of the map, access times could become a big problem.
    An Alternative would be a HashMap, with a wrapper class for the chunk coordinates (just 2 ints) as Key, and your data as value. If you choose this method, make sure to implement a propper getHashCode(), eaquals(Object) etc. If none of those approaches fits your needs, you could seach for third party libraries aswell, maybe something simular already exists.

    regards, minoneer
     
  3. Offline

    psychic94

    I think I have an idea. The data type I intend to store is boolean. Perhaps I can use a Set. Since the default is false, the Set starts empty. I add chunks when I set their data to true, and remove them when I set their data to false. That way, I can just use contains(Object) to get the data I want. Would this be a good idea? What implementation of Set should I use if I want it synchronized?

    Update: I did it by extending ArrayList
     
Thread Status:
Not open for further replies.

Share This Page