diff --git a/duckShopServer/DuckShopServerSetDefinition/task.md b/duckShopServer/DuckShopServerSetDefinition/task.md index a5aed2a..c147ba9 100644 --- a/duckShopServer/DuckShopServerSetDefinition/task.md +++ b/duckShopServer/DuckShopServerSetDefinition/task.md @@ -3,7 +3,7 @@ `Set`s are collections of _unique_ elements. They reflect the mathematical abstraction of `set`: a group of objects without duplicates. -It means, if we have two sets with the same size with the same objects inside, +It means, if we have two sets of the same size with the same objects inside, these two sets will be equal. ![Set definition](../../utils/src/main/resources/images/duck/shop/theory/set_definition.png) @@ -11,24 +11,24 @@ these two sets will be equal.
Unlike `List`, `Set` normally does not preserve the order of items. -But similar to `List` you can use the different `Set` implementations to change this property, -e.g. you can use `LinkedHashSet` implementation, that sorts elements in the set by default. +But similar to the case of `List`, you can use different `Set` implementations to change this property: +e.g., you can use the `LinkedHashSet` implementation, which sorts elements in the set by default. -Each implementation defines not only the set of possible operations with this collection, +Each implementation defines not only the set of possible operations with this collection but also the complexity of `this` operation. -`LinkedHashSet`, for the intents and purposes of being accessed using contains is simply +`LinkedHashSet`, for the intents and purposes of being accessed using `contains`, is simply a hash set. So, inserting elements into the linked hash set is cheap.
In general `Set` contains _only_ elements with the _same_ type. -In some cases it is possible to store elements with different types, -but which have a _relation_ between them, see the [documentation](https://kotlinlang.org/docs/generics.html) for more details. +In some cases, it is possible to store elements with different types, +but they must have a _relation_ between them, see the [documentation](https://kotlinlang.org/docs/generics.html) for more details. ![Incorrect type in a set](../../utils/src/main/resources/images/duck/shop/theory/set_wrong_type.png) -If you have a set with objects, e.g. with your own type like `Duck`, -it is possible to override behaviour to compare element in `Set`. -By default, to compare elements inside a set the [`euqals`](https://kotlinlang.org/docs/equality.html) function is used. +If you have a set with objects, e.g., with your own type like `Duck`, +it is possible to override the behavior of comparing elements in `Set`. +By default, to compare elements inside a set, the [`euqals`](https://kotlinlang.org/docs/equality.html) function is used. It is possible to override this function and compare items only by a part of possible properties.
@@ -54,13 +54,13 @@ but `DuckOverridden` will be compared _only_ by `backgroundColor`: ![Set comparison example](../../utils/src/main/resources/images/duck/shop/theory/set_equal_example.png) -Since we compare only `backgroundColor`, the set in the second case consists only from one element. +Since we compare only `backgroundColor`, the set in the second case consists only of one element.
## Initialization -To create a new set you can use special _builders_: +To create a new set, you can use special _builders_: ```kotlin val emptySet1 = emptySet() // Builds the internal object EmptySet @@ -69,10 +69,10 @@ val emptySet2 = setOf() // Calls emptySet()
-In Kotlin the `emptySet` implementation is an object under the hood. -The main reason such function exists is to save allocations (creating and deleting new variables). -Since `emptySet` returns the same _singleton_ instance every time it is called so one can -use it in allocation free manner. It allows to work your Kotlin program in a more efficient way. +In Kotlin, the `emptySet` implementation is an object under the hood. +The main reason such a function exists is to save allocations (creating and deleting new variables). +Since `emptySet` returns the same _singleton_ instance every time it is called, one can +use it in allocation freely. It allows your Kotlin program to work in a more efficient way.
```kotlin