Hi there. 2
Now let's look at Lincoln National if you recall when Scott has said unladen link has said. 3
He said that Hastert does not preserve social order but Lynch has said extensor has set up reserves 4
in such an order and is also almost as fast as a hassle just because it extends Hassen. 5
Similarly the map implementation's hash map does not because of insertion order one linked hash map 6
which extends the hash map does so in such an order that not much difference in this speed. 7
So the set up is exactly at anything. 8
Implementations. 9
We have the has set on that subclass. 10
Link has set Verizon map implementations. 11
We have hashed map undersupply us and encashment and we know that internally has set uses a hash map 12
on link has set uses it linked Hashanah. 13
So he had other key points of her linked hash map on most of this stuff is reported to from earlier 14
lessons on Henson's very straightforward. 15
But let's quickly glance to them linked to hash map is basically a hash table as well as a linked list 16
implementation of a map because it has a doubly linked list running through its entries which help in 17
preserving the order off in certain mappings. 18
But it extends the hash not Osoyoos almost as fast as a hash small and slight Malonis will be due to 19
the expense of maintaining a linked list. 20
So just like hash map lookup insertion and deletion operations are somewhat constant I also like a hash 21
map linked hash map where it's not allowed use and also exactly one NULL. 22
So if there is already a mapping within Alte try to add a new mapping with a null key once again then 23
the value in the old mapping will be replaceable. 24
The new I look in the new moppy and we already know that. 25
Finally it's methods are not synchronized just like in the case of the hash mob under synchronization 26
is required. 27
It can always be they can get off externally as we will see later when we get to the Mugby trading partner 28
. 29
And this is about activation speed. 30
And this was also discussed in length has surplus and since Lynch has said in an early is of selling 31
Hasham up there is absolutely nothing which is different from what we discussed earlier in encashment 32
only slightly faster than hashmarks when it comes to iterating them out. 33
And that's because it duration length hash map is dependent on the size of the map due to the use of 34
doubly linked list. 35
There doesn't the kings of hash map the duration is dependent on the capacity right which could be much 36
greater than the actual size of the map. 37
And here comes a very interesting feature offering hash. 38
It can be used as an LRU cache where you transport least use and be used if you're not sure what a cache 39
means. 40
It is basically a component that stores important and data so that this important data can be quickly 41
access. 42
Now when you say important it could mean anything depending on the application in context. 43
It could signify most recently used items or most frequently access items are in a Facebook like application 44
it could mean most liked or most shared items all of the heavily trafficked Web sites cache lots and 45
lots of data so that the response time in written Ingur pages will be very fast. 46
You just cannot always access the database cross-stitching your most important data. 47
Memcached is a very popular in-memory gushing system that you cough up so sites made news on a note 48
that such data is stored in RAM fast boxes and these websites use lots and lots of room so they don't 49
use the database for fetching the data on every single Axel's lot of data will be stored in the cache 50
Engram and that is more bit hard to use since in encashment can be used as a lot of cash. 51
Let's look at an illustration. 52
Also allow you cash and a lot in cash uses least recently used caching strategy. 53
There can be many strategies but this is the strategy that an alarm Lukash uses on running of the cash 54
. 55
We have the least recently used item while on the other. 56
We have the most recently used item so items on order according to how recently they were used. 57
Honestly are done in green with cash that would be considered as the most recently used item will be 58
added on the air and has been most recently used item. 59
Now if the cash is full then the new entry will be added under the least recently added entry. 60
On the other and we're getting more. 61
Sometimes the victim and victim is for the more cash typically has a sexes no other than in session 62
. 63
If an entry in the cash is accessed then that entry there'll be more prudent and which present. 64
Most recently Axel's writing due to this. 65
Any items that come before that access item are shared by one position. 66
Note that in this case there is no elementary middle as we are only Mogen the elements. 67
I don't know that if you are searching for an item and that item is found in the cache then the seductive 68
cashier. 69
But if the item is not found in the cash then we say that you have a cache miss and we try to find the 70
item in the database on the phone. 71
Well the Mogen got cash. 72
Of know that this LRU cache is a feature of only link Hashima. 73
It does not act like a link has set although link has it in only use ascending hash. 74
No let me pull up the linked hash maps API and we can look at the constructs that would allow us to 75
use link hash map as an alarming cache. 76
After that we would also agree on am offline hash map and we'll see how it can be used as an LRU cache 77
. 78
OK here's a link. 79
Hash map class and we are in the Java 8 API so we are looking at July 8 and as we can see here this 80
is the definition. 81
So the linked hash map extrinsic Hashima. 82
So it is a national honor to implement the map and you can also check out the description of the specification 83
and we have already discussed most often in our lesson. 84
But if you want to you can still look at it. 85
So here are the different construct Girsh are aren't we are concerned about. 86
On the one constructor with regards to the LRU cache and that is just one. 87
OK so this particular constructor it takes three parameters one has the capacity. 88
Another is a low Kacher because it's a map and the third one is Axel's order. 89
OK now if you pass a false to this constructor then NENKE hash mob will not act as a LRU cache. 90
But if you pass through court access order then it would be horizon and argue cash. 91
However the LRU cache size would be unlimited which means that the elements on one end which are least 92
recently used will not be removed. 93
OK that particular element will not be read more than the insert a new element in dialog Googoosh. 94
Now if you want to really Moeder element on if you want to have a fixed size call that a lot of us which 95
is normally done is then what you need to do is you need to subclass discuss. 96
OK so you need to extend this glassing to create a new class with text. 97
Until you can see why the size of LRU cache not in order to remove the least recently used item. 98
There is this matter called as a remote a list entry search sisig remote and yesterday which means that 99
we are removing the entry under Andrius nothing back the entry which is least recently used now when 100
we insert an item using the method or called motard got called in will this particular method. 101
In fact in this particular blast this method will always get done a false pretenses false. 102
It means that a list entry should not be removed. 103
So by default this linked hash mobbers not mode. 104
But we want that lost or injured will be removed if the cache is full. 105
OK so Hadari create a subclass unbe override this matter on that subplot and the subclass will define 106
a purse size for the cache and when the sizes full trying to insert an item then the most and B should 107
be removed. 108
So this method will be invoked by both as well as all mockups because those are the insertion of on 109
every time we insert and add a minute. 110
This method would be in-work and that lesson will also be passed on but within this entry we can this 111
matter. 112
We will actually see if the sizes. 113
If the class sizes can then be written. 114
In which case Dismuke this particular entry will be removed by the class. 115
OK so it would be removed and the option now of the size is not your fault. 116
That will work enough flaws aren't annoying and may be removed. 117
So this particular parameter will not do anything with the parameter. 118
Typically it is just passed but getting this method will be all right. 119
We typically look at the size on Meryton either true or false. 120
Ok we'll sizing is reached max sizes reach the middle and accrue. 121
Otherwise we don't know who was on when that the hash map the put method which says order put on my 122
third most popular and just in case you want to reward me in this matter then you should ensure that 123
you all get it or don't have flaws was so that put off but put all motard will not bring it on there 124
. 125
So that's about getting more or less in theory but let's go hard on much to blur them on striation and 126
we will actually look at we'll create a subclass and we will actually override this. 127
So let's head over to our editor or not. 128
OK. 129
Here we are in the map Demopolis on a new Materne called LRU cache dust has been added. 130
Ok so here the code has already been written. 131
So we are going to create a little hash map and initially we are not going to use it as an add on you 132
cache. 133
OK. 134
So this is a constructor which we have seen already. 135
So we are going to pass a false on we are going in search through mappings. 136
We're going to print it a little PP-ASEL true value and then we will see how it works Asom LRU cache 137
. 138
And we also said that we can subclass it so that we can set the size of the new cash and we'll also 139
look at that. 140
So there are three things that we are going to test. 141
So we are going to pass a force which means that the hash map the hash map is not going to be as on 142
allow you cache it. 143
So here you are inserting three strings three mappings. 144
So it is a map or a string or a string so the string value is string. 145
And here you are in doing it in small gains on the value is a number is. 146
So you're writing in here BBC and we are spending it and we are next Shingo value for you and we are 147
doing it price and we're going to go in printing the value of the dollar you cash. 148
And that would make sense on me as if I had access on a lot of cash. 149
So it will not. 150
It doesn't make sense for this demonstration. 151
We are watching the value beat the value for the ECB and we are printing it and we are adding a couple 152
of more mappings. 153
DD And then each action we print and go on here. 154
So let me just go to aren't those here or does it just. 155
So here is the first one. 156
Some people think is OK maybe the NCC and after fetching the value the value for the key we are printing 157
it once again and once again it's just the same mapping the same old book and after fetching the value 158
forby of on second printing on second the same thing. 159
And then we're adding B and then printing the cash on them there aren't any. 160
Nobody in the cash. 161
So this is like a regular map. 162
It's just a hash map. 163
So you want to change continue to hashmarks. 164
You will be able to see any difference. 165
It's just not internally a hash map is used as its own implementation. 166
It doesn't hash not users and then list also. 167
Now let's go on. 168
Esther Esther doesn't lot gosh. 169
So we just passed through. 170
Here it is. 171
So the hustle of the household put this to love him. 172
And here we are that you know value for lucky. 173
Now it is the value the mapping is being accessed. 174
So the mapping that has is the most recently used on as you can see the Kukla corresponding mapping 175
has been more the Google and which represents the most recently used most recent news item. 176
So how BBC see on it. 177
Now the thing is this having multiple calls who will not make any difference. 178
So it doesn't make any difference whether you Axel's the value price or even once. 179
I and here we are getting more value for be on the TV. 180
So the mapping with B is more than a friend. 181
OK so that's what this particular instrument is showing us the market. 182
Next we are inserting B. 183
So D would be the most recently used item so be added here. 184
And is added here later. 185
So there is no elementary mall shopping at the mall here. 186
As we discussed earlier and the size of the BOP is also on every day. 187
So you can go had an are more and more mappings and they just decided to go up. 188
Now do the final one which is an alarm cashbook a fixed size. 189
Dock. 190
There is a new glass here along Lukash and as discussed earlier Extreme's the lens has Sh'ma. 191
It is all what writing this motard card the more and less and and this glass also defines what size 192
the max and he's history. 193
You can use the cash and how only three elements add the max. 194
And we are also the alarm your cash so we will basically instantiate this particular class and we will 195
pass these values. 196
And this is in done in Wolken the concept in the superclass is and then hash map and link hash map. 197
Then we try to insert an element. 198
It will involve this be more or less and treat it as passing the element that needs to be read more 199
. 200
But like I mentioned earlier we are not going to do anything with this particular parameter. 201
Are we just you don't recall our falls half the size. 202
Here we are in the seismometer and them in dealing hash map class and if the size is greater than max 203
increase which means the cache is full and history in which case it would return at three and record 204
it couldn't looks a good return crew on and that is to put my third order book on the motor when somebody 205
Mode-S enemy. 206
Now if the size is not dead then this will be false. 207
Which means or the size is less than max increase. 208
So the the cache sizes not yet is not the call. 209
In which case it claws will be repaired and that entry will not be removed. 210
So understandability more only when the sizes. 211
So let's go ahead and just change this this and we are still passing crews so we're good. 212
So Tzschirner once again. 213
And as you can see the sizes are listed. 214
So initially it bends all of the elements then we are accessing a Kreiss but it doesn't make any difference 215
. 216
Only once is good enough. 217
So it to move here but just at the moment axis we're not on any at the moment. 218
So we still have both B and C sources and then more than just get by one position then is axles so B 219
will come on the front and it will be moved here to slack on Sistan day. 220
Then we are inserting the new mapping the insert will be added here. 221
And the least recently used mapping is Sea. 222
So that gets to the third. 223
So that particular matter gets in would be more or less the entry on the nation and receive Samal NCM 224
happens when we insert it. 225
He's here Bismo here and these more here. 226
The last entry is tomorrow. 227
So that's all there is. 228
So it's a wonderful data structure on the circle all you have to use a caching mechanism that will allow 229
you mentioned strategy then you can make use of this class. 230
But when you're developing like large search you would typically use memcache. 231
But still there can be chances. 232
Got you. 233
Mr. Inhofe you may want to use this in certain situations where you want to use something like memcached 234
. 235
So there might be some components that you are developing on thought that maybe this will do a good 236
job for you. 237
So that's about Hashima and what code is available in the resource section. 238
Thank you. 239
I'm happy coding