Fixes github #7533 (#7539)

* Fixes #7533

Fixes problem with SparseIntVect and SparseBitVect where the intention is to
be able to store all possible values of the index type: in these cases
you could not store (or access) the final element.

* increase the verbosity of the DataStructs tests
so that we can see what's going on
This commit is contained in:
Greg Landrum
2024-06-20 09:27:27 +02:00
committed by GitHub
parent 3a8199e4ca
commit d3061b03ef
7 changed files with 72 additions and 20 deletions

View File

@@ -1,6 +1,5 @@
// $Id$
//
// Copyright (c) 2001-2008 greg Landrum and Rational Discovery LLC
// Copyright (c) 2001-2024 greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
@@ -14,7 +13,6 @@
#include "base64.h"
#include <RDGeneral/StreamOps.h>
#include <sstream>
#include <limits>
#ifdef WIN32
#include <ios>
@@ -150,7 +148,7 @@ SparseBitVect SparseBitVect::operator~() const {
//
// """ -------------------------------------------------------
bool SparseBitVect::getBit(const unsigned int which) const {
if (which >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(which);
}
return dp_bits->count(which) > 0u;
@@ -163,7 +161,7 @@ bool SparseBitVect::getBit(const unsigned int which) const {
//
// """ -------------------------------------------------------
bool SparseBitVect::getBit(const IntVectIter which) const {
if (*which < 0 || static_cast<unsigned int>(*which) >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(*which);
}
return dp_bits->count(*which) > 0u;
@@ -176,7 +174,7 @@ bool SparseBitVect::getBit(const IntVectIter which) const {
//
// """ -------------------------------------------------------
bool SparseBitVect::getBit(const IntSetIter which) const {
if (*which < 0 || static_cast<unsigned int>(*which) >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(*which);
}
return dp_bits->count(*which) > 0u;
@@ -193,11 +191,10 @@ bool SparseBitVect::setBit(const unsigned int which) {
if (!dp_bits) {
throw ValueErrorException("BitVect not properly initialized.");
}
std::pair<IntSetIter, bool> res;
if (which >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(which);
}
res = dp_bits->insert(which);
auto res = dp_bits->insert(which);
return !(res.second);
}
@@ -213,11 +210,10 @@ bool SparseBitVect::setBit(const IntSetIter which) {
if (!dp_bits) {
throw ValueErrorException("BitVect not properly initialized.");
}
std::pair<IntSetIter, bool> res;
if (*which < 0 || static_cast<unsigned int>(*which) >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(*which);
}
res = dp_bits->insert(*which);
auto res = dp_bits->insert(*which);
return !(res.second);
}
@@ -232,7 +228,7 @@ bool SparseBitVect::unsetBit(const unsigned int which) {
if (!dp_bits) {
throw ValueErrorException("BitVect not properly initialized.");
}
if (which >= d_size) {
if (!checkIndex(which)) {
throw IndexErrorException(which);
}