-
Notifications
You must be signed in to change notification settings - Fork 0
Домашняя работа 5 Cpp (STL-совместимый контейнер) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично сделал все пункты, даже итерация за О(1) есть.
Какая-то беда с отступами. Нужно их поправить и убрать лишние комментарии. Если линтер это пропускает, наверное, с ним что-то не так.
Подпиши работу в ридми. Требовать работу с твоей библиотекой в меин не буду.
Расскажи свои соображения по поводу линковки через include в конце файла тут.
Ты правильно декомпозировал .h, хотя обычно в случае с шаблонными классами, этого не требуют. Я лишь укажу на то, что set_definition.h по сути является отдельным классом авл-дерева, который, например, ты бы мог использовать отдельно. Обычно, сет - обертка над чистым деревом, т.е. содержит stl container AVL-tree своим полем.
можешь написать тесты на замер асимптотики или хотя бы сравнительный тест на время работы
Добавь преподавателя, как исправишь разметку
| # techopark_cpp_hw | ||
| Репозиторий для сдачи домашних работ по С++ в Технопарке | ||
|
|
||
| **STL-совместимый контейнер** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавь само задание в ридми, подпиши работу
| template <typename T, typename Comparator> | ||
| void TestInsertErase(Set<T, Comparator> &set, std::istream &in) | ||
| { | ||
| char op; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что-то странное с отступами
| #include "iterator.h" | ||
|
|
||
| template <typename T, typename Comparator> | ||
| void TestInsertErase(Set<T, Comparator> &set, std::istream &in) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
круто сделал с потоком
tests/test_set.cpp
Outdated
| }); | ||
| EXPECT_EQ(count, 2); | ||
|
|
||
| // CORRECT ERROR: no matching function for call to ‘Set<int>::insert(Set<int>::iterator&, const value_type&)’ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
фраза "правильная ошибка", возможно, вводит в заблуждение, но пусть будет. Здорово
set_lib/include/set.h
Outdated
| using value_compare = Cmp; | ||
| using reference = T&; | ||
| using const_reference = const T&; | ||
| using iterator = Iterator<T, Cmp>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
необязательно было реализовывать сигнатуру std::set полностью
| @@ -0,0 +1,101 @@ | |||
| #pragma once | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
те же замечания по подключению файлов что и в set. кажется, прагма ванс спасает, но и без нее должно работать
| node = Set<T, Cmp>::getRightMost(root); | ||
| after_end = false; | ||
| } | ||
| // before_begin-- = before_begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
убери
| Iterator<T, Cmp> Iterator<T, Cmp>::operator--(int) | ||
| { | ||
| Iterator<T, Cmp> tmp(*this); | ||
| operator--(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
более наглядно будет вызвaть (*this)--
| { | ||
| if (!node) | ||
| { | ||
| throw std::runtime_error("operator*() to nullptr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
кажется, для итераторов есть свои классы исключений для случаев окончания итерации, но это не точно
set_lib/include/set_definition.h
Outdated
| } | ||
|
|
||
| template <typename T, typename Cmp> | ||
| typename Set<T, Cmp>::Node* Set<T, Cmp>::prevInternal(Node* node) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
абсолютно правильная идея со списком
|
обрати внимание на такой пункт в ДЗ: покрытие надо будет померить в твоих тестах |
|
Исправлены следующие замечания:
В моей реализации класс Set не является оберткой над AVL-деревом, и, действительно, смешивать логику дерева и контейнера - не лучшее решение. Нужно было разделить зоны ответственности. |
Домашняя работа 5
STL-совместимый контейнер
Nodeхранитleft,right,parent)next,prev)Iterator- дружественный для структурыNode, не имеет ссылки на контейнерafter_endиbefore_begingetLeftMostиgetRightMostв классеSetнужны для итератора, чтобы, например, из элемента после последнего (node = nullptr, after_end = true, before_begin = false) декрементом дойти до последнего элемента