#Gapbuffer unit tests failing because of the gap -- need some iterator help

8 messages · Page 1 of 1 (latest)

lost warren
#

Three test cases are failing on my line() method implemented here https://github.com/Ttibsi/gapvector/blob/gv2/gapbuffer.h#L398-L419 -- going through it with gdb and it looks like the calculation of the line_end part is wrong, but I'm not sure what I'm missing. If I breakpoint at the assert statement and do line_end - line_start, it looks like the iterators are pointing to the wrong plac e-- I'm getting values much larger than even the current size of the container at the time.

(gdb) p line_end - line_start
$2 = 22
(gdb) p size()
$3 = 14
(gdb) p capacity()
$4 = 22

I'm pretty sure this is something to do with the actual gap being taken into consideration in the iterator -- see line 62-63 for an example. I think I do want that to be taken into consideration, so I can just use the values in the container for stdlib algorithms and things like that.

Alternatively, I could add something to the line() method to take that into consideration, but I'm not sure exactly what. I've tried a few things -- else if (line_end == gapEnd) { line_end = gapStart; } and else if (line_end == end()) { line_end -= gap_size(); } are both alternate else blocks I've tried adding to the if statement on lines 414-416, and the latter just segfaults on the string constructor and the former requires extra work to turn a pointer into an iterator and I'm not convinced it's the right approach. Can anyone else see something I'm missing here?

crimson obsidianBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

outer hornet
#

I think your iterator addition function is wrong

#

because while operator++ takes the gap into acount, I dont think operator+ does

#

so I would change that to also take the gap into account in operator+ and similar

lost warren
#

Huh, I'll give that a go. Thanks

outer hornet
#

no problem, hope that fixes it

crimson obsidianBOT
#

@lost warren Has your question been resolved? If so, type !solved :)