PS. Now I have a method to convert YAML to my struct only by defining another vector-based struct and then converting it into my hash-based struct. But it is not beautiful at all.
You can't use a HashSet as the key in a HashMap since it doesn't have a fixed order. You can use a BTreeSet instead, perhaps. I'm also not sure what you want the resulting value to be.
Fortunately, I implemented Hash for struct DuplicatePattern. Like frozenset in Python, I want to set this struct to immutable and then it would allowed get-hash, but now I just sort it and then calculate the hash of each element.
// I know it is ugly.
impl Hash for DuplicatePattern {
fn hash<H: Hasher>(&self, state: &mut H) {
let mut sorted_elements = self.pattern.iter().collect::<Vec<&String>>();
sorted_elements.sort();
for element in sorted_elements {
element.hash(state);
}
}
}
Another question. I just want to determine the duplicate pattern
whether it is contained in the pattern-db,
if it is, whether the boolean value it is related to is true or false.
I believe using the HashMap struct would make it fast to match.
The reason why I choose HashSet to be the key: the format of all entries of each identical film is presented randomly so inserting them into a HashSet would be helpful. I would do some research of BTreeSet and I hope it helpful.
Firstly, thank you for providing information about std::collections::BtreeSet. I replace HashSet with BtreeSet and everything works fine and even faster than before. Great!
What I can only provide here is the format of the YAML. Now I select a not-smart method: create a middle-struct that can be easier to use during deserializing and then convert this middle-struct to the target struct. A good news is that the quantity of YAML entries is not large.