Make sure you have the geometrie resource. If necessary, see the Resources import webpage.
A table is a function that assigns a value to a key; a key can only have one value. The HashMap <K, V> class is a special implementation table (K is the key type and V value type). The search function is performed in an almost constant time, through the use of a so-called hash function, which converts the key to an integer.
The statement below creates an empty hashmap:
How many fields represent an HashMap? What do their names mean?
Add an entry to the table:
Add a second key-value pair, then a third one. What happened?Entry instances are not adjacently stored in the table. Are you able to find the way used for the allocation of cells?
What happens if you added a new key-value pair with a key that already exists?
It is also possible to delete a key-value pair, using the remove function. Write the statement that removes a key and display the evolution of the memory representation.It’s time to choose the “Unreferenced objects” option. What do you see?
The statement below creates a new empty hashmap:
Add the baba key. What happens to the table of Entry instances? What is one Entry instance?
What happens if you add the new xxx key?
Write a call to the get function. How is performed the get function? at can we conclude about the effectiveness of the get function?
Remove one by one all the points stored in the table (remove function).
Is the table reorganized ?
Enter the instructions below. The goal is to create a hash table table1 containing 2 points, then to create table2 using the copy constructor of HashMap and to create table3 using the clone function. Look at the different memory implementations of these tables. Count the number of instances of the points then remove one point of table1.
What do you notice?
The instructions sequence below is similar to the previous one, except that the points are accessible from variables. What do you notice?