Hi there. 2
Now let's look at link has said that is another set implementation as the name linked has set implies 3
. 4
It uses a hash table as well as a linked list in its implementation of the set interface which has set 5
below that element insertion order is not because of how alert linked has it has a doubly linked list 6
running through its elements which helps in preserving the order off in certain elements but that doesn't 7
mean that it is slow. 8
It extends has set on it has almost asfast us hash Hachette sleights known as would be due to the expense 9
of maintaining a linked list. 10
So just like has said look up insertion and deletion operations are supported in constant time not on 11
like a house set linked has set permits only one element unintentionally It uses a linked hash map which 12
we will look at later. 13
Recall that set uses hash map internally and this one uses a linked Hashima on preset which we will 14
discuss later uses a tree mapping identity. 15
So all these implementations internally use corresponding map implementations. 16
Let's actually take a quick look at the sourcecode to see how linked Hassett instantiates a linked hash 17
map. 18
OK here we are in the grip code Web site and this is the link. 19
Has a class on this is the constructor and it is in the super constructor. 20
So it is invoking the constructor in the superclass which is the Hasson. 21
OK so let's look at that particular constructor under just passing three values. 22
One is the capacity. 23
The second one is the load factor and the third one has some boolean value. 24
So let's go into hierarchy here. 25
Let's click on has said OK this is a high set and it's going to outline. 26
And this is the constructor so there are multiple overloaded constructors and this one with the three 27
parameters is the one that is invoked. 28
Kremlin has seen on here it is. 29
So the first parameter is capacity second is load factor and third the caller does dummy. 30
So it is used only do under load the constructor. 31
OK so if it is not used then we have two identical constructors. 32
So it's only use for the sake of overloading. 33
You can construct it already. 34
And here we are invoking the linked hash map. 35
OK we are instantiating encash map on passing initial capacity unload factor and dummy variable is simply 36
ignored. 37
Now let's head back to the sleights we already discuss these. 38
These are the typical use cases we would want to use a linked headset. 39
If we want first look up insertion and deletion but that insertion order Pozzo. 40
OK. 41
Finally similar to a headset link has set is also better than our eldest If remove all are written. 42
All operations are will be used frequently now although some of the operations Silverlink hasard can 43
be slightly slower than Hassid linked has it can be slightly faster when it comes to iterating the elements 44
. 45
And that's because it addition with the link has set is dependent on the size of the SEC due to the 46
use of doubling. 47
Whereas in the case of Hasek's it duration is dependent on the capacity. 48
Now if you recall capacity is nothing but the number of buckets in the hash table that is a odysseys 49
as we know that has table in Donelly users on our IT has set the actual number of elements would be 50
less than the capacity. 51
But it still depends on the capacity and length has it duration has nothing to do with that capacity 52
but with only the number of actual elements due to the usage off doubly linked list. 53
Now in under a minute let's do a quick demo of linked has set a new method called Link Hassidim all 54
has been added with a set class and here all we are doing as fast we are instantiating it has set and 55
we are adding these three elements. 56
So the has set has strengths. 57
So we are adding these three elements at large. 58
John and Anita and simply we are printing the Hasson. 59
OK. 60
So these are three elements. 61
And then we are creating a lint has set here. 62
OK. 63
And we are simply adding the same elements on we are printing the length Hasen. 64
So let's just go ahead and run it. 65
And so we can see the difference between the two sets. 66
Now he has said is printing John-Roger non-adult although the order of arding is large. 67
John I and Anita. 68
OK so the order is not preserved as we know in a has set but when it comes to link has set the order 69
is preserved. 70
You can see that Roger John and Anita are being displayed in the same order as Douban in-circuit. 71
So that's that one did you have it linked has you got the benefits of Hosack but at the same time you 72
also have the insertion order preserved. 73
OK so it is just slightly smaller than ḥasan. 74
So that's about it that's about Lane has. 75
Thank you. 76
See you in the next lesson.