Итак, для этого кода я использую массив списков ссылок и хеш-функцию, чтобы определить, в какой «корзину» и элемент следует войти. Набор представляет собой шаблон и может хранить любой тип. Когда я запускаю свой код с помощью SetType_Tests, я получаю следующее: Ошибка: фатальная ошибка, затем процесс завершается с кодом завершения 139 (прерван сигналом 11:SIGSEGV)
Я новичок в отладке, когда запускаю в отладчике я получаю следующее:
//highlights this: __node_pointer __next = __p->__next_; then
4 Exception = EXC_BAD_ACCESS (code=1, address=0x6bbc8eb0)
= this = {std::
_forward_list_base *} 0x16bbc8c10
_before_begin_ = {std:: compressed_pair}
≥ std:: 1::
_compressed_pair_elem numElems){
throw IteratorOutOfBounds();
}
while(bucketIter == buckets[currBucket].end()){
currBucket++;
bucketIter = buckets[currBucket].begin();
}
item = *bucketIter;
bucketIter++;
iterCount++;
return item;
}
template
double SetType::LoadFactor() const {
return static_cast (numElems) / numBuckets;
}
template
SetType::SetType(SetType& other) {
copySet(other);
}
template
void SetType::Rehash(int newNumBuckets) {
SetType rehashedSet(newNumBuckets);
for(int i = 0; i < numBuckets; i++){
for(auto &elem : buckets){
rehashedSet.Add(elem);
}
}
*this = rehashedSet;
}
template
void SetType::copySet(const SetType &otherSet) {
MakeEmpty();
numBuckets = otherSet.numBuckets;
maxLoad = otherSet.maxLoad;
buckets = new forward_list[numBuckets];
for(int i = 0; i < numBuckets; i++){
for(auto &elem : otherSet.buckets){
Add(elem);
}
}
}
template
int SetType::GetHashIndex(const T& key) {
unordered_map mapper;
typename unordered_map::hasher hashFunction = mapper.hash_function();
return static_cast(hashFunction(key) % numBuckets);
}
template
void SetType::SetMaxLoad(double max) {
if (max < 0.1)
maxLoad = 0.1;
else
maxLoad = max;
}
//Test failing:
SECTION("Overload Add/Remove Tests") {
SetType testSet;
// Add all numbers 0 - 99
for (int i = 0; i < 100; i++) {
testSet = testSet+i;
}
// Remove all odd numbers
for (int i = 1; i < 100; i += 2) {
testSet = testSet-i;
}
// Check to make sure even numbers are there
for (int i = 0; i < 100; i+=2) {
//REQUIRE(testSet.Contains(i));
if (!testSet.Contains(i)) {
INFO("testSet should contain "
Подробнее здесь: https://stackoverflow.com/questions/783 ... -my-c-test