Hashmaps are generally much faster than Treemaps.  I would recommend just
sorting at serialization time.  That is,

   for (String key : new TreeSet(data.keySet())) {...}


On Thu, Aug 7, 2008 at 2:47 PM, Sean Owen <[EMAIL PROTECTED]> wrote:

> Yeah that Map is a HashMap and so has no predictable key ordering.
>
> Sounds like we want a TreeMap (i.e. a SortedMap implementation)?
> author, may I change it? :)
>
> On Thu, Aug 7, 2008 at 3:32 PM, Allen Day <[EMAIL PROTECTED]> wrote:
> > Here's a relevant snippet:
> >
> >    [junit] Testcase:
> > testAsFormatString(org.apache.mahout.matrix.TestSparseVector):
> > FAILED
> >    [junit] format expected:<[s5, [2:2.2, 1:1.1], 3:3.3, ] > but
> > was:<[s5, [1:1.1, 2:2.2], 3:3.3, ] >
> >    [junit] junit.framework.ComparisonFailure: format expected:<[s5,
> > [2:2.2, 1:1.1], 3:3.3, ] > but was:<[s5, [1:1.1, 2:2.2], 3:3.3, ] >
> >    [junit]     at
> >
> org.apache.mahout.matrix.TestSparseVector.testAsFormatString(TestSparseVector.java:40)
> >
> > I've seen this happen in some of my dev environments but not others.
> > The error is because the serialized vector/matrix has transposed some
> > of the elements relative to what the unit test expects.  It looks to
> > me like this is caused by iterating over the keyset directly rather
> > than sorting it first:
> >
> > SparseVector.java:97
> > -------------------------
> >  public String asFormatString() {
> >    StringBuilder out = new StringBuilder();
> >    out.append("[s").append(cardinality).append(", ");
> >    for (Integer index : values.keySet())
> >      out.append(index).append(':').append(values.get(index)).append(",
> ");
> >    out.append("] ");
> >    return out.toString();
> >  }
> > -------------------------
> >
> > -Allen
> >
>



-- 
ted

Reply via email to