diff options
author | Paul Phillips <paulp@improving.org> | 2011-11-24 01:24:28 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-11-24 01:24:28 +0000 |
commit | 60fb9ec19b50cd8059122ccffd72014b3eefc51f (patch) | |
tree | 47f47b7b9ad13fb79df825e4e42864a9f53d7035 /src/library/scala/collection/GenSeqLike.scala | |
parent | 4cfca8a7f6763fbbaab37a3473d74118b3ec52bc (diff) | |
download | scala-60fb9ec19b50cd8059122ccffd72014b3eefc51f.tar.gz scala-60fb9ec19b50cd8059122ccffd72014b3eefc51f.tar.bz2 scala-60fb9ec19b50cd8059122ccffd72014b3eefc51f.zip |
Refinements of "def seq" and murmurhash.
Trying to make hashcodes faster. Didn't achieve much on that front, so
redirected into structural/consistency issues. The latter was lacking
in terms of how/where "def seq" was defined. The documentation I can
find doesn't give me much hint that the sequential form of my sequential
collection might be a single-use iterator! (As in StringOps, ArrayOps.)
If that's intentional it should be in huge letters. I'm assuming for now
that it wasn't.
Also, there was this:
GenMapLike: def seq: Map[A, B]
GenSetLike: def seq: Set[A]
GenSeqLike: // nothing, returns Traversable
So I added some def seqs where I needed the more specific types for
my hashcode work. Hashcodewise, I broke the MurmurHash3 object into
a reusable class and a collections-specific object, and I deprecated
the methods which took GenTraversableOnce in favor of ones taking
TraversableOnce, because there's no reason the hashcode library should
have to know about things like "make sure to call seq before you
traverse or you'll be sorry." Exclude things by their type and you can
never make a mistake. End transmission.
Diffstat (limited to 'src/library/scala/collection/GenSeqLike.scala')
-rw-r--r-- | src/library/scala/collection/GenSeqLike.scala | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/src/library/scala/collection/GenSeqLike.scala b/src/library/scala/collection/GenSeqLike.scala index 2d50cb18b3..b3dd4764a9 100644 --- a/src/library/scala/collection/GenSeqLike.scala +++ b/src/library/scala/collection/GenSeqLike.scala @@ -31,6 +31,7 @@ import annotation.bridge * Unlike iterables, sequences always have a defined order of elements. */ trait GenSeqLike[+A, +Repr] extends GenIterableLike[A, Repr] with Equals with Parallelizable[A, parallel.ParSeq[A]] { + def seq: Seq[A] /** Selects an element by its index in the $coll. * @@ -439,16 +440,7 @@ trait GenSeqLike[+A, +Repr] extends GenIterableLike[A, Repr] with Equals with Pa /** Hashcodes for $Coll produce a value from the hashcodes of all the * elements of the $coll. */ - override def hashCode() = { - import util.MurmurHash3._ - var n = 0 - var h = Seq.hashSeed - seq foreach { - x => h = mix(h, x.##) - n += 1 - } - finalizeHash(h, n) - } + override def hashCode() = util.MurmurHash3.seqHash(seq) /** The equals method for arbitrary sequences. Compares this sequence to * some other object. |