- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Ordered Mutable Map.
Wed, 2012-01-18, 14:47
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
Best RegardsEdmondo
Wed, 2012-01-18, 16:51
#2
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:
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
Wed, 2012-01-18, 17:11
#3
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
> >
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