News for hackers. Stuff that matters.
Re:Vstr: C string library designed to work optimally with ve... by tyingq on Tuesday March 10, 2020 @06:39AM (#22534322)
Sds from Antirez has a lot of the same features (not all), and is kept updated since it's used by redis and other projects. https://github.com/antirez/sds/blob/master/README.md

Vstr appears to have last been updated in 2006. It does have a comparison of different string libraries, though that's also dated: http://www.and.org/vstr/comparison

Re:Vstr: C string library designed to work optimally with ve... by endorphone on Tuesday March 10, 2020 @08:44AM (#22534914)
"Vstr" seems to target zero-copy by storing a string as a collection of blocks of data. Sds, from my reading, is essentially Pascal strings for C.

They don't seem to be comparable.

Re:Vstr: C string library designed to work optimally with ve... by tyingq on Tuesday March 10, 2020 @09:09AM (#22535090)
It also targets "string like buffers" with arbitrary nulls, appends, splitting on a delimiter, and tokenizing. Yes, it works differently, and isn't readv/writev centric.
Re:Vstr: C string library designed to work optimally with ve... by bvrmn on Tuesday March 10, 2020 @10:52AM (#22535925)
SDS has no special primitives to support scatter/gather io. In this regard sds-strings are the same as plain c-strings.
Re:Vstr: C string library designed to work optimally with ve... by tyingq on Tuesday March 10, 2020 @10:55AM (#22535948)
I mentioned that.
Re:Vstr: C string library designed to work optimally with ve... by cowsandmilk on Tuesday March 10, 2020 @08:09AM (#22534711)
SDS and this library are implemented completely differently...
Re:Vstr: C string library designed to work optimally with ve... by optimuspaul on Tuesday March 10, 2020 @10:25AM (#22535693)
2006 being the last update makes me not want to use it. But I suspect it is a stable library that doesn't need much update. I'm just getting back into c/c++ development and I'm very interested in libraries like these.
Re:Vstr: C string library designed to work optimally with ve... by coliveira on Tuesday March 10, 2020 @12:33PM (#22536925)
C is an old language, some of the best libraries are stable for 20 years now.
Re:Vstr: C string library designed to work optimally with ve... by robobro on Tuesday March 10, 2020 @11:45AM (#22536420)
> 2006 being the last update makes me not want to use it. Why
Re:Vstr: C string library designed to work optimally with ve... by optimuspaul on Thursday March 12, 2020 @12:45PM (#22558732)
security concerns, might be unfounded, but something to consider
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)
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.