New answers tagged

0 votes

Coderbyte: String Reduction

I know this is very old, but I have a small update to this program, I believe you do not need the while loop and original because it always executes once or goes in indefinite loop if the string has ...
4 votes

C++ std::string implementation

Overview The main issue is to decide if the stored char buffer is '\0' terminated or not. Make it clear in comments then write tests to check for it. The first constructor does this explicitly but ...
  • 92.1k
2 votes

Reversing a Python string using [::-1]

Is there another way of reversing a string other than using [::-1] method? Yes there is. There are plenty of tutorials on the Internet, consider this one for example: Python Reverse String - 5 Ways ...
  • 5,607
1 vote

StringPool in C++

Applied changes Completely removed special handling of literals. Use unordered_set as an underlying container Handling of literals overcomplicated my pool without ...
1 vote

StringPool in C++

Errors, warnings and style std::uninitialized_copy() requires <memory> to be included. ...
  • 60.7k
5 votes

Reversing a Python string using [::-1]

Using string slicing as you have done is pretty much the best way, as discussed in this answer. You should consistently put a space before and after the = ...
3 votes

StringPool in C++

Reconsider your design: Why do you limit yourself to strings, and only those fitting the specialization string_view? With a slight adjustment you could use it for any kind of read-only data. Mostly, ...
3 votes
Accepted

StringPool in C++

Make it more generic You have already written somewhat generic code, as StringPool is a template. However, you can go further than that. First, consider that ...
  • 35.7k
4 votes

Split string into same consecutive characters

Nice tidy code, and you've provided a test - that's good. You didn't mention warning options when compiling; I used ...
  • 60.7k
4 votes

Split string into same consecutive characters

Avoid memory allocations, Part 1. Your function takes a std::string_view in input, why does it return a std::string? It would be ...
  • 3,553
3 votes

Split string into same consecutive characters

You could convert the while loop to a for loop: ...
  • 110k
5 votes
Accepted

Remove leading zeroes from the beginning of a string

For style and formatting, your asm is pretty good except for label names. Correctly indented, and some intro comments about register usage. But missing comments about even the major steps of the ...
  • 2,707
6 votes

Remove leading zeroes from the beginning of a string

Choosing assembly for speed is likely an error. You will have to spend a lot of time optimising for your hardware to beat a well-tuned compiler¹. And you'll need to repeat that every time you target ...
  • 60.7k
8 votes

Remove leading zeroes from the beginning of a string

C doesn't match assembly for (size_t i = 0; i < strlen(number); i++) { You don't seem to actually be doing this. Your actual assembly is more like ...
  • 21.1k
1 vote

Finding first unique character in string

We forgot to #include <string>. This definition looks like C: typedef struct { ⋮ } Tracking; In C++, we ...
  • 60.7k
4 votes
Accepted

Finding first unique character in string

As already mentioned, you can do this in a one-pass algorithm. You only need to keep track of whether you have seen a character before, and what the position of its first occurence is. Here is a ...
  • 35.7k
3 votes

Finding first unique character in string

Consider a simpler algorithm: Pass 1: Build a map of counts of characters. Pass 2: For each index, if the count of the current character is 1, return the index. If pass 2 terminates without returning,...
  • 110k
1 vote

Evaluate a boolean expression as a string

Missing header #include <string> Misspelt type name size_t is in the std namespace, ...
  • 60.7k

Top 50 recent answers are included