Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Is it a good or bad practice to store to store "" as a map key in Go? It seems like a special case which wouldnt be ideal for storage as a key. What do you think?
The empty string value "" is a valid value for the string type, so it's a valid key value for maps having string as the key type. There's nothing "edge" case in that.
Whether it makes sense to store a value associated with the empty string key really depends on your use case. There's nothing good or bad in it. Use it if it has meaning for you.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I have a string consisting zeros and ones and I need to know how many deletions from the beginning I need to do in order to make a string a palindrome. I wrote a function to check if the string is palindrome (and iterate over each element) and it works, but I need complexity better than O(n^2). It will be probably O(n) with KMP algorithm but I have no idea how to use it in this case.
Can you help me?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm getting this on a match block:
patterns `&Unspecified` and `&__Nonexhaustive` not covered
The code:
fn vipaddress_from_ipddress(address: &IpAddress) -> VIpAddress {
match address {
I think &Unspecified has something to do with not accounting for null case, but references in Rust cannot be null. What is &__Nonexhaustive?
Seems to be an undocumented enum variant: https://docs.rs/ethox/0.0.1-wip/src/ethox/wire/ip.rs.html#15
This possibly indicates that the developer does not expect the users of IpAddress to match; maybe there is already a function doing what you want?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
A Vec<T> can be converted to a string:
let string: String = format!("{:.?}", vec));
Can said string be converted back into a Vec<T>?
No, not for generic Ts, as the output of Debug (e.g. via #[derive(Debug)]) does not necessarily yield the right format for FromStr (if the type even implements it). Furthermore, Vec does not implement FromStr, so parse() needs at least a wrapper around the Vec.
Also, while most Debug implementation (including the derived one) show the values of their fields, they're not required to. You cannot get the lost information back at that point.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Variable for whether having, for example, the variable for if the user has points, which is correct?
have_points, has_points, if_having_points or if_has_points?
Naming convention for a variable which holds boolean value should be indicated by prefixes like: is, has, have, does, will, can etc.
In your case you're using snake case. If "has Points" is being tracked for a single entity then you can go with has_points. For more than one entity you might want to go for have_points.
Although it boils to personal preference, but you should still try to keep your code short and succinct.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to compare two input strings and display the number of common characters in Assembly but i can't find how to do that.
To do it efficiently you would need some sort of data structure to remember which characters you have seen already.
If you don’t mind duplicates and don't need efficiency, you could loop over the first string and, for each character, loop over the second string and compare them (adding one to a register or a variable when they match).