blob: 2c2679bcad61c77d15959905bdc6b6ff1a1cf17c [file] [log] [blame]
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress(
"RedundantVisibilityModifier",
"KotlinRedundantDiagnosticSuppress",
"KotlinConstantConditions",
"PropertyName",
"ConstPropertyName",
"PrivatePropertyName",
"NOTHING_TO_INLINE",
"UnusedImport",
)
package PACKAGE
import androidx.collection.PRIMITIVESet
import androidx.collection.MutablePRIMITIVESet
import androidx.collection.emptyPRIMITIVESet
import androidx.collection.mutablePRIMITIVESetOf
import VALUE_PKG.VALUE_CLASS
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DO NOT MAKE CHANGES to this kotlin source file.
//
// This file was generated from a template:
// collection/collection/template/ValueClassSet.kt.template
// Make a change to the original template and run the generateValueClassCollections.sh script
// to ensure the change is available on all versions of the set.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* Returns an empty, read-only [VALUE_CLASSSet].
*/
VISIBILITY inline fun emptyVALUE_CLASSSet(): VALUE_CLASSSet = VALUE_CLASSSet(emptyPRIMITIVESet())
/**
* Returns an empty, read-only [VALUE_CLASSSet].
*/
VISIBILITY inline fun vALUE_CLASSSetOf(): VALUE_CLASSSet = VALUE_CLASSSet(emptyPRIMITIVESet())
/**
* Returns a new read-only [VALUE_CLASSSet] with only [element1] in it.
*/
VISIBILITY inline fun vALUE_CLASSSetOf(element1: VALUE_CLASS): VALUE_CLASSSet =
VALUE_CLASSSet(mutablePRIMITIVESetOf(element1.BACKING_PROPERTY))
/**
* Returns a new read-only [VALUE_CLASSSet] with only [element1] and [element2] in it.
*/
@Suppress("UNCHECKED_CAST")
VISIBILITY fun vALUE_CLASSSetOf(
element1: VALUE_CLASS,
element2: VALUE_CLASS
): VALUE_CLASSSet =
VALUE_CLASSSet(
mutablePRIMITIVESetOf(
element1.BACKING_PROPERTY,
element2.BACKING_PROPERTY,
)
)
/**
* Returns a new read-only [VALUE_CLASSSet] with only [element1], [element2], and [element3] in it.
*/
@Suppress("UNCHECKED_CAST")
VISIBILITY fun vALUE_CLASSSetOf(
element1: VALUE_CLASS,
element2: VALUE_CLASS,
element3: VALUE_CLASS
): VALUE_CLASSSet = VALUE_CLASSSet(
mutablePRIMITIVESetOf(
element1.BACKING_PROPERTY,
element2.BACKING_PROPERTY,
element3.BACKING_PROPERTY,
)
)
/**
* Returns a new [MutableVALUE_CLASSSet].
*/
VISIBILITY fun mutableVALUE_CLASSSetOf(): MutableVALUE_CLASSSet = MutableVALUE_CLASSSet(
MutablePRIMITIVESet()
)
/**
* Returns a new [MutableVALUE_CLASSSet] with only [element1] in it.
*/
VISIBILITY fun mutableVALUE_CLASSSetOf(element1: VALUE_CLASS): MutableVALUE_CLASSSet =
MutableVALUE_CLASSSet(mutablePRIMITIVESetOf(element1.BACKING_PROPERTY))
/**
* Returns a new [MutableVALUE_CLASSSet] with only [element1] and [element2] in it.
*/
VISIBILITY fun mutableVALUE_CLASSSetOf(
element1: VALUE_CLASS,
element2: VALUE_CLASS
): MutableVALUE_CLASSSet =
MutableVALUE_CLASSSet(
mutablePRIMITIVESetOf(
element1.BACKING_PROPERTY,
element2.BACKING_PROPERTY,
)
)
/**
* Returns a new [MutableVALUE_CLASSSet] with only [element1], [element2], and [element3] in it.
*/
VISIBILITY fun mutableVALUE_CLASSSetOf(
element1: VALUE_CLASS,
element2: VALUE_CLASS,
element3: VALUE_CLASS
): MutableVALUE_CLASSSet =
MutableVALUE_CLASSSet(
mutablePRIMITIVESetOf(
element1.BACKING_PROPERTY,
element2.BACKING_PROPERTY,
element3.BACKING_PROPERTY,
)
)
/**
* [VALUE_CLASSSet] is a container with a [Set]-like interface designed to avoid
* allocations, including boxing.
*
* This implementation makes no guarantee as to the order of the elements,
* nor does it make guarantees that the order remains constant over time.
*
* Though [VALUE_CLASSSet] offers a read-only interface, it is always backed
* by a [MutableVALUE_CLASSSet]. Read operations alone are thread-safe. However,
* any mutations done through the backing [MutableVALUE_CLASSSet] while reading
* on another thread are not safe and the developer must protect the set
* from such changes during read operations.
*
* @see [MutableVALUE_CLASSSet]
*/
@OptIn(ExperimentalContracts::class)
@JvmInline
VISIBILITY value class VALUE_CLASSSet(val set: PRIMITIVESet) {
/**
* Returns the number of elements that can be stored in this set
* without requiring internal storage reallocation.
*/
@get:androidx.annotation.IntRange(from = 0)
public inline val capacity: Int
get() = set.capacity
/**
* Returns the number of elements in this set.
*/
@get:androidx.annotation.IntRange(from = 0)
public inline val size: Int
get() = set.size
/**
* Returns `true` if this set has at least one element.
*/
public inline fun any(): Boolean = set.any()
/**
* Returns `true` if this set has no elements.
*/
public inline fun none(): Boolean = set.none()
/**
* Indicates whether this set is empty.
*/
public inline fun isEmpty(): Boolean = set.isEmpty()
/**
* Returns `true` if this set is not empty.
*/
public inline fun isNotEmpty(): Boolean = set.isNotEmpty()
/**
* Returns the first element in the collection.
* @throws NoSuchElementException if the collection is empty
*/
public inline fun first(): VALUE_CLASS = VALUE_CLASS(set.first()TO_PARAM)
/**
* Returns the first element in the collection for which [predicate] returns `true`.
*
* **Note** There is no mechanism for both determining if there is an element that matches
* [predicate] _and_ returning it if it exists. Developers should use [forEach] to achieve
* this behavior.
*
* @param predicate Called on elements of the set, returning `true` for an element that matches
* or `false` if it doesn't
* @return An element in the set for which [predicate] returns `true`.
* @throws NoSuchElementException if [predicate] returns `false` for all elements or the
* collection is empty.
*/
public inline fun first(predicate: (element: VALUE_CLASS) -> Boolean): VALUE_CLASS =
VALUE_CLASS(set.first { predicate(VALUE_CLASS(itTO_PARAM)) }TO_PARAM)
/**
* Iterates over every element stored in this set by invoking
* the specified [block] lambda.
* @param block called with each element in the set
*/
public inline fun forEach(block: (element: VALUE_CLASS) -> Unit) {
contract { callsInPlace(block) }
set.forEach { block(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns true if all elements match the given [predicate].
* @param predicate called for elements in the set to determine if it returns return `true` for
* all elements.
*/
public inline fun all(predicate: (element: VALUE_CLASS) -> Boolean): Boolean {
contract { callsInPlace(predicate) }
return set.all { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns true if at least one element matches the given [predicate].
* @param predicate called for elements in the set to determine if it returns `true` for any
* elements.
*/
public inline fun any(predicate: (element: VALUE_CLASS) -> Boolean): Boolean {
contract { callsInPlace(predicate) }
return set.any { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns the number of elements in this set.
*/
@androidx.annotation.IntRange(from = 0)
public inline fun count(): Int = set.count()
/**
* Returns the number of elements matching the given [predicate].
* @param predicate Called for all elements in the set to count the number for which it returns
* `true`.
*/
@androidx.annotation.IntRange(from = 0)
public inline fun count(predicate: (element: VALUE_CLASS) -> Boolean): Int {
contract { callsInPlace(predicate) }
return set.count { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns `true` if the specified [element] is present in this set, `false`
* otherwise.
* @param element The element to look for in this set
*/
public inline operator fun contains(element: VALUE_CLASS): Boolean =
set.contains(element.BACKING_PROPERTY)
/**
* Returns a string representation of this set. The set is denoted in the
* string by the `{}`. Each element is separated by `, `.
*/
public override fun toString(): String {
if (isEmpty()) {
return "[]"
}
val s = StringBuilder().append('[')
var index = 0
forEach { element ->
if (index++ != 0) {
s.append(',').append(' ')
}
s.append(element)
}
return s.append(']').toString()
}
}
/**
* [MutableVALUE_CLASSSet] is a container with a [MutableSet]-like interface based on a flat
* hash table implementation. The underlying implementation is designed to avoid
* all allocations on insertion, removal, retrieval, and iteration. Allocations
* may still happen on insertion when the underlying storage needs to grow to
* accommodate newly added elements to the set.
*
* This implementation makes no guarantee as to the order of the elements stored,
* nor does it make guarantees that the order remains constant over time.
*
* This implementation is not thread-safe: if multiple threads access this
* container concurrently, and one or more threads modify the structure of
* the set (insertion or removal for instance), the calling code must provide
* the appropriate synchronization. Concurrent reads are however safe.
*/
@OptIn(ExperimentalContracts::class)
@JvmInline
VISIBILITY value class MutableVALUE_CLASSSet(val set: MutablePRIMITIVESet) {
/**
* Returns the number of elements that can be stored in this set
* without requiring internal storage reallocation.
*/
@get:androidx.annotation.IntRange(from = 0)
public inline val capacity: Int
get() = set.capacity
/**
* Returns the number of elements in this set.
*/
@get:androidx.annotation.IntRange(from = 0)
public inline val size: Int
get() = set.size
/**
* Returns `true` if this set has at least one element.
*/
public inline fun any(): Boolean = set.any()
/**
* Returns `true` if this set has no elements.
*/
public inline fun none(): Boolean = set.none()
/**
* Indicates whether this set is empty.
*/
public inline fun isEmpty(): Boolean = set.isEmpty()
/**
* Returns `true` if this set is not empty.
*/
public inline fun isNotEmpty(): Boolean = set.isNotEmpty()
/**
* Returns the first element in the collection.
* @throws NoSuchElementException if the collection is empty
*/
public inline fun first(): VALUE_CLASS = VALUE_CLASS(set.first()TO_PARAM)
/**
* Returns the first element in the collection for which [predicate] returns `true`.
*
* **Note** There is no mechanism for both determining if there is an element that matches
* [predicate] _and_ returning it if it exists. Developers should use [forEach] to achieve
* this behavior.
*
* @param predicate Called on elements of the set, returning `true` for an element that matches
* or `false` if it doesn't
* @return An element in the set for which [predicate] returns `true`.
* @throws NoSuchElementException if [predicate] returns `false` for all elements or the
* collection is empty.
*/
public inline fun first(predicate: (element: VALUE_CLASS) -> Boolean): VALUE_CLASS =
VALUE_CLASS(set.first { predicate(VALUE_CLASS(itTO_PARAM)) }TO_PARAM)
/**
* Iterates over every element stored in this set by invoking
* the specified [block] lambda.
* @param block called with each element in the set
*/
public inline fun forEach(block: (element: VALUE_CLASS) -> Unit) {
contract { callsInPlace(block) }
set.forEach { block(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns true if all elements match the given [predicate].
* @param predicate called for elements in the set to determine if it returns return `true` for
* all elements.
*/
public inline fun all(predicate: (element: VALUE_CLASS) -> Boolean): Boolean {
contract { callsInPlace(predicate) }
return set.all { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns true if at least one element matches the given [predicate].
* @param predicate called for elements in the set to determine if it returns `true` for any
* elements.
*/
public inline fun any(predicate: (element: VALUE_CLASS) -> Boolean): Boolean {
contract { callsInPlace(predicate) }
return set.any { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns the number of elements in this set.
*/
@androidx.annotation.IntRange(from = 0)
public inline fun count(): Int = set.count()
/**
* Returns the number of elements matching the given [predicate].
* @param predicate Called for all elements in the set to count the number for which it returns
* `true`.
*/
@androidx.annotation.IntRange(from = 0)
public inline fun count(predicate: (element: VALUE_CLASS) -> Boolean): Int {
contract { callsInPlace(predicate) }
return set.count { predicate(VALUE_CLASS(itTO_PARAM)) }
}
/**
* Returns `true` if the specified [element] is present in this set, `false`
* otherwise.
* @param element The element to look for in this set
*/
public inline operator fun contains(element: VALUE_CLASS): Boolean =
set.contains(element.BACKING_PROPERTY)
/**
* Returns a string representation of this set. The set is denoted in the
* string by the `{}`. Each element is separated by `, `.
*/
public override fun toString(): String = asVALUE_CLASSSet().toString()
/**
* Creates a new [MutableVALUE_CLASSSet]
* @param initialCapacity The initial desired capacity for this container.
* The container will honor this value by guaranteeing its internal structures
* can hold that many elements without requiring any allocations. The initial
* capacity can be set to 0.
*/
public constructor(initialCapacity: Int = 6) : this(MutablePRIMITIVESet(initialCapacity))
/**
* Returns a read-only interface to the set.
*/
public inline fun asVALUE_CLASSSet(): VALUE_CLASSSet = VALUE_CLASSSet(set)
/**
* Adds the specified element to the set.
* @param element The element to add to the set.
* @return `true` if the element has been added or `false` if the element is already
* contained within the set.
*/
public inline fun add(element: VALUE_CLASS): Boolean = set.add(element.BACKING_PROPERTY)
/**
* Adds the specified element to the set.
* @param element The element to add to the set.
*/
public inline operator fun plusAssign(element: VALUE_CLASS) =
set.plusAssign(element.BACKING_PROPERTY)
/**
* Adds all the elements in the [elements] set into this set.
* @param elements A [VALUE_CLASSSet] of elements to add to this set.
* @return `true` if any of the specified elements were added to the collection,
* `false` if the collection was not modified.
*/
public inline fun addAll(elements: VALUE_CLASSSet): Boolean = set.addAll(elements.set)
/**
* Adds all the elements in the [elements] set into this set.
* @param elements A [VALUE_CLASSSet] of elements to add to this set.
* @return `true` if any of the specified elements were added to the collection,
* `false` if the collection was not modified.
*/
public inline fun addAll(elements: MutableVALUE_CLASSSet): Boolean = set.addAll(elements.set)
/**
* Adds all the elements in the [elements] set into this set.
* @param elements A [VALUE_CLASSSet] of elements to add to this set.
*/
public inline operator fun plusAssign(elements: VALUE_CLASSSet) =
set.plusAssign(elements.set)
/**
* Adds all the elements in the [elements] set into this set.
* @param elements A [VALUE_CLASSSet] of elements to add to this set.
*/
public inline operator fun plusAssign(elements: MutableVALUE_CLASSSet) =
set.plusAssign(elements.set)
/**
* Removes the specified [element] from the set.
* @param element The element to remove from the set.
* @return `true` if the [element] was present in the set, or `false` if it wasn't
* present before removal.
*/
public inline fun remove(element: VALUE_CLASS): Boolean = set.remove(element.BACKING_PROPERTY)
/**
* Removes the specified [element] from the set if it is present.
* @param element The element to remove from the set.
*/
public inline operator fun minusAssign(element: VALUE_CLASS) =
set.minusAssign(element.BACKING_PROPERTY)
/**
* Removes the specified [elements] from the set, if present.
* @param elements An [VALUE_CLASSSet] of elements to be removed from the set.
* @return `true` if the set was changed or `false` if none of the elements were present.
*/
public inline fun removeAll(elements: VALUE_CLASSSet): Boolean = set.removeAll(elements.set)
/**
* Removes the specified [elements] from the set, if present.
* @param elements An [VALUE_CLASSSet] of elements to be removed from the set.
* @return `true` if the set was changed or `false` if none of the elements were present.
*/
public inline fun removeAll(elements: MutableVALUE_CLASSSet): Boolean =
set.removeAll(elements.set)
/**
* Removes the specified [elements] from the set, if present.
* @param elements An [VALUE_CLASSSet] of elements to be removed from the set.
*/
public inline operator fun minusAssign(elements: VALUE_CLASSSet) =
set.minusAssign(elements.set)
/**
* Removes the specified [elements] from the set, if present.
* @param elements An [VALUE_CLASSSet] of elements to be removed from the set.
*/
public inline operator fun minusAssign(elements: MutableVALUE_CLASSSet) =
set.minusAssign(elements.set)
/**
* Removes all elements from this set.
*/
public inline fun clear() = set.clear()
/**
* Trims this [MutableVALUE_CLASSSet]'s storage so it is sized appropriately
* to hold the current elements.
*
* Returns the number of empty elements removed from this set's storage.
* Returns 0 if no trimming is necessary or possible.
*/
@androidx.annotation.IntRange(from = 0)
public inline fun trim(): Int = set.trim()
}