Scala Set Hashcode -
assume have 3 sets of strings in scala. 1 has elements a,b,c. 2 has elements b,c,d. , 3 has elements j,k,i.
my first question is, there way hashcodes 2 of these sets same? second question is, if add d 1 , 2 new sets one.n , two.n, hashcodes one.n , two.n same?
question 1) in general yes, entirely possible. hashcode limited number of bytes long. set can size. hashcodes cannot unique (although are).
question 2) why not try it?
scala> val 1 = collection.mutable.set[string]("a", "b", "c") one: scala.collection.mutable.set[string] = set(a, b, c) scala> one.hashcode res3: int = 1491157345 scala> val 2 = collection.mutable.set[string]("b", "c", "d") two: scala.collection.mutable.set[string] = set(b, d, c) scala> two.hashcode res4: int = -967442916 scala> 1 += "d" res5: one.type = set(a, b, d, c) scala> 2 += "a" res6: two.type = set(b, d, a, c) scala> one.hashcode res7: int = -232075924 scala> two.hashcode res8: int = -232075924
so, yes are, might expect, since expect ==
method true these 2 instances.
Comments
Post a Comment