|
|
@@ -19,11 +19,13 @@ import kotlin.jvm.JvmOverloads
|
|
|
/**
|
|
|
* Collect all the elements into a [MutableList] then cast it as a [List]
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> LockFreeLinkedList<E>.toList(): List<E> = toMutableList()
|
|
|
|
|
|
/**
|
|
|
* Collect all the elements into a [MutableList].
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
|
|
|
val list = mutableListOf<E>()
|
|
|
this.forEach { list.add(it) }
|
|
|
@@ -33,11 +35,13 @@ fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
|
|
|
/**
|
|
|
* Collect all the elements into a [MutableSet] then cast it as a [Set]
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> LockFreeLinkedList<E>.toSet(): Set<E> = toMutableSet()
|
|
|
|
|
|
/**
|
|
|
* Collect all the elements into a [MutableSet].
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
|
|
|
val list = mutableSetOf<E>()
|
|
|
this.forEach { list.add(it) }
|
|
|
@@ -49,6 +53,7 @@ fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
|
|
|
*
|
|
|
* Note that the sequence is dynamic, that is, elements are yielded atomically only when it is required
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
|
|
|
return sequence {
|
|
|
forEach {
|
|
|
@@ -57,6 +62,7 @@ fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+@MiraiInternalAPI
|
|
|
operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
|
|
|
return asSequence().iterator()
|
|
|
}
|
|
|
@@ -64,6 +70,7 @@ operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
|
|
|
/**
|
|
|
* 构建链表结构然后转为 [LockFreeLinkedList]
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
|
|
|
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
|
|
|
}
|
|
|
@@ -71,6 +78,7 @@ fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
|
|
|
/**
|
|
|
* 构建链表结构然后转为 [LockFreeLinkedList]
|
|
|
*/
|
|
|
+@MiraiInternalAPI
|
|
|
fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
|
|
|
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
|
|
|
}
|
|
|
@@ -81,6 +89,8 @@ fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
|
|
|
* Modifying can be performed concurrently.
|
|
|
* Iterating concurrency is guaranteed.
|
|
|
*/
|
|
|
+@PlannedRemoval("1.0.0") // make internal
|
|
|
+@MiraiInternalAPI("This is unstable API and is going to be internal in 1.0.0")
|
|
|
open class LockFreeLinkedList<E> {
|
|
|
@PublishedApi
|
|
|
internal val tail: Tail<E> = Tail()
|