score:7
since the inheritance chain set <: genset <: gensetlike
is a bit lengthy, it might be not immediately obvious where to look for the code of equals
, so i thought maybe i quote it here:
/** compares this set with another object for equality.
*
* '''note:''' this operation contains an unchecked cast: if `that`
* is a set, it will assume with an unchecked cast
* that it has the same element type as this set.
* any subsequent classcastexception is treated as a `false` result.
* @param that the other object
* @return `true` if `that` is a set which contains the same elements
* as this set.
*/
override def equals(that: any): boolean = that match {
case that: genset[_] =>
(this eq that) ||
(that canequal this) &&
(this.size == that.size) &&
(try this subsetof that.asinstanceof[genset[a]]
catch { case ex: classcastexception => false })
case _ =>
false
}
essentially, it checks whether the other object is also a genset
, and if yes, it attempts to perform some fail-fast checks (like comparing size
and invoking canequal
), and if the sizes are equal, it checks whether this set is a subset of another set, presumably by checking each element.
so, the exact class used to represent the set at runtime is irrelevant, what matters is that the compared object is also a genset
and has the same elements.
score:3
this class implements immutable sets using a list-based data structure.
so listset is a set too but with concrete (list-based) implementation.
score:4
from scala collections equality:
the collection libraries have a uniform approach to equality and hashing. the idea is, first, to divide collections into sets, maps, and sequences.
...
on the other hand, within the same category, collections are equal if and only if they have the same elements
in your case, both collections are considered sets and they contain the same elements, hence, they're equal.
Source: stackoverflow.com
Related Query
- Scala - Collection comparison - Why is Set(1) == ListSet(1)?
- Google guava vs Scala collection framework comparison
- Why does Scala maintain the type of collection not return Iterable (as in .Net)?
- Why are there so many Scala collection view types?
- Why in scala a comparison between integer and floating point such as 71 == 71.0 is true?
- Trying to understand the Range collection in Scala and why errors arise upon assigning the data type in Scala v2.13 as opposed to v2.11
- Why are Futures in scala realised using a collection in the companion object?
- Scala best way of turning a Collection into a Map-by-key?
- Why does the Scala compiler disallow overloaded methods with default arguments?
- Why does pattern matching in Scala not work with variables?
- Any reason why scala does not explicitly support dependent types?
- Converting a Java collection into a Scala collection
- What are Scala continuations and why use them?
- Why does Scala provide both multiple parameters lists and multiple parameters per list?
- How to transform Scala collection of Option[X] to collection of X
- When and why should one use Applicative Functors in Scala
- How are Scala collections able to return the correct collection type from a map operation?
- Why can a Scala trait extend a class?
- Why does a small change to this Scala code make such a huge difference to performance?
- Why doesn't Scala have static members inside a class?
- Why are there two sets of arguments/parenthesis in this Scala method definition?
- How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?
- Why is foreach better than get for Scala Options?
- Scala class and case class == comparison
- Why won't the Scala compiler apply tail call optimization unless a method is final?
- Checking that all items in a collection match a predicate in Scala
- Why no immutable arrays in scala standard library?
- Why is this Scala code with assignment of a val in a parameter working?
- Why are classes inside Scala package objects dispreferred?
- Why are scala functions limited to 22 parameters?
More Query from same tag
- How to sort scala list dynamically on multiple fields
- How to make curried merge sort properly generic
- Is there Scala aware high level byte-code manipulation tool like Javassist?
- Scala - modify strings in a list based on their number of occurences
- cuMemcpyDtoH yields CUDA_ERROR_INVALID_VALUE
- Scala - ScheduledFuture
- Sbt testOnly from Windows console
- Scala preserve type parameter of case class object upon copying
- Is there a way to randomly assign routes or roles for a defined number of actors in Akka?
- How to add a XML node for Some case in pattern matching?
- Retrieve metrics from elasticsearch-spark
- Open source JavaScript interpreter written in Scala
- How JVM distinguish between Scala bytecode and Java bytecode?
- Stuck on writing a polymorphic transpose function that accepts and returns RDDs of either Arrays or Seqs/Vectors
- Modeling a simple rule engine
- Csv Data is not loading properly as Parquet using Spark
- Scala test cannot find any test to run
- Why I can create instance of case class in scala without new operator?
- How to resolve with sbt Resolver maven2 repositories
- How store methods vals without recreating them every method call
- To write a Scala program to convert the given date & time to GMT based on airport code
- Alternatives for BKTree
- Scala convert from list to map by property with sum logic
- scala method call trick List(1, 2, 3).foldLeft(0) _+_
- play framework reading file from conf folder with routing
- Scala variable names collected into List of String
- How to encode values in DataFrame?
- R-tree - Remove algorithm using reinsertion
- Pausing an actor in Akka
- How to get a subset of a map?