Welcome in this lecture, I'm going to talk about the full slice expressions, a full slice expression
allows you to control the capacity of a return slice from a slice expression.
Let me show you how it works and why you want to use it.
Let's take a look at a simple expression first, I know you're already mastered this now let's take
a look at our full size expression.
A full glass expression has a third index called the cap, or more formally, the max.
So using a full slice expression, you can slice a slice and at the same time, you can limit the capacity
of the return slice from this slice expression.
Let's take a look at some examples.
Let's say you have a slice such as this one.
That creates this slice, I'm going to put the sliceable variable here so you can understand what's
going on better.
Now, let's slice it by starting from its first index up to its third element.
May do so, it returns a new slice that looks like this.
The length is three and the capacity is four, so far so good.
Now let's use a full glass expression to limit the capacity like this.
OK, here it is.
Let's check out the slicers capacity now.
Think of the capacity position as the element position in the back injury.
Here it is three.
So it returns a slice with the capacity of three elements.
It hides the last element from the return slice me, limit the capacity even further.
To do that, I also need to change the stopping position is because the stopping position can't be greater
than the capacity position.
Now the slice cannot see the rest of the begging Gary's elements after the second element.
Let's limit the capacity even further.
So now the slice can only see the back in Gary's first element, not the rest of it.
Now, let's take a look at this slice expression here.
I set the cup, the position to three, but the capacity of the slice becomes to speak because for this
slice, there are only two elements in Specking array.
Here I increase the starting index to two, so the slices capacity becomes one is because the slice
can only see this element.
Here are increment the capacity position to four.
So the fourth element of the begging injury becomes visible to the slice for the slice.
There are two elements in this injury, so its capacity becomes too.
OK, one last example.
Here I said all the indexes to for so the slice becomes empty now, so when you add an element to this
slice, the apan function will allocate a new era for its.
OK, enough theory.
Now, let's take a look at that cold example.
Let's create an insidious.
Lima printed.
As you guessed, this lies its length and capacity are for the first two elements of the slides are
old numbers and the rest are even numbers.
Let's say I want to slice it for the odd numbers.
Let me also show you the old slice.
As you can see, the numbers and the old slices are sharing the same baking array, the old slice has
two elements and there are two more elements in the back injury.
Let me open two more odd numbers to the old slice.
Doing so overwrites the normalises back injury as well.
So how can I prevent this problem?
Well, I can use a full sized expression like this.
Now, it doesn't override the begging aura of the numb slice, it's because the numbers and the slices
have different back injuries now.
So why do they have different arrays, please powers the video and try to guess.
OK, is because here I limit the capacity of the old slice, right?
Let me comment about this aband.
So before that happened, they were sharing the same array, however old slices capacity was two, so
it didn't have any remaining capacity.
It was already full.
So I expanded to it.
Here, the apan function calculated that there wasn't enough capacity in the slice.
So it has allocated a new array.
So unless you want to override the old slice, you should use a full glass expression.
As in here, by the way, I can refactor this code.
Let me add this up and call here.
And let me remove this up and call here.
All right, whether it still works here, first it returns a slice with a capacity of two, then appending
to it returns a new slice with a new back injury.
Let me also add two more, even numbers to the numbers slice.
Here I say the result to a new variable, so the return slice doesn't override the numskulls.
I didn't use a full glass expression here, however, that even Slice has a new back injury despite
of that.
But why this past video?
And try to guess.
Well, it's because the numskulls is already full.
It's cuppers these four.
So when I point to it, the function allocates a new era and returns a slice that references to that
new era.
That's why it doesn't change the num slice.
So you don't always need the use of full slice expression.
All right.
That's all for now.
Thank you for watching.
See in the next picture.