.
Continue to analyze Histo.log, find an online normal machine, generate histo, use the fault machine data minus normal value, get the difference is as follows (Top 10):
class
instances
bytes
[B
47404
4275481936
java.util.hashmap$entry
19442009
622144288
java.lang.Long
19711584
473078016
[Ljava.util.hashmap$entry;
239216
164734560
com.taobao.at.dal.comm
1, Hashtable is a dictionary subclass,
Copy Code code as follows:
public class HashtableExtends dictionaryImplements Map
HASHMAP:
Copy Code code as follows:
public class HashmapExtends abstractmapImplements Map
HashMap and Hashtable are all the implementation classes of the map interface;
2, the method in Hashtable is synchronous (), and the method in
temporary e = p;As for the other situation is the position conflict, that is, according to (N-1) hash algorithm has a collision, again sub-situation discussion;1. Deposit in the form of a linked list;2. If a collision causes the chain list to be too long (greater than or equal to Treeify_threshold), convert the linked list into a red-black tree;
Finally, if E is not empty, add e to the table (E.value is assigned the parameter value in Putval ());
The code is as follows:Final V putval
1. IntroductionWe know from the above essay that the bottom of hashset is implemented by map, so what is map? How is the bottom layer implemented? Here we analyze the source code, to see the specific structure and implementation. The Map collection class is used to store element pairs (called "Keys" and "values"), where each key is mapped to a value. Map.entry is its inner class, which describes the key/value pairs in the map. It should be noted that the map, which allows NULL for a key, also al
Hashmap is a great utility of JDK. It maps various objects and implements fast access to the corresponding "key-value. I feel ashamed after the study. Hash is to hash the object's hashcode through the key, and then obtain the index value in the object table through indexfor.
Hashmap is a great utility of JDK. It maps various objects and implements fast access to the corresponding "key-value. But what have
The difference between Hashtable and HashMap
First, the inherited parent classes are different.Hashtable inherits from the dictionary class, and HashMap inherits from the Abstractmap class. But both implement the map interface.
Copy Code code as follows:
public class HashtableExtends dictionaryImplements Map
public class HashmapExtends abstractmapImplements Map
second, thread securit
A simple operation method of subclass HashMap of map CollectionImport Java.util.hashmap;import Java.util.iterator;public class Hashmapdemos {public static void%r0main (string[] args) {//HashmapClass studenti{private String name;private int age; Studenti (String name, int age) {this.name=name;this.age = age;} public int getage () {return age;} Public String GetName () {return name;} Public String toString () {return ' The Student Name: ' +name + ' and
In HashMap, if you need to use multiple attribute combinations as keys, you can combine the several attributes into one object as key. However, the problem is that, to do get, there is often no way to save the original put operation of the key object reference, at this time, you need to have key object cover the following hashcode() and equals( Object obj) is implemented. Sample code is as follows: Public classTestkeyobject {Private LongID; Private in
-Wxhm.put ("The Pride of the lake", array1); AWxhm.put ("The Condor Man", array2); + the //Add a collection of martial arts novels to the collection -Hm1.put ("Martial arts Fiction", WXHM); $ the //Traverse the the //get a collection of keys for a novel collection theSetHm1.keyset (); - //Traverse in for(String hm1key:hm1set) { the //the value of the novel collection is Hashmap
is a segment--->Segment---> A hashentry---> In the future each Key-value pair is converted into Hashentry object.The structure of--->hashentry is also a unidirectional linked list structure---> This class takes advantage of the CAS operation and the lock method provided by the unsafe class. Achieve thread safety and efficiency. The so-called segmented lock technique is to store elements in multiple containers, each with its own lock. Distribute the pressure of a single lock to multiple locks. G
[Java learning notes] HashMap subinterface --- LinkedHashMap, javalinkedhashmapFeatures:
The order of stored elements is the same as that of retrieved elements (similar to the sequence hashset)
1 import java.util.HashMap; 2 import java.util.Iterator; 3 import java.util.LinkedHashMap; 4 import java.util.Map; 5 6 public class LinkedHashMapDemo { 7 8 public static void main(String[] args) { 9
The first is the use of the HashMap EntrySet () method: map The second is to use HashMap's keyset () method: map In both ways, the efficiency of the former is higher than that of the latter, mainly because the former actually puts both the key and the value into the iterator, and only executes once to find all the key-value pairs. and the latter equivalent to execute two times, the first time the key and value are deposited into the itera
string and the number of occurrences of the character +HashmapNewHashmap(); - //4. Iterate through the character array to get each character and store the characters in a double-column collection + for(CharC:arr) { A //5, the stored procedure to make a judgment, if the collection does not contain this key, the character as a key, the value of 1 storage, if the collection contains this key, the value is added 1 storage at /*if (!hm.containskey (c)) {//If
ObjectiveAs an efficient map structure, HASHMAP has become an indispensable and efficient way to execute in Java.Inheritance relationshipHashMap inherits the Abstractmap, realizes the map interface, cloneable,serailizable interface.Base properties
Default_initial_capacity=16
Maximum_capacity=1
default_load_factor=0.75
Treeify_threshold=8
Untreeify_threshold=6
Min_treeify_capacity=64
NodeThe node class implements the Map.entry int
of space and time consumption?
1, the original when we expand the container of the hash structure, the hash table to new a larger array, and then copy the contents of the original array to the new array, and to hash;
2. It is also a matter of knowledge as to the size of this larger new array, which, in general, will be set to a prime number similar to the double size of the original array. NET in the generation of this prime number there is a certain skill.
From 1 and 2, it can be seen that
longer executed.(2) But in the case of a hash collision, the first two conditions are established, and then the last equals must be used to determine the equality of the objects.A 3.hash collision scene?(1) Generally appears in large data situations(2) The generation method of Hashcode is weak (such as the artificial production hashcode above)Summary: This chapter mainly through the introduction of hash collision once again in-depth understanding of hashmap
// studnet Package yzhou.gen03; Public class Student{ private T score; Public T Getscore () { return score; } Public void SetScore (T score) { this. score = score; }} // bjstu public class Student{ private T score; public T Getscore () { return score; public void SetScore (T score) { this . Score = SCO Re }}Package Yzhou.gen03;import Java.util.hashmap;import java.util.map;import java.util.set;import Java.util.Map.Entry;/** * generics
. Delete // When you delete a node, you need to // 1. The successor of the forward node points to the subsequent node to delete the node // privatevoid remove () { = after ; = before; }3. Increase Private void Addbefore (entry existingentry) {after = existingentry; The successor node of the current node points to the new node = Existingentry.before; this ; this ; // }4. The rewritten init
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.