diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt index 86982bd0..8887a6e2 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt @@ -145,11 +145,12 @@ class PTree(val root: String = ".ε", val branches: List<Π2A> = listOf() } fun sampleStrWithoutReplacement(stride: Int = 1, offset: Int = 0): Sequence = - if (totalTrees.bitLength() < 5) sequence { + if (6 < totalTrees.bitLength()) + bigLFSRSequence(totalTrees).mapIndexedNotNull { index, i -> if (index % stride == offset) newDecoder(i) else null } + else sequence { var i = BigInteger.ZERO while (i < totalTrees) { yield(newDecoder(i)); i++} - } else bigLFSRSequence(totalTrees) - .mapIndexedNotNull { index, i -> if (index % stride == offset) newDecoder(i) else null } + } fun sampleStrWithPCFG5(pcfgTable: Map): Sequence = sequence { while (true) yield(samplePCFG5(pcfgTable)) } diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt index 293476ff..8b5fb0af 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt @@ -297,7 +297,7 @@ class BigLFSR(primitivePoly: BigInteger, val start: BigInteger = BigInteger.ONE) val shiftedOutA1: Boolean = last.bitAt(0) next = last.shr(1) if (shiftedOutA1) { next = next.xor(taps) } - if (next == start) break else yield(next) + if (next == start) { yield(BigInteger.ZERO); break } else yield(next) last = next } }