Re:Vstr: C string library designed to work optimally with ve...
by joosters on Tuesday March 10, 2020 @06:59AM
(#22534413)
Are these claims of O(1) behavior accurate? They might not be O(n), where n is the length of the string, but they sound likely to be O(v), where v is the number of 'iovec chunks' that the string is using (which could get large, depending upon how you are building up your strings)
[ Parent
| on HN ]
Re:Vstr: C string library designed to work optimally with ve...
by chalst on Tuesday March 10, 2020 @10:06AM
(#22535522)
If the list of chunks is represented as a deque, then concatenation and popping the first character can both be done in constant time.
Re:Vstr: C string library designed to work optimally with ve...
by joosters on Tuesday March 10, 2020 @10:35AM
(#22535763)
Sure, but the page O(1) examples are:
1) Getting the data for a writev() call: Sure, it’s just returning a pointer to an array of iovecs, but someone is going to have to linearly scan that array.
2) Substituting or moving data anywhere in the string: As you say, you can do stuff with the start or end of a (v)string with O(1) but anywhere else will require a linear walk of the data chunks
Re:Vstr: C string library designed to work optimally with ve...
by chalst on Tuesday March 10, 2020 @11:17AM
(#22536142)
If the claim is random access, then I agree that O(1) is imposssible. Rope would allow these tasks to be carried out in logarithmic time.
The tasks I chose were the first two API desiderata from http://www.and.org/vstr/design - which is the examples page you had in mind?
Re:Vstr: C string library designed to work optimally with ve...
by joosters on Tuesday March 10, 2020 @11:45AM
(#22536425)
I was quoting from the ‘about’ section of the linked page. I’m not deliberately trying to pick on or criticise this data structure, it’s certainly a good way of manipulating some forms of text (I’ve used similar data structures for efficient HTTP processing/mangling). It’s just that there can be hidden costs and the O(1) claims appeared misleading.
Re:Vstr: C string library designed to work optimally with ve...
by kevingadd on Tuesday March 10, 2020 @09:02AM
(#22535026)
If your strings are short that's basically O(1), which could be nice for some workloads - enums, json keys, etc.
Re:Vstr: C string library designed to work optimally with ve...
by jacwah on Tuesday March 10, 2020 @09:30AM
(#22535250)
That's not what O(1) means. If your strings are short, complexity doesn't matter either way.
Re:Vstr: C string library designed to work optimally with ve...
by leetcrew on Tuesday March 10, 2020 @10:00AM
(#22535481)
if all your strings are of size < c, you can do any string operation on a single string in constant time.
Re:Vstr: C string library designed to work optimally with ve...
by saagarjha on Tuesday March 10, 2020 @03:58PM
(#22539020)
There are certain (randomized) operations that you can’t…
Re:Vstr: C string library designed to work optimally with ve...
by admax88q on Tuesday March 10, 2020 @09:31AM
(#22535264)
That's still misleading.
If all my input is small then O(n^2) is basically O(1) as well.
Re:Vstr: C string library designed to work optimally with ve...
by naniwaduni on Tuesday March 10, 2020 @12:04PM
(#22536617)
Everything is O(1) when you have finite bounded input.