The Artima Developer Community
Sponsored Link

Articles Forum
What's New in Scala 2.8: The Architecture of Scala Collections

6 replies on 1 page. Most recent reply: Dec 28, 2010 7:48 PM by Cameron Purdy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 16, 2010 10:00 PM
Reply to this message Reply
Advertisement
In this installment of a series of articles on the latest Scala release, Scala 2.8, Martin Odersky and Lex Spoon explain how the collections library was redesigned in 2.8, and how to extend the library with new collection types.

http://www.artima.com/scalazine/articles/scala_collections_architecture.html


Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 21, 2010 10:44 PM
Reply to this message Reply
I use collections a ton in Java. And I've done years of programming for DNA sequencing. (BTW, you probably want 1 bit per possible base to cover heterozygotes, at which point it's probably simpler to just waste a factor of 2 in space and use 1 byte per base instead of the packing.)

I've tried several times to understand the article. And I'll try again. Between Scala's syntax, which I admit I don't know much about but doesn't resemble any language I know and seems deliberately terse and "weird", (e.g., what is a -Elem and a +To?) and the complexities and layering of the Scala Collection Architecture, I'm lost.

If I'm lost, I suspect many others are too.

Martin Odersky

Posts: 84
Nickname: modersky
Registered: Sep, 2003

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 22, 2010 6:14 AM
Reply to this message Reply
If you don't know Scala, this article is not for you. You are much better off reading the previous article I published which describes collections from a user's point of view:

http://www.artima.com/scalazine/articles/scala_collections.html

Even if you do know Scala, you should read this article first. The present article is for experts who want to understand how collections hang together and how one can integrate new collections in the framework so that all operations are automatically specialized to the proper types. That's a non-issue for traditional CRUD collections, but very hard to achieve for the kind of functional / parallel collections Scala has. In fact I know of no other language or framework that even tries this.

-Elem and +T mean contravariant and covariant btw. In C# 4.0 that would be "out Elem" and "in T". It's roughly comparable to Java's wildcards "? super Elem" and "? extends T" but is declaration site rather than use site. Variance is hard, that's why none of the three notations is particularly easy (-Elem, +T is the most standard, if you go by the literature).

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 22, 2010 12:36 PM
Reply to this message Reply
Thanks. I'll look at the earlier article first.

I was guessing that + and - were roughly "extends" / "super", and, in practice, I'd have a 50:50 chance of picking the right one. :-)

michael lawley

Posts: 2
Nickname: lawley
Registered: Dec, 2007

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 23, 2010 12:20 AM
Reply to this message Reply
Really nice article!

Just wondering what the memory footprint of these classes is like?

The Java Collections library is pretty bad wrt HashMap, HashSet and the like.

michael

Martin Odersky

Posts: 84
Nickname: modersky
Registered: Sep, 2003

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 23, 2010 5:10 AM
Reply to this message Reply
>
> Just wondering what the memory footprint of these classes
> is like?
>

The standard framework mixin traits have no per-object memory overhead, all they add is extra methods. The net memory footprint hence depends on the chosen collection implementation. Here, for small collections, immutable generally wins. For instance, an immutable Set of 4 elements is represented as just a single object with 4 fields, so typically 20 bytes. By contrast, a mutable HashSet would consume typically ~ 100 bytes.

Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: What's New in Scala 2.8: The Architecture of Scala Collections Posted: Dec 28, 2010 7:48 PM
Reply to this message Reply
> Just wondering what the memory footprint of these classes is like?
> The Java Collections library is pretty bad wrt HashMap, HashSet and the like.

HashSet uses a HashMap, so let's focus just on HashMap. For a general-purpose key/value dictionary that uses key-based hashing, is it bad? Or is it bad compared to other algorithms?

Peace,

Cameron Purdy | Oracle Coherence
http://coherence.oracle.com

Flat View: This topic has 6 replies on 1 page
Topic: What's New in Scala 2.8: Package Objects Previous Topic   Next Topic Topic: Azul's Pauseless Garbage Collector

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use