From 706ef6d3bc74ab26d5c2b9ec9c3d5659400f9025 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Fri, 17 Apr 2026 16:55:53 +0200 Subject: [PATCH] :bug: Changed the indices sampling logic to use lists to prevent duplicate clauses. --- lib/kcnf.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/kcnf.cpp b/lib/kcnf.cpp index f8b0200..66346e4 100644 --- a/lib/kcnf.cpp +++ b/lib/kcnf.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #ifdef _OPENMP @@ -50,18 +51,18 @@ std::vector unrank_combination(long n, long k, long long idx) { // sample c indices in [0,total] for our c = # of clauses // this is the heart of the program as we are flattening the problem with our sampled indices and the unrank function! std::vector sample_indices(long long total, long c) { - std::vector idx; - idx.reserve(c); + std::unordered_set set; + set.reserve(c); std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution dist(0, total - 1); - for (long i = 0; i < c; i++) { - idx.push_back(dist(gen)); + while ((long)set.size() < c) { + set.insert(dist(gen)); } - return idx; + return std::vector(set.begin(), set.end()); } // decode one clause from global index (think of it like a hash function for better understanding!)