Итак, для этого кода я использую массив списков ссылок и хеш-функцию, чтобы определить, в какой «корзину» и элемент следует войти. Набор представляет собой шаблон и может хранить любой тип. Когда я запускаю свой код с помощью 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
Почему я получаю ошибку SIGSEGV в тесте C++? ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1713271214
Anonymous
Итак, для этого кода я использую массив списков ссылок и хеш-функцию, чтобы определить, в какой «корзину» и элемент следует войти. Набор представляет собой шаблон и может хранить любой тип. Когда я запускаю свой код с помощью 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[i]){
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[i]){
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 "
Подробнее здесь: [url]https://stackoverflow.com/questions/78334543/why-am-i-getting-a-sigsegv-error-in-my-c-test[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия