Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Kotlin 1.9.22 #621

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions .detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ style:
- reason: 'Kotlin does not support @Inherited annotation, see https://youtrack.jetbrains.com/issue/KT-22265'
value: 'java.lang.annotation.Inherited'
ForbiddenComment:
active: true
active: false
comments:
- reason: 'Forbidden FIXME todo marker in comment, please fix the problem.'
value: 'FIXME:'
Expand Down Expand Up @@ -662,8 +662,6 @@ style:
active: true
OptionalUnit:
active: false
OptionalWhenBraces:
active: false
PreferToOverPairSyntax:
active: false
ProtectedMemberInFinalClass:
Expand Down
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[*.{kt,kts}]
indent_size=4
indent_size = 4
max_line_length = 120
4 changes: 2 additions & 2 deletions .github/workflows/test-extensively.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ windows-2022, macos-12, ubuntu-22.04 ]
java-version: [11, 17, 19]
java-version: [11, 17, 21]
jdk-dist:
- adopt-hotspot
- temurin
Expand Down Expand Up @@ -40,8 +40,8 @@ jobs:
node-version:
- 'latest-16'
- 'latest-18'
- 'latest-19'
- 'latest-20'
- 'latest-21'
runs-on: ${{ matrix.os }}
env:
ORG_GRADLE_PROJECT_nodeVersion: ${{ matrix.node-version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ interface BinaryDecisionDiagram<T : Comparable<T>> {
fun <E : Comparable<E>> variableOf(
value: E,
low: BinaryDecisionDiagram<E>,
high: BinaryDecisionDiagram<E>
high: BinaryDecisionDiagram<E>,
): BinaryDecisionDiagram<E> = BinaryDecisionDiagramBuilder.defaultOf<E>().buildVariable(value, low, high)

/** Creates a new [Terminal] node from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import kotlin.js.JsName
* @author Jason Dellaluce
*/
interface BinaryDecisionDiagramBuilder<T : Comparable<T>> {

/**
* Returns an instance of [BinaryDecisionDiagram.Variable] with
* the provided input.
* */
@JsName("buildVariable")
fun buildVariable(value: T, low: BinaryDecisionDiagram<T>, high: BinaryDecisionDiagram<T>): BinaryDecisionDiagram<T>
fun buildVariable(
value: T,
low: BinaryDecisionDiagram<T>,
high: BinaryDecisionDiagram<T>,
): BinaryDecisionDiagram<T>

/**
* Returns an instance of [BinaryDecisionDiagram.Terminal] with
Expand Down Expand Up @@ -68,7 +71,7 @@ interface BinaryDecisionDiagramBuilder<T : Comparable<T>> {
* */
@JsName("reducedOf")
fun <E : Comparable<E>> reducedOf(
delegate: BinaryDecisionDiagramBuilder<E> = defaultOf()
delegate: BinaryDecisionDiagramBuilder<E> = defaultOf(),
): BinaryDecisionDiagramBuilder<E> {
return ReducedBinaryDecisionDiagramBuilder(delegate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import kotlin.jvm.JvmName
* Decision Diagram (ROBDD).
* */
@JsName("applyUnary")
fun <T : Comparable<T>> BinaryDecisionDiagram<T>.apply(
unaryOp: (Boolean) -> Boolean
): BinaryDecisionDiagram<T> {
fun <T : Comparable<T>> BinaryDecisionDiagram<T>.apply(unaryOp: (Boolean) -> Boolean): BinaryDecisionDiagram<T> {
return runOperationAndCatchErrors {
this.applyThenExpansion(
unaryOp,
0,
0
0,
) { _, _, _ -> 0 }
}.first
}
Expand All @@ -37,14 +35,14 @@ fun <T : Comparable<T>> BinaryDecisionDiagram<T>.apply(
@JsName("applyBinary")
fun <T : Comparable<T>> BinaryDecisionDiagram<T>.apply(
that: BinaryDecisionDiagram<T>,
binaryOp: (Boolean, Boolean) -> Boolean
binaryOp: (Boolean, Boolean) -> Boolean,
): BinaryDecisionDiagram<T> {
return runOperationAndCatchErrors {
this.applyThenExpansion(
that,
binaryOp,
0,
0
0,
) { _, _, _ -> 0 }
}.first
}
Expand All @@ -65,7 +63,7 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(
unaryOp: (Boolean) -> Boolean,
expansionFalseTerminal: E,
expansionTrueTerminal: E,
expansionOperator: (node: T, low: E, high: E) -> E
expansionOperator: (node: T, low: E, high: E) -> E,
): Pair<BinaryDecisionDiagram<T>, E> {
return runOperationAndCatchErrors {
this.accept(
Expand All @@ -74,8 +72,8 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(
unaryOp,
expansionFalseTerminal,
expansionTrueTerminal,
expansionOperator
)
expansionOperator,
),
)
}
}
Expand All @@ -97,7 +95,7 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(
binaryOp: (Boolean, Boolean) -> Boolean,
expansionFalseTerminal: E,
expansionTrueTerminal: E,
expansionOperator: (node: T, low: E, high: E) -> E
expansionOperator: (node: T, low: E, high: E) -> E,
): Pair<BinaryDecisionDiagram<T>, E> {
return runOperationAndCatchErrors {
this.accept(
Expand All @@ -107,8 +105,8 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(
binaryOp,
expansionFalseTerminal,
expansionTrueTerminal,
expansionOperator
)
expansionOperator,
),
)
}
}
Expand Down Expand Up @@ -139,14 +137,14 @@ fun <T : Comparable<T>> BinaryDecisionDiagram<T>.not(): BinaryDecisionDiagram<T>
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.notThenExpansion(
expansionFalseTerminal: E,
expansionTrueTerminal: E,
expansionOperator: (node: T, low: E, high: E) -> E
expansionOperator: (node: T, low: E, high: E) -> E,
): Pair<BinaryDecisionDiagram<T>, E> {
return runOperationAndCatchErrors {
this.applyThenExpansion(
{ a -> !a },
expansionFalseTerminal,
expansionTrueTerminal,
expansionOperator
expansionOperator,
)
}
}
Expand All @@ -157,9 +155,7 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.notThenExpansion(
* Decision Diagram (ROBDD).
*/
@JsName("and")
infix fun <T : Comparable<T>> BinaryDecisionDiagram<T>.and(
that: BinaryDecisionDiagram<T>
): BinaryDecisionDiagram<T> {
infix fun <T : Comparable<T>> BinaryDecisionDiagram<T>.and(that: BinaryDecisionDiagram<T>): BinaryDecisionDiagram<T> {
return runOperationAndCatchErrors {
this.apply(that) { a, b -> a && b }
}
Expand All @@ -181,15 +177,15 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.andThenExpansion(
that: BinaryDecisionDiagram<T>,
expansionFalseTerminal: E,
expansionTrueTerminal: E,
expansionOperator: (node: T, low: E, high: E) -> E
expansionOperator: (node: T, low: E, high: E) -> E,
): Pair<BinaryDecisionDiagram<T>, E> {
return runOperationAndCatchErrors {
this.applyThenExpansion(
that,
{ a, b -> a && b },
expansionFalseTerminal,
expansionTrueTerminal,
expansionOperator
expansionOperator,
)
}
}
Expand All @@ -199,9 +195,7 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.andThenExpansion(
* The result is a Reduced Ordered Binary Decision Diagram (ROBDD).
*/
@JsName("or")
infix fun <T : Comparable<T>> BinaryDecisionDiagram<T>.or(
that: BinaryDecisionDiagram<T>
): BinaryDecisionDiagram<T> {
infix fun <T : Comparable<T>> BinaryDecisionDiagram<T>.or(that: BinaryDecisionDiagram<T>): BinaryDecisionDiagram<T> {
return runOperationAndCatchErrors {
this.apply(that) { a, b -> a || b }
}
Expand All @@ -223,15 +217,15 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.orThenExpansion(
that: BinaryDecisionDiagram<T>,
expansionFalseTerminal: E,
expansionTrueTerminal: E,
expansionOperator: (node: T, low: E, high: E) -> E
expansionOperator: (node: T, low: E, high: E) -> E,
): Pair<BinaryDecisionDiagram<T>, E> {
return runOperationAndCatchErrors {
this.applyThenExpansion(
that,
{ a, b -> a || b },
expansionFalseTerminal,
expansionTrueTerminal,
expansionOperator
expansionOperator,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import kotlin.jvm.JvmName
* Shortcut for the [BinaryDecisionDiagram.variableOf] method.
*/
@JsName("bddOf")
fun <T : Comparable<T>> bddOf(value: T): BinaryDecisionDiagram<T> =
BinaryDecisionDiagram.variableOf(value)
fun <T : Comparable<T>> bddOf(value: T): BinaryDecisionDiagram<T> = BinaryDecisionDiagram.variableOf(value)

/**
* Shortcut for the [BinaryDecisionDiagram.terminalOf] method.
*/
@JsName("bddTerminalOf")
fun <T : Comparable<T>> bddTerminalOf(
value: Boolean
): BinaryDecisionDiagram<T> = BinaryDecisionDiagram.terminalOf(value)
fun <T : Comparable<T>> bddTerminalOf(value: Boolean): BinaryDecisionDiagram<T> =
BinaryDecisionDiagram.terminalOf(value)

/** Internal helper function to catch all exceptions and wrap them into
* BBD-specific ones. */
Expand All @@ -35,7 +33,7 @@ internal fun <T> runOperationAndCatchErrors(action: () -> T): T {
} catch (e: Throwable) {
throw BinaryDecisionDiagramOperationException(
"BinaryDecisionDiagram operation failure",
e
e,
)
}
}
Expand All @@ -50,15 +48,15 @@ internal fun <T> runOperationAndCatchErrors(action: () -> T): T {
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.expansion(
falseTerminal: E,
trueTerminal: E,
operator: (node: T, low: E, high: E) -> E
operator: (node: T, low: E, high: E) -> E,
): E {
return runOperationAndCatchErrors {
this.accept(
ExpansionVisitor(
operator,
falseTerminal,
trueTerminal
)
trueTerminal,
),
)
}
}
Expand All @@ -68,9 +66,7 @@ fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.expansion(
* element matching the given predicate.
*/
@JsName("anyWhere")
fun <T : Comparable<T>> BinaryDecisionDiagram<T>.any(
predicate: (T) -> Boolean
): Boolean {
fun <T : Comparable<T>> BinaryDecisionDiagram<T>.any(predicate: (T) -> Boolean): Boolean {
return runOperationAndCatchErrors {
this.accept(AnyVisitor(predicate))
}
Expand All @@ -92,14 +88,12 @@ fun <T : Comparable<T>> BinaryDecisionDiagram<T>.any(): Boolean {
* The internal structure of the diagram is maintained.
*/
@JsName("map")
fun <T : Comparable<T>, E : Comparable<E>> BinaryDecisionDiagram<T>.map(
mapper: (T) -> E
): BinaryDecisionDiagram<E> {
fun <T : Comparable<T>, E : Comparable<E>> BinaryDecisionDiagram<T>.map(mapper: (T) -> E): BinaryDecisionDiagram<E> {
val builder = BinaryDecisionDiagramBuilder.reducedOf<E>()
return runOperationAndCatchErrors {
this.expansion(
builder.buildTerminal(false),
builder.buildTerminal(true)
builder.buildTerminal(true),
) { node, low, high -> builder.buildVariable(mapper(node), low, high) }
}
}
Expand All @@ -124,7 +118,7 @@ fun <T : Comparable<T>> BinaryDecisionDiagram<T>.toDotString(): String {
val nodeValue = Triple(node, low, high).hashCode()
if (nodeValue !in checkSet) {
labelBuilder.append(
"$nodeValue [shape=record, label=\"$node\"]\n"
"$nodeValue [shape=record, label=\"$node\"]\n",
)
graphBuilder.append("$nodeValue -> $low [style=dashed]\n")
graphBuilder.append("$nodeValue -> $high\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlin.js.JsName
* @author Jason Dellaluce
*/
interface BinaryDecisionDiagramVisitor<T : Comparable<T>, E> {

companion object

@JsName("visitTerminal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import kotlin.jvm.JvmOverloads
* @param message the detail message string.
* @param cause the cause of this exception.
*/
open class BinaryDecisionDiagramException @JvmOverloads constructor(
override val message: String? = null,
override val cause: Throwable? = null
) : RuntimeException(message, cause)
open class BinaryDecisionDiagramException
@JvmOverloads
constructor(
override val message: String? = null,
override val cause: Throwable? = null,
) : RuntimeException(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import kotlin.jvm.JvmOverloads
* @param message the detail message string.
* @param cause the cause of this exception.
*/
class BinaryDecisionDiagramOperationException @JvmOverloads constructor(
message: String?,
cause: Throwable? = null
) : BinaryDecisionDiagramException(message, cause)
class BinaryDecisionDiagramOperationException
@JvmOverloads
constructor(
message: String?,
cause: Throwable? = null,
) : BinaryDecisionDiagramException(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import it.unibo.tuprolog.bdd.BinaryDecisionDiagramVisitor
* @author Jason Dellaluce
*/
internal class AnyVisitor<T : Comparable<T>>(
private val predicate: (T) -> Boolean
private val predicate: (T) -> Boolean,
) : BinaryDecisionDiagramVisitor<T, Boolean> {

override fun visit(
node: BinaryDecisionDiagram.Terminal<T>
): Boolean = false
override fun visit(node: BinaryDecisionDiagram.Terminal<T>): Boolean = false

override fun visit(node: BinaryDecisionDiagram.Variable<T>): Boolean {
var result = predicate(node.value)
Expand Down
Loading
Loading