@@ -75,7 +75,7 @@ pub mod ListExt {
7575}
7676
7777pub mod SetExt {
78- use crate :: Native_ :: { Func2 , Hashable , NullableRef , Vec , make_compare, seq_to_iter} ;
78+ use crate :: Native_ :: { Func2 , Hashable , NullableRef , Vec , combineHashCodes , make_compare, seq_to_iter} ;
7979 use crate :: Set_ :: { Set , add, compareTo, empty, equals, isEmpty, toSeq} ;
8080 use core:: cmp:: Ordering ;
8181 use core:: hash:: { Hash , Hasher } ;
@@ -113,6 +113,17 @@ pub mod SetExt {
113113
114114 impl < T : Clone + Hashable + PartialOrd > Eq for Set < T > { }
115115
116+ impl < T : Clone + Hashable + PartialOrd > Hashable for Set < T > {
117+ fn getHashCode ( & self ) -> i32 {
118+ let s = toSeq ( self . clone ( ) ) ;
119+ let mut res = 0_i32 ;
120+ for value in seq_to_iter ( s) {
121+ res = combineHashCodes ( res, value. getHashCode ( ) ) ;
122+ }
123+ res
124+ }
125+ }
126+
116127 impl < T : Clone + Hashable + PartialOrd + Hash > Hash for Set < T > {
117128 fn hash < H : Hasher > ( & self , state : & mut H ) {
118129 let s = toSeq ( self . clone ( ) ) ;
@@ -171,7 +182,7 @@ pub mod SetExt {
171182
172183pub mod MapExt {
173184 use crate :: Map_ :: { Map , add, compareTo, empty, equals, isEmpty, iterate, toSeq} ;
174- use crate :: Native_ :: { Func2 , Hashable , NullableRef , Vec , make_compare, seq_to_iter} ;
185+ use crate :: Native_ :: { Func2 , Hashable , NullableRef , Vec , combineHashCodes , make_compare, seq_to_iter} ;
175186 use core:: cmp:: Ordering ;
176187 use core:: hash:: { Hash , Hasher } ;
177188
@@ -208,6 +219,19 @@ pub mod MapExt {
208219
209220 impl < K : Clone + Hashable + PartialOrd , V : Clone + Hashable + PartialOrd > Eq for Map < K , V > { }
210221
222+ impl < K : Clone + Hashable + PartialOrd , V : Clone + Hashable + PartialOrd > Hashable for Map < K , V > {
223+ fn getHashCode ( & self ) -> i32 {
224+ let s = toSeq ( self . clone ( ) ) ;
225+ let mut res = 0_i32 ;
226+ for kvp in seq_to_iter ( s) {
227+ let ( key, value) = kvp. as_ref ( ) ;
228+ res = combineHashCodes ( res, key. getHashCode ( ) ) ;
229+ res = combineHashCodes ( res, value. getHashCode ( ) ) ;
230+ }
231+ res
232+ }
233+ }
234+
211235 impl < K : Clone + Hashable + PartialOrd + Hash , V : Clone + Hash > Hash for Map < K , V > {
212236 fn hash < H : Hasher > ( & self , state : & mut H ) {
213237 let s = toSeq ( self . clone ( ) ) ;
0 commit comments