whats wrong? im getting this assertion: ASSERT: "numBuckets > 0" in file…
- User
whats wrong? im getting this assertion: ASSERT: "numBuckets > 0" in file C:\Qt\6.6.0_static\include\QtCore\qhash.h, line 682 Debug Error!
and when it happens the ciphermap have a size > 65536
template <typename T, size_t Prealloc = 32> class QDuplicateTracker { class SimpleCipher { public:
SimpleCipher() { initializeCipherMap(); } QString encode(const QString& input) const { QString result; for (const QChar& ch : input) { result.append(cipherMap.value(ch, ch)); } return result; } private: QHash<QChar, QChar> cipherMap; void initializeCipherMap() { // Create a QVector of all possible QChars QVector<QChar> allChars; allChars.reserve(65536); // Pre-allocate space for efficiency for (int i = 0; i < 65536; ++i) { allChars.append(QChar(i)); } // Make an independent copy for shuffling QVector<QChar> shuffled = allChars; // Shuffle the vector using a random engine std::random_device rd; std::mt19937 g(rd()); std::shuffle(shuffled.begin(), shuffled.end(), g); // Build the cipher map for (int i = 0; i < allChars.size(); ++i) { cipherMap.insert(allChars[i], shuffled[i]); } } }; SimpleCipher cipher;#ifdef __cpp_lib_memory_resource template struct QHasher { size_t storedSeed = QHashSeed::globalSeed(); size_t operator()(const HT& t) const { return QHashPrivate::calculateHash(t, storedSeed); } };
struct node_guesstimate { void* next; size_t hash; T value; }; static constexpr size_t bufferSize(size_t N) { return N * sizeof(void*) // bucket list + N * sizeof(node_guesstimate); // nodes } char buffer[bufferSize(Prealloc)]; std::pmr::monotonic_buffer_resource res{ buffer, sizeof buffer }; std::pmr::unordered_set<T, QHasher<T>> set{ Prealloc, &res };#else class Set : public QSet { qsizetype setSize = 0; public: explicit Set(qsizetype n) : QSet{} { this->reserve(n); }
auto insert(const T& e) { auto it = QSet<T>::insert(e); const auto n = this->size(); return std::pair{ it, std::exchange(setSize, n) != n }; } auto insert(T&& e) { auto it = QSet<T>::insert(std::move(e)); const auto n = this->size(); return std::pair{ it, std::exchange(setSize, n) != n }; } }; Set set{ Prealloc };#endif Q_DISABLE_COPY_MOVE(QDuplicateTracker); public: static constexpr inline bool uses_pmr = #ifdef __cpp_lib_memory_resource true #else false #endif ; QDuplicateTracker() = default; explicit QDuplicateTracker(qsizetype n) #ifdef __cpp_lib_memory_resource : set{ size_t(n), &res } #else : set{ n } #endif { } Q_DECL_DEPRECATED_X("Pass the capacity to reserve() to the ctor instead.") void reserve(qsizetype n) { set.reserve(n); } [[nodiscard]] bool hasSeen(const T& s) { T t = cipher.encode(s); return !set.insert(t).second; } [[nodiscard]] bool hasSeen(T&& s) { return !set.insert(std::move(s)).second; }
- Assistant