Scoop API

scoop:scoop.std:0.1.0

src/collections/element_buffer.scoop

Selected production source · src/collections/element_buffer.scoop

1package scoop.collections
3internal fun expandedCollectionCapacity(capacity: Long): Long {
4 if (capacity == 9223372036854775807L) throw IllegalStateException(Some("collection capacity exhausted"))
5 return if (capacity == 0L) 8L else if (capacity > 4611686018427387903L) 9223372036854775807L else capacity * 2L
6}
8internal class ElementBuffer<T> internal constructor(capacity: Long) {
9 private val elements: MutableArray<MaybeUninit<T>> =
10 MutableArray<MaybeUninit<T>>(capacity) { _ -> MaybeUninit<T>.uninit() }
11 internal val capacity: Long get() = elements.size
13 internal fun read(index: Long): T {
14 @Unsafe { return elements[index].assumeInit() }
15 }
17 internal fun write(index: Long, value: T) { elements[index] = MaybeUninit<T>.initialized(value) }
18 internal fun erase(index: Long) { elements[index] = MaybeUninit<T>.uninit() }