This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Ordered Mutable Map.

3 replies
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Dear all,what is the best way to hold an ordered key-value relationship in a mutable collection in scala, since there is no mutable TreeMap?
Best RegardsEdmondo
Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.
Re: Ordered Mutable Map.

seems there is none ( http://stackoverflow.com/questions/4531856/why-is-there-no-mutable-treem... )

you could use one of Java's sorted maps:

http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Concurrent...

On 18 Jan 2012, at 13:47, Edmondo Porcu wrote:

> Dear all,
> what is the best way to hold an ordered key-value relationship in a mutable collection in scala, since there is no mutable TreeMap?
>
> Best Regards
> Edmondo

Michael Church
Joined: 2012-01-18,
User offline. Last seen 40 weeks 6 days ago.
Re: Ordered Mutable Map.
This solution may be a bit clunky, but you can try using mutable.PriorityQueue for that. If your type is Tuple2[K,V] and you leave the ordering unspecified, you'll get default tuple ordering, which is lexicographic (K's first, then V's).

On Wed, Jan 18, 2012 at 8:47 AM, Edmondo Porcu <edmondo.porcu@gmail.com> wrote:
Dear all,what is the best way to hold an ordered key-value relationship in a mutable collection in scala, since there is no mutable TreeMap?
Best Regards Edmondo

H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Ordered Mutable Map.

use a java tree map and a wrapper. there is one in javaconversions. i think.
btw., have i been correct yesterday? i'd like to know if i sacrificed my lunch break for something useful.

-------- Original-Nachricht --------
> Datum: Wed, 18 Jan 2012 10:34:37 -0500
> Von: Michael Church
> An: Edmondo Porcu
> CC: scala-user
> Betreff: Re: [scala-user] Ordered Mutable Map.

> This solution may be a bit clunky, but you can try using
> mutable.PriorityQueue for that. If your type is Tuple2[K,V] and you leave
> the ordering unspecified, you'll get default tuple ordering, which is
> lexicographic (K's first, then V's).
>
>
> On Wed, Jan 18, 2012 at 8:47 AM, Edmondo Porcu
> wrote:
>
> > Dear all,
> > what is the best way to hold an ordered key-value relationship in a
> > mutable collection in scala, since there is no mutable TreeMap?
> >
> > Best Regards
> > Edmondo
> >

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland