Discussion in 'Plugin Development' started by mastermustard, Feb 28, 2013.
good documentation/tutorials on Hash's?
it seems TheNewBoston had none
alright any other pages that gives examples on uses?
Pretty hard to give you an example usage. I had to write up my own version of a hashmap for my class. It's just a very efficient data structure in terms of being able to add/remove/get values. I use it to store player names (as the key) and store information about players (as the value). This way, if I need to grab a players information, I just use their name as the key, and it will return their information.
They're key-value pairs, you asign some object by a key that you can use to retrieve it back.
The key must be an object that has a good unique hashcode and/or good equals(), String or Integer is just fine most of the time.
You use the put() method to add/replace stuff, if key already exists it will overwrite the value (but not the key - this will make more sense when you make custom classes with hashcode).
The get() method gets the value stored on that key, it returns null if the key-value pair does not exist OR the value is actually null.
You can use containsKey() to check if a key exists but if you're not storing null values you can just use get() and check against null.
The containsValue() method is slow because it doesn't do a quick-search for a key, instead it loops through all elemts and compares, the bigger the map the longer this will take, as opposed to get() and containsKey() which take the same amount of time regardless of map size.
If you still need example then say so, although I think I've covered it.
You can play around with some data structures here:
This gives a more in-depth visual of how data structures work, though I only took a look at hashmap when I was writing the code for it. Digi gave a very good description of the methods and it might be valuable for you to just play around with it without really making a plugin first. This way you can gain a better understanding of it before you implement it in your plugins.
Thanks so much for the detail you put into that.
Ill try out some suff and repost in a few days
Separate names with a comma.