Skip to main content
Ben Voigt's user avatar
Ben Voigt's user avatar
Ben Voigt's user avatar
Ben Voigt
  • Member for 13 years, 9 months
  • Last seen more than a week ago
  • Houston, TX
comment
Get histogram of bytes in any set of files in Java
isLetterOrDigit isn't nearly the set of useful printable characters. Consider printing everything for which isISOControl returns false.
comment
Is set of integers closed under the operation of subtraction?
unnecessary to call unordered_set::find(), since the information's available in second of the pair returned from insert(). no_dups &= v_abs.insert(x).second;
comment
C++ function template implementation to find the min/max value from three vectors
Toby's version using concat/join is correct (in regard to the bug mentioned above), because it doesn't require min or max to exist for individual vectors.
comment
C++ function template implementation to find the min/max value from three vectors
The specification is valid if the total number of elements across all three vectors is at least one, but your implementation only works if all three vectors are individually non-empty. So I'd argue that it is too early to discuss expressive/concise/performant, because it is not correct.
comment
comment
Coding exercise to represent an integer as words using python
@AdrianMcCarthy: It's a bug in the specification, the description "Convert a non-negative integer" conflicts with the stated constraint "num is strictly greater than zero"
comment
Coding exercise to represent an integer as words using python
"English numerals are never written out in Title Case"? They are when found in titles. "Twenty Thousand Leagues Under the Seas" So it may make sense to have an option argument as_title_case rather than assert it is wrong.
comment
File path normalizer
Also EXPECT_EQ(normalize("./.a/"), "./.a/"); looks wrong, I think it should be .a/
comment
Optimized data structure mapping finite set of integers to values in C++
I contend that the correct name for "array, with some elements missing/skipped" is "sparse array", "sparse vector", or "sparse matrix".
awarded
awarded
awarded
comment
A simple Vector library in C
@TomTsagkatos: Yes they are. The linker may or may not be able to deduplicate them during an optimization pass (for example, Microsoft's linker does this with OPT:ICF but it is non-compliant to rules about comparison of function pointers).
comment
A simple Vector library in C
@lhballoti: Why in the world would you do that? This datatype is plenty small enough to pass by value efficiently, stack allocation is much more efficient than heap, and one will very often want to define arrays with memory locality, not arrays of pointers into the heap.
comment
Dynamic array of int in C
Potential overflow in cap * sizeof(int) is a vulnerability.
comment
char* to integer implementation (atoi with saturation to INT_MIN or INT_MAX on overflow)
Your mention of two's-complement seems totally immaterial, there are no operations here which fail on other representations (except the one that fails on all representations).
comment
char* to integer implementation (atoi with saturation to INT_MIN or INT_MAX on overflow)
Forcing an in-range value of INT_MIN to take the overflow early return path is a bit of trickery worthy of a comment and explanation in the answer prose.
comment
char* to integer implementation (atoi with saturation to INT_MIN or INT_MAX on overflow)
Also, odd that you would rely on isspace(0) to return false in one loop, and then carefully protect against testing isdigit(0) in the next
comment
char* to integer implementation (atoi with saturation to INT_MIN or INT_MAX on overflow)
Not worth a whole answer, but the parameter should be const char*
comment
Image Processing Application in C
In the larger context, magic might be guaranteed NUL-terminated, but that's essentially an implementation detail of the chosen I/O function. Other I/O functions don't make that guarantee, and the condition you're rewriting didn't depend on it. So I don't consider it equivalent. Could use strncmp to preserve the original semantics.
1
2 3 4 5
10