1. #11
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    We don't have a use case, which is why I was asking about a SortedSet. A List implies some order but not uniqueness whereas a Set implies uniqueness but no order. To me, a SortedSet is the happy medium because it implies both some type of ordering and uniqueness among elements.

    I still can't think of a scenario whereby I would have two duplicate model objects but each one would return a different key value - to me, this implies that the models are not the same, and thus, not duplicates.

    Additionally, you talked about performance. Using the right SortedSet implementation can be significantly faster than a List. Java's implementation of TreeSet uses its implementation of TreeMap, which is a red-black tree. Red-black trees have a best and worst O(log n) for searching, inserting, and deleting (sorting is done on insert) whereas a list has at best an O(n log(n)) for sorting.

    References:
    http://en.wikipedia.org/wiki/Red%E2%80%93black_tree
    http://en.wikipedia.org/wiki/Sorting_algorithm

  2. #12
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    In Java, you'd be exactly right, and I'd be foolish to not look into at least considering these changes, but in GWT/Java, where ArrayList is compiled to create JS Array instances, the game is a little different.

    JavaScript has native arrays and objects, and ArrayList is re-implemented to use them, as opposed to Java's array type. From com.google.gwt.emul.java.lang.ArrayList:

    /**
    * Resizeable array implementation of the List interface. <a
    * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html">[Sun
    * docs]</a>
    *
    * <p>
    * This implementation differs from JDK 1.5 <code>ArrayList</code> in terms of
    * capacity management. There is no speed advantage to pre-allocating array
    * sizes in JavaScript, so this implementation does not include any of the
    * capacity and "growth increment" concepts in the standard ArrayList class.
    * Although <code>ArrayList(int)</code> accepts a value for the initial
    * capacity of the array, this constructor simply delegates to
    * <code>ArrayList()</code>. It is only present for compatibility with JDK
    * 1.5's API.
    * </p>
    *
    * @param <E> the element type.
    */
    The implementation then is almost entirely JSNI wrapping around standard JS Array methods, and will be pretty efficient, especially for iterating through them, which is the main use case in Stores where performance is important, visiting each item to render it.

    Can you suggest a class that should be a good SortedSet implementation to try backing the ListStore with, and is available in the available JRE classes in GWT? I might try a quick implementation, see what happens performance-wise.

  3. #13
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Ack! I'd forgotten that we're dealing with Java --> J/S conversion.

    I see TreeSet/TreeMap implementations in GWT SVN: http://code.google.com/p/google-web-...emul/java/util, is this what's used to generate J/S versions of java.util.[TreeSet/TreeMap]? I don't think this is what you're talking about though.

    I'm perusing the google-collections framework (apparently, now known as Guava) and they have plenty of GWT Compatible (annotated with GwtCompatible) collections. But, this would introduce a transient dependency on GXT API users and it looks like their SortedMultiset collection allows duplicates (however duplicate here means occurrences of the same single element).

    Additionally, it appears that the LightweightCollections effort was killed as well due to "the GWT implementaiton of teh Java libraries performed reasonably well, even when compared to a simple encapsulation of J/S datastructures. HashMap even provides specialized behavior for String keys.

    I would be curious as to the performance of Google's code, but to answer your question, I don't have an alternative implementation.