-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.3.0 release
- Loading branch information
Showing
36 changed files
with
1,199 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
plugins { | ||
id("common-conventions-before") | ||
id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions") | ||
id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-conventions") | ||
id("com.huanshankeji.kotlin-multiplatform-sonatype-ossrh-publish-conventions") | ||
id("common-conventions-after") | ||
} | ||
|
||
kotlin.jvmToolchain(8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.huanshankeji | ||
|
||
import kotlin.annotation.AnnotationTarget.* | ||
|
||
@RequiresOptIn("This API hasn't been tested yet. Use at your own risk.", RequiresOptIn.Level.WARNING) | ||
@Retention(AnnotationRetention.BINARY) | ||
// The ones commented out are what I think may be used in very few use cases. | ||
@Target( | ||
CLASS, | ||
//ANNOTATION_CLASS, | ||
PROPERTY, | ||
//FIELD, | ||
//VALUE_PARAMETER, | ||
CONSTRUCTOR, | ||
FUNCTION, | ||
PROPERTY_GETTER, | ||
PROPERTY_SETTER, | ||
//TYPEALIAS | ||
) | ||
annotation class Untested |
10 changes: 10 additions & 0 deletions
10
core/src/commonMain/kotlin/com/huanshankeji/collections/Collections.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.huanshankeji.collections | ||
|
||
fun List<*>.areElementsDistinct() = | ||
// There is a more efficient implementation. | ||
distinct().size == size | ||
|
||
fun <T> List<T>.eachCount() = | ||
groupBy { it }.mapValues { it.value.size } | ||
// This is tested to be faster than the implementation below in some scenarios. | ||
//groupingBy { it }.eachCount() |
27 changes: 27 additions & 0 deletions
27
core/src/commonMain/kotlin/com/huanshankeji/collections/LexicographicOrderListComparable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.huanshankeji.collections | ||
|
||
class LexicographicOrderListComparable<E : Comparable<E>> internal constructor(val list: List<E>) : | ||
Comparable<LexicographicOrderListComparable<E>> { | ||
override fun compareTo(other: LexicographicOrderListComparable<E>): Int { | ||
val otherList = other.list | ||
tailrec fun helper(index: Int): Int { | ||
val a = list.getOrNull(index) | ||
val b = otherList.getOrNull(index) | ||
return if (a === null) | ||
if (b === null) 0 | ||
else -1 | ||
else | ||
if (b === null) 1 | ||
else { | ||
val elementCompareResult = a.compareTo(b) | ||
if (elementCompareResult != 0) elementCompareResult | ||
else helper(index + 1) | ||
} | ||
} | ||
|
||
return helper(0) | ||
} | ||
} | ||
|
||
fun <E : Comparable<E>> List<E>.lexicographicOrderComparable() = | ||
LexicographicOrderListComparable(this) |
26 changes: 26 additions & 0 deletions
26
...rc/commonTest/kotlin/com/huanshankeji/collections/LexicographicOrderListComparableTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.huanshankeji.collections | ||
|
||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.pair | ||
import io.kotest.property.arbitrary.string | ||
import io.kotest.property.checkAll | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.math.sign | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class LexicographicOrderListComparableTest { | ||
@Test | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
fun testLexicographicOrderListComparable() = runTest { | ||
val stringArb = Arb.string() | ||
checkAll(Arb.pair(stringArb, stringArb)) { (a, b) -> | ||
assertEquals( | ||
(a compareTo b).sign, | ||
(a.toCharArray().asList().lexicographicOrderComparable() compareTo | ||
b.toCharArray().asList().lexicographicOrderComparable()).sign | ||
) | ||
} | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
core/src/jvmMain/kotlin/com/huanshankeji/collections/Collections.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
coroutines/src/commonMain/kotlin/com/huanshankeji/kotlinx/coroutine/Await.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.huanshankeji.kotlinx.coroutine | ||
|
||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.selects.select | ||
|
||
suspend fun <T> awaitAny(vararg deferreds: Deferred<T>): T { | ||
require(deferreds.isNotEmpty()) | ||
return select { deferreds.forEach { it.onAwait { it } } } | ||
} | ||
|
||
suspend fun <T> Collection<Deferred<T>>.awaitAny(): T { | ||
require(isNotEmpty()) | ||
return select { forEach { it.onAwait { it } } } | ||
} | ||
|
||
suspend fun <T> Collection<Deferred<T>>.awaitAnyAndCancelOthers(): T { | ||
require(isNotEmpty()) | ||
val firstAwaited = select { forEachIndexed { index, deferred -> deferred.onAwait { IndexedValue(index, it) } } } | ||
val firstAwaitedIndex = firstAwaited.index | ||
forEachIndexed { index, deferred -> if (index != firstAwaitedIndex) deferred.cancel() } | ||
return firstAwaited.value | ||
} | ||
|
||
suspend fun joinAny(vararg jobs: Job) { | ||
require(jobs.isNotEmpty()) | ||
select { jobs.forEach { it.onJoin { } } } | ||
} | ||
|
||
suspend fun Collection<Job>.joinAny() { | ||
require(isNotEmpty()) | ||
select { forEach { it.onJoin { } } } | ||
} |
75 changes: 75 additions & 0 deletions
75
coroutines/src/commonTest/kotlin/com/huanshankeji/kotlinx/coroutine/AwaitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.huanshankeji.kotlinx.coroutine | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.* | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class AwaitTest { | ||
@Test | ||
fun simplyTestAwaitAnyAndJoinAny() = runTest { | ||
val mutex = Mutex() | ||
mutex.withLock { | ||
fun asyncOf(value: Int) = async { value } | ||
fun asyncSuspendUtilEnd() = async { mutex.withLock { } } | ||
|
||
fun deferredArray0() = arrayOf(asyncOf(0), asyncSuspendUtilEnd()) | ||
fun deferredArray1() = arrayOf(asyncSuspendUtilEnd(), asyncOf(1)) | ||
assertEquals(0, awaitAny(*deferredArray0())) | ||
assertEquals(1, awaitAny(*deferredArray1())) | ||
assertEquals(0, deferredArray0().asList().awaitAny()) | ||
assertEquals(1, deferredArray1().asList().awaitAny()) | ||
|
||
|
||
val deffereds = deferredArray0() | ||
assertFalse(deffereds[1].isCancelled) | ||
assertEquals(0, deffereds.asList().awaitAnyAndCancelOthers()) | ||
assertTrue(deffereds[1].isCancelled) | ||
|
||
|
||
var value: Int? | ||
|
||
fun launchSetOf(newValue: Int) = launch { value = newValue } | ||
fun launchSuspendUtilEndAndSetOf(newValue: Int) = launch { | ||
mutex.withLock { } | ||
value = newValue | ||
} | ||
|
||
fun jobArray0() = arrayOf(launchSetOf(0), launchSuspendUtilEndAndSetOf(1)) | ||
fun jobArray1() = arrayOf(launchSuspendUtilEndAndSetOf(0), launchSetOf(1)) | ||
|
||
value = null | ||
joinAny(*jobArray0()) | ||
assertEquals(0, value) | ||
|
||
value = null | ||
joinAny(*jobArray1()) | ||
assertEquals(1, value) | ||
|
||
value = null | ||
jobArray0().asList().joinAny() | ||
assertEquals(0, value) | ||
|
||
value = null | ||
jobArray1().asList().joinAny() | ||
assertEquals(1, value) | ||
} | ||
} | ||
|
||
private inline fun assertFailsWithIae(block: () -> Unit) = | ||
assertFailsWith<IllegalArgumentException>(block = block) | ||
|
||
@Test | ||
fun simplyTestAwaitAnyAndJoinAnyWithNoTarget() = runTest { | ||
val emptyList = emptyList<Nothing>() | ||
assertFailsWithIae { awaitAny() } | ||
assertFailsWithIae { emptyList.awaitAny() } | ||
assertFailsWithIae { emptyList.awaitAnyAndCancelOthers() } | ||
assertFailsWithIae { joinAny() } | ||
assertFailsWithIae { emptyList.joinAny() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import com.huanshankeji.cpnProject | ||
|
||
plugins { | ||
id("jvm-conventions") | ||
} | ||
|
||
dependencies { | ||
implementation(commonDependencies.exposed.core()) | ||
|
||
implementation(cpnProject(project, ":core")) | ||
} |
93 changes: 0 additions & 93 deletions
93
exposed/src/main/kotlin/com/huanshankeji/exposed/SimpleOrm.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.