Skip to content

Commit 544a8db

Browse files
committed
Renamed empty creation methods; Added map conversion methods
Additionally, prevented replaced-withs from ignoring type-paremeters, and added some gradle properties as the library didn't build.
1 parent 1d18389 commit 544a8db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+467
-243
lines changed

benchmarks/commonMain/src/benchmarks/immutableList/AddAll.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.ImmutableList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213

1314
@State(Scope.Benchmark)
1415
open class AddAll {
@@ -35,7 +36,7 @@ open class AddAll {
3536
*/
3637
@Benchmark
3738
fun addAllLast(): ImmutableList<String> {
38-
return persistentListOf<String>().addAll(listToAdd)
39+
return emptyPersistentList<String>().addAll(listToAdd)
3940
}
4041

4142
/**

benchmarks/commonMain/src/benchmarks/immutableList/Get.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213

1314
@State(Scope.Benchmark)
1415
open class Get {
1516
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1617
var size: Int = 0
1718

18-
private var persistentList: PersistentList<String> = persistentListOf()
19+
private var persistentList: PersistentList<String> = emptyPersistentList()
1920

2021
@Setup
2122
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableList/Iterate.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213

1314
@State(Scope.Benchmark)
1415
open class Iterate {
1516
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1617
var size: Int = 0
1718

18-
private var persistentList: PersistentList<String> = persistentListOf()
19+
private var persistentList: PersistentList<String> = emptyPersistentList()
1920

2021
@Setup
2122
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableList/Remove.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import kotlinx.collections.immutable.ImmutableList
1010
import kotlinx.collections.immutable.PersistentList
1111
import kotlinx.collections.immutable.persistentListOf
1212
import kotlinx.benchmark.*
13+
import kotlinx.collections.immutable.emptyPersistentList
1314

1415
@State(Scope.Benchmark)
1516
open class Remove {
1617
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1718
var size: Int = 0
1819

19-
private var persistentList: PersistentList<String> = persistentListOf()
20+
private var persistentList: PersistentList<String> = emptyPersistentList()
2021

2122
@Setup
2223
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableList/RemoveAll.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213
import kotlin.random.Random
1314

1415
@State(Scope.Benchmark)
1516
open class RemoveAll {
1617
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1718
var size: Int = 0
1819

19-
private var persistentList: PersistentList<Int> = persistentListOf()
20+
private var persistentList: PersistentList<Int> = emptyPersistentList()
2021

2122
@Setup
2223
fun prepare() {
23-
persistentList = persistentListOf<Int>().addAll(List(size) { it })
24+
persistentList = emptyPersistentList<Int>().addAll(List(size) { it })
2425
}
2526

2627
// Results of the following benchmarks do not indicate memory or time spent per operation,

benchmarks/commonMain/src/benchmarks/immutableList/RemoveAllPredicate.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList
88
import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentList
1112
import kotlinx.collections.immutable.persistentListOf
1213
import kotlin.random.Random
1314

@@ -16,7 +17,7 @@ open class RemoveAllPredicate {
1617
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1718
var size: Int = 0
1819

19-
private var persistentList = persistentListOf<String>()
20+
private var persistentList = emptyPersistentList<String>()
2021
private val truePredicate: (String) -> Boolean = { true }
2122
private val falsePredicate: (String) -> Boolean = { false }
2223
private var randomHalfElementsPredicate: (String) -> Boolean = truePredicate
@@ -39,7 +40,7 @@ open class RemoveAllPredicate {
3940
tailElementsPredicate = { it in tailElements }
4041

4142
val allElements = List(size) { it.toString() }
42-
persistentList = persistentListOf<String>().addAll(allElements)
43+
persistentList = emptyPersistentList<String>().addAll(allElements)
4344
}
4445

4546
// The benchmarks measure (time and memory spent in `removeAll` operation) / size

benchmarks/commonMain/src/benchmarks/immutableList/Set.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import kotlinx.collections.immutable.ImmutableList
1010
import kotlinx.collections.immutable.PersistentList
1111
import kotlinx.collections.immutable.persistentListOf
1212
import kotlinx.benchmark.*
13+
import kotlinx.collections.immutable.emptyPersistentList
1314

1415
@State(Scope.Benchmark)
1516
open class Set {
1617
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1718
var size: Int = 0
1819

19-
private var persistentList: PersistentList<String> = persistentListOf()
20+
private var persistentList: PersistentList<String> = emptyPersistentList()
2021
private var randomIndices = listOf<Int>()
2122

2223
@Setup

benchmarks/commonMain/src/benchmarks/immutableList/builder/AddAll.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213

1314
@State(Scope.Benchmark)
1415
open class AddAll {
@@ -38,7 +39,7 @@ open class AddAll {
3839
*/
3940
@Benchmark
4041
fun addAllLast(): PersistentList.Builder<String> {
41-
val builder = persistentListOf<String>().builder()
42+
val builder = emptyPersistentList<String>().builder()
4243
builder.addAll(listToAdd)
4344
return builder
4445
}

benchmarks/commonMain/src/benchmarks/immutableList/builder/Get.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList.builder
88
import benchmarks.*
99
import kotlinx.collections.immutable.persistentListOf
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentList
1112

1213
@State(Scope.Benchmark)
1314
open class Get {
@@ -17,7 +18,7 @@ open class Get {
1718
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
1819
var immutablePercentage: Double = 0.0
1920

20-
private var builder = persistentListOf<String>().builder()
21+
private var builder = emptyPersistentList<String>().builder()
2122

2223
@Setup
2324
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableList/builder/Iterate.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableList.builder
88
import benchmarks.*
99
import kotlinx.collections.immutable.persistentListOf
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentList
1112

1213
@State(Scope.Benchmark)
1314
open class Iterate {
@@ -17,7 +18,7 @@ open class Iterate {
1718
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
1819
var immutablePercentage: Double = 0.0
1920

20-
private var builder = persistentListOf<String>().builder()
21+
private var builder = emptyPersistentList<String>().builder()
2122

2223
@Setup
2324
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableList/builder/RemoveAll.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213
import kotlin.random.Random
1314

1415
@State(Scope.Benchmark)
@@ -84,7 +85,7 @@ open class RemoveAll {
8485

8586
private fun persistentListBuilderAddIndexes(): PersistentList.Builder<Int> {
8687
val immutableSize = immutableSize(size, immutablePercentage)
87-
var list = persistentListOf<Int>()
88+
var list = emptyPersistentList<Int>()
8889
for (i in 0 until immutableSize) {
8990
list = list.add(i)
9091
}

benchmarks/commonMain/src/benchmarks/immutableList/builder/Set.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentList
1213

1314
@State(Scope.Benchmark)
1415
open class Set {
@@ -18,7 +19,7 @@ open class Set {
1819
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
1920
var immutablePercentage: Double = 0.0
2021

21-
private var builder = persistentListOf<String>().builder()
22+
private var builder = emptyPersistentList<String>().builder()
2223
private var randomIndices = listOf<Int>()
2324

2425
@Setup

benchmarks/commonMain/src/benchmarks/immutableList/utils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
package benchmarks.immutableList
77

88
import kotlinx.collections.immutable.PersistentList
9+
import kotlinx.collections.immutable.emptyPersistentList
910
import kotlinx.collections.immutable.persistentListOf
1011

1112
fun persistentListAdd(size: Int): PersistentList<String> {
12-
var list = persistentListOf<String>()
13+
var list = emptyPersistentList<String>()
1314
repeat(times = size) {
1415
list = list.add("some element")
1516
}

benchmarks/commonMain/src/benchmarks/immutableMap/Canonicalization.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentMap
1010
import kotlinx.collections.immutable.persistentMapOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentMap
1213

1314

1415
/**
@@ -35,13 +36,13 @@ open class Canonicalization {
3536

3637
private var keys = listOf<IntWrapper>()
3738
private var keysToRemove = listOf<IntWrapper>()
38-
private var persistentMap = persistentMapOf<IntWrapper, String>()
39+
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
3940

4041
/**
4142
* Expected height of this persistent map is equal to the [persistentMap]'s expected height divided by 2.
4243
* Obtained by removing some entries of the [persistentMap].
4344
*/
44-
private var halfHeightPersistentMap = persistentMapOf<IntWrapper, String>()
45+
private var halfHeightPersistentMap = emptyPersistentMap<IntWrapper, String>()
4546

4647
@Setup
4748
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableMap/Equals.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package benchmarks.immutableMap
77

88
import benchmarks.*
99
import kotlinx.benchmark.*
10+
import kotlinx.collections.immutable.emptyPersistentMap
1011
import kotlinx.collections.immutable.persistentMapOf
1112

1213
@State(Scope.Benchmark)
@@ -20,10 +21,10 @@ open class Equals {
2021
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
2122
var hashCodeType = ""
2223

23-
private var persistentMap = persistentMapOf<IntWrapper, String>()
24-
private var sameMap = persistentMapOf<IntWrapper, String>()
25-
private var slightlyDifferentMap = persistentMapOf<IntWrapper, String>()
26-
private var veryDifferentMap = persistentMapOf<IntWrapper, String>()
24+
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
25+
private var sameMap = emptyPersistentMap<IntWrapper, String>()
26+
private var slightlyDifferentMap = emptyPersistentMap<IntWrapper, String>()
27+
private var veryDifferentMap = emptyPersistentMap<IntWrapper, String>()
2728

2829
@Setup
2930
fun prepare() {
@@ -36,8 +37,10 @@ open class Equals {
3637

3738
@Benchmark
3839
fun equalsTrue() = persistentMap == sameMap
40+
3941
@Benchmark
4042
fun nearlyEquals() = persistentMap == slightlyDifferentMap
43+
4144
@Benchmark
4245
fun notEquals() = persistentMap == veryDifferentMap
4346
}

benchmarks/commonMain/src/benchmarks/immutableMap/Get.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
88
import benchmarks.*
99
import kotlinx.collections.immutable.persistentMapOf
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentMap
1112

1213
@State(Scope.Benchmark)
1314
open class Get {
@@ -21,7 +22,7 @@ open class Get {
2122
var hashCodeType = ""
2223

2324
private var keys = listOf<IntWrapper>()
24-
private var persistentMap = persistentMapOf<IntWrapper, String>()
25+
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
2526

2627
@Setup
2728
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableMap/Iterate.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
88
import benchmarks.*
99
import kotlinx.collections.immutable.persistentMapOf
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentMap
1112

1213
@State(Scope.Benchmark)
1314
open class Iterate {
@@ -20,7 +21,7 @@ open class Iterate {
2021
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
2122
var hashCodeType = ""
2223

23-
private var persistentMap = persistentMapOf<IntWrapper, String>()
24+
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
2425

2526
@Setup
2627
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableMap/PutAll.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package benchmarks.immutableMap
88
import benchmarks.*
99
import kotlinx.collections.immutable.PersistentMap
1010
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.emptyPersistentMap
1112
import kotlinx.collections.immutable.persistentMapOf
1213

1314
@State(Scope.Benchmark)
@@ -21,10 +22,10 @@ open class PutAll {
2122
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
2223
var hashCodeType = ""
2324

24-
private var lhs = persistentMapOf<IntWrapper, String>()
25-
private var lhsSmall = persistentMapOf<IntWrapper, String>()
26-
private var rhs = persistentMapOf<IntWrapper, String>()
27-
private var rhsSmall = persistentMapOf<IntWrapper, String>()
25+
private var lhs = emptyPersistentMap<IntWrapper, String>()
26+
private var lhsSmall = emptyPersistentMap<IntWrapper, String>()
27+
private var rhs = emptyPersistentMap<IntWrapper, String>()
28+
private var rhsSmall = emptyPersistentMap<IntWrapper, String>()
2829

2930
@Setup
3031
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableMap/Remove.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import benchmarks.*
99
import kotlinx.collections.immutable.PersistentMap
1010
import kotlinx.collections.immutable.persistentMapOf
1111
import kotlinx.benchmark.*
12+
import kotlinx.collections.immutable.emptyPersistentMap
1213

1314
@State(Scope.Benchmark)
1415
open class Remove {
@@ -22,7 +23,7 @@ open class Remove {
2223
var hashCodeType = ""
2324

2425
private var keys = listOf<IntWrapper>()
25-
private var persistentMap = persistentMapOf<IntWrapper, String>()
26+
private var persistentMap = emptyPersistentMap<IntWrapper, String>()
2627

2728
@Setup
2829
fun prepare() {

benchmarks/commonMain/src/benchmarks/immutableMap/builder/Equals.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package benchmarks.immutableMap.builder
77

88
import benchmarks.*
99
import kotlinx.benchmark.*
10+
import kotlinx.collections.immutable.emptyPersistentMap
1011
import kotlinx.collections.immutable.persistentMapOf
1112

1213
@State(Scope.Benchmark)
@@ -20,10 +21,10 @@ open class Equals {
2021
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
2122
var hashCodeType = ""
2223

23-
private var persistentMap = persistentMapOf<IntWrapper, String>().builder()
24-
private var sameMap = persistentMapOf<IntWrapper, String>().builder()
25-
private var slightlyDifferentMap = persistentMapOf<IntWrapper, String>().builder()
26-
private var veryDifferentMap = persistentMapOf<IntWrapper, String>().builder()
24+
private var persistentMap = emptyPersistentMap<IntWrapper, String>().builder()
25+
private var sameMap = emptyPersistentMap<IntWrapper, String>().builder()
26+
private var slightlyDifferentMap = emptyPersistentMap<IntWrapper, String>().builder()
27+
private var veryDifferentMap = emptyPersistentMap<IntWrapper, String>().builder()
2728

2829
@Setup
2930
fun prepare() {
@@ -38,8 +39,10 @@ open class Equals {
3839

3940
@Benchmark
4041
fun equalsTrue() = persistentMap == sameMap
42+
4143
@Benchmark
4244
fun nearlyEquals() = persistentMap == slightlyDifferentMap
45+
4346
@Benchmark
4447
fun notEquals() = persistentMap == veryDifferentMap
4548

0 commit comments

Comments
 (0)