Merge branch 'refs/heads/0.22.0' into bpavuk.tests

# Conflicts:
#	CHANGELOG.md
#	gradle.properties
This commit is contained in:
bpavuk
2024-08-02 22:52:29 +03:00
40 changed files with 4976 additions and 2947 deletions

View File

@@ -24,7 +24,9 @@ class ReadMapKeyValueRepo<Key, Value>(
) : ReadKeyValueRepo<Key, Value> {
constructor(map: Map<Key, Value> = emptyMap()) : this(map, SmartRWLocker())
override suspend fun get(k: Key): Value? = locker.withReadAcquire { map[k] }
override suspend fun get(k: Key): Value? = locker.withReadAcquire {
map[k]
}
override suspend fun values(
pagination: Pagination,

View File

@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.SmartRWLocker
import dev.inmo.micro_utils.coroutines.withReadAcquire
import dev.inmo.micro_utils.coroutines.withWriteLock
import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.optionallyReverse
import dev.inmo.micro_utils.pagination.utils.paginate
import dev.inmo.micro_utils.pagination.utils.reverse
import kotlinx.coroutines.flow.*
@@ -33,6 +34,20 @@ class MapReadKeyValuesRepo<Key, Value>(
)
}
override suspend fun getAll(k: Key, reversed: Boolean): List<Value> {
return locker.withReadAcquire { map[k] ?.optionallyReverse(reversed) ?: return emptyList() }
}
override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> {
return locker.withReadAcquire {
if (reverseLists) {
map.mapValues { it.value.reversed() }
} else {
map.toMap()
}
}
}
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key> {
val keys = locker.withReadAcquire {
map.keys
@@ -108,6 +123,19 @@ class MapWriteKeyValuesRepo<Key, Value>(
}
}
override suspend fun set(toSet: Map<Key, List<Value>>) {
locker.withWriteLock {
map.putAll(
toSet.mapValues { it.value.toMutableList() }
)
}
toSet.forEach { (k, v) ->
v.forEach {
_onNewValue.emit(k to it)
}
}
}
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
val removed = mutableListOf<Pair<Key, Value>>()
val cleared = mutableListOf<Key>()