Rant about Hashmaps in plugins.

Discussion in 'Bukkit Discussion' started by wow4201, Aug 1, 2012.

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

    wow4201

    I see many plugins use hashmaps (obviously).
    What i don't understand is under practical cases (Say a server has 50 people online at time).
    and this plugin has been used for 1-2 months.
    and lets say this plugin is to protect chests.

    So theres a file for this plugin that contains 9000 entries.

    So this plugin uses the onBlockBreak to determine if
    the block that is being broken is "protected"

    So it does that by scanning through the hashmap of 9000 Entries.
    Every, single time a player breaks a block.

    -_- WHY.
     
  2. Offline

    JOPHESTUS

    If it makes you feel any better, I don't know how to use hashmaps so you'll never find a hashmap in one of my plugins (atm)
     
  3. Offline

    Milkywayz

    You are aware that the contents of a hash map are erased from memory when the plugin is disabled right? The simple solution would be to restart your server once a day. Hashmaps are very useful for a variety of other things for example if you need to associate a players name with say maybe a group? You can easily do that by adding the players to the hash map upon enable, onJoin, or maybe every few minutes. I find hash maps extremely useful if the purpose is right ;)
     
  4. Offline

    mindless728

    Umm, do you realize the reason to use HashMap's is because there is a near constant time access to get elements out of it right (akin to getting information out of an array). Essentially it is used to make it VERY fast for accesses into the map. This means that it doesn't "scan" through all 9k entries, it calculates the hash (usually very fast) and then essentially uses an array behind the scenes to get near constant time accesses.

    This is why they are used, because they are fast.
     
Thread Status:
Not open for further replies.

Share This Page