Skip to content

Commit

Permalink
Setup Maven central publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
cvb941 committed Apr 27, 2024
1 parent c42dbd5 commit 52348f1
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ jobs:
- name: Publish package
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_IN_MEMORY_KEY_PASSWORD }}
4 changes: 1 addition & 3 deletions .idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Parallel Operations for Kotlin
Parallel *map*, *reduce*, and various indexed and in-place operations on collections for Kotlin using coroutines.

The parallel *map* implementation is called *.mapParallel()*. It is implemented like this.
```kotlin
suspend fun <T, R> Iterable<T>.mapParallel(transform: (T) -> R): List<R> = coroutineScope {
map { async { transform(it) } }.map { it.await() }
}
```

Example of using the parallel *map* operation.
```kotlin
fun showCase() {
val list = listOf(1,2,3)
runBlocking(Dispatchers.Default) {
var mappedList = list.mapParallel { it * 2 } // Results in [2,4,6]
}
}
```

There is also the parallel *reduce* operation with chunked variations, which can be used to perform **associative** operations on a collection, like *sum*.

**Note:** If you want to achieve multithreading, make sure to run the coroutine with the Default dispatcher.

## Chunked operations
Chunked operations improve performance since they split the collection into just a couple of segments,
which are processed each by a single thread. That benefits from data locality and lesser thread management.
It is particularly useful (pretty much needed for operations like sum) in the reduce operation when using multithreading,
since each thread takes one chunk that it reduces on its own. After all coroutines finish, their results are then reduced again to the final result.

## Gradle
The library is published in the Maven Central repository.
Include this line in your module build.gradle file.
```gradle
dependencies {
implementation("io.github.cvb941:kotlin-parallel-operations:2.0.0")
}
```

## Future
In the future, I would like other transformation functions to be implemented.
40 changes: 30 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform") version "1.9.23"
id("org.jetbrains.kotlinx.benchmark") version "0.4.10"
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.23"
id("maven-publish")
id("com.vanniktech.maven.publish") version "0.28.0"
}

group = "net.kusik"
group = "io.github.cvb941"
version = "2.0.0"

repositories {
Expand Down Expand Up @@ -90,15 +91,34 @@ allOpen {
annotation("org.openjdk.jmh.annotations.State")
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/cvb941/kotlin-parallel-operations")
credentials {
username = project.findProperty("gpr.user")?.toString() ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key")?.toString() ?: System.getenv("GITHUB_TOKEN")
mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)

signAllPublications()

pom {
name.set("Parallel Operations")
description.set("Parallel map, reduce and more using coroutines in Kotlin.")
inceptionYear.set("2019")
url.set("https://github.com/cvb941/kotlin-parallel-operations/")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
distribution.set("repo")
}
}
developers {
developer {
id.set("cvb941")
name.set("Lukas Kusik")
url.set("https://github.com/cvb941/")
}
}
scm {
url.set("https://github.com/cvb941/kotlin-parallel-operations/")
connection.set("scm:git:git://github.com/cvb941/kotlin-parallel-operations.git")
developerConnection.set("scm:git:ssh://[email protected]/cvb941/kotlin-parallel-operations.git")
}
}
}

0 comments on commit 52348f1

Please sign in to comment.