Похожие чаты

Hey there. Does arithmetic operations on iterators work in O(n) ? Example: std::vector<int>::iterator

it = v.begin();
it += 6;

Is "it += 6;" done in O(n) or constant time ?

12 ответов

26 просмотров
Sahand-🏔️ Автор вопроса

Can anyone help out?

Sahand 🏔️
Can anyone help out?

i think its constant, just move address

Sahand-🏔️ Автор вопроса
²
i think its constant, just move address

So it's constant for std vector but for std list (that no random access is available) it'll be O(n) I think. Because the compiler says no operator '+=' is overloaded.

Sahand-🏔️ Автор вопроса
²
screenshot oh, you right

Which book is it

²
screenshot oh, you right

Would be interesting to know if they give you any guarantees on complexity, but likely they won't

Sahand-🏔️ Автор вопроса
BinaryByter
Would be interesting to know if they give you any ...

guarantees on the complexity of arithmetic operations on iterators?

BinaryByter
Would be interesting to know if they give you any ...

You can see here that the operation on a random access I iterators is not O(1) while others iterators are O(n) https://en.cppreference.com/w/cpp/iterator/distance

Похожие вопросы

Обсуждают сегодня

Если у меня есть такой класс: Object = {} function Object:new(a_name, a_transform, a_color, a_mesh, a_material, a_shader, a_textures) local private = {} private.n...
Cuarno Vile
4
А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
At which price point will BCH, an ASIC mined coin, be succeptible to reorg attacks because of low hashrate? $10? $1? $0.1? $0.01?
Kishniev
18
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
I hodl ocean for a long time. Is there new development that I should read?
A33
12
Is there an article I can read for more information?
Lobaka
10
здравствуйте. совершаю вот такую вещь: strcpy(line, (char)current_number); где current number — неподписанный шорт, line — массив чаров. ругань следующая: main.c:29:30: error...
Roberto's Ширгозиев
13
Карта сайта