1+ use  hashbrown:: HashSet ; 
2+ use  std:: hash:: { Hash ,  Hasher } ; 
3+ 
14use  is_macro:: Is ; 
25use  paste:: paste; 
36use  serde:: { Deserialize ,  Serialize } ; 
47use  strum_macros:: { Display ,  EnumString } ; 
58
69use  crate :: WordId ; 
710
8- #[ derive( Debug ,  Default ,  Clone ,  PartialEq ,  Eq ,  Serialize ,  Deserialize ,   PartialOrd ,   Hash ) ]  
11+ #[ derive( Debug ,  Default ,  Clone ,  PartialEq ,  Eq ,  Serialize ,  Deserialize ) ]  
912pub  struct  WordMetadata  { 
1013    pub  noun :  Option < NounData > , 
1114    pub  pronoun :  Option < PronounData > , 
@@ -28,7 +31,28 @@ pub struct WordMetadata {
2831#[ serde( default  = "default_false" ) ]  
2932    pub  common :  bool , 
3033    #[ serde( default  = "default_none" ) ]  
31-     pub  derived_from :  Option < WordId > , 
34+     pub  derived_from :  Option < HashSet < WordId > > , 
35+ } 
36+ 
37+ impl  Hash  for  WordMetadata  { 
38+     fn  hash < H :  Hasher > ( & self ,  state :  & mut  H )  { 
39+         self . noun . hash ( state) ; 
40+         self . pronoun . hash ( state) ; 
41+         self . verb . hash ( state) ; 
42+         self . adjective . hash ( state) ; 
43+         self . adverb . hash ( state) ; 
44+         self . conjunction . hash ( state) ; 
45+         self . swear . hash ( state) ; 
46+         self . dialect . hash ( state) ; 
47+         self . determiner . hash ( state) ; 
48+         self . preposition . hash ( state) ; 
49+         self . common . hash ( state) ; 
50+         if  let  Some ( ref  derived_from)  = self . derived_from  { 
51+             for  id in  derived_from. iter ( )  { 
52+                 id. hash ( state) ; 
53+             } 
54+         } 
55+     } 
3256} 
3357
3458/// Needed for `serde` 
@@ -111,7 +135,16 @@ impl WordMetadata {
111135            determiner :  self . determiner  || other. determiner , 
112136            preposition :  self . preposition  || other. preposition , 
113137            common :  self . common  || other. common , 
114-             derived_from :  self . derived_from . or ( other. derived_from ) , 
138+             derived_from :  match  ( & self . derived_from ,  & other. derived_from )  { 
139+                 ( Some ( a) ,  Some ( b) )  => { 
140+                     let  mut  set = a. clone ( ) ; 
141+                     set. extend ( b) ; 
142+                     Some ( set) 
143+                 } 
144+                 ( Some ( a) ,  None )  => Some ( a. clone ( ) ) , 
145+                 ( None ,  Some ( b) )  => Some ( b. clone ( ) ) , 
146+                 ( None ,  None )  => None , 
147+             } , 
115148        } 
116149    } 
117150
0 commit comments