7 Replies Latest reply: May 29, 2013 8:26 AM by 584593 RSS

    how to sort mappings (double, int) retrieving after by int

    584593
      I need to remove by some rules, from a set of doubles, ascending sorted, some of them. All doubles associate int indexes.
      If I use a common array, after sorting, the old index position is lost, so it couldn't keep the mappings with old indexes.
      I tried to use a TreeMap, but there are no methods for sequential access, using the int indexes, treated as values - because the doubles must use as keys, for initial sorting purpose.
      What could it be the solution?

      Best wishes!
        • 1. Re: how to sort mappings (double, int) retrieving after by int
          EJP
          I tried to use a TreeMap, but there are no methods for sequential access
          Yes there are. Iterators over the key set and the entry set both return the keys/entries in key order. See the Javadoc.
          • 2. Re: how to sort mappings (double, int) retrieving after by int
            584593
            thks for ur answer :)
            pb is that I need to access simultaneuosly same iterator, by keys order (old doubles), twice_, cause I have to remove some mappings, by comparison of the others.
            The iterators has no index-based access methods...
            • 3. Re: how to sort mappings (double, int) retrieving after by int
              EJP
              The problem is that you haven't defined your problem clearly enough for anyone to have the faintest idea what you're talking about. Try again.
              • 4. Re: how to sort mappings (double, int) retrieving after by int
                gimbal2
                Good, I thought I was alone there :)

                Perhaps start by posting a code example of your current data setup that you're trying to work with.
                • 5. Re: how to sort mappings (double, int) retrieving after by int
                  EJP
                  You're never alone with folie a deux.
                  • 6. Re: how to sort mappings (double, int) retrieving after by int
                    aksarben
                    I'm taking a wild guess here, but it may be that what you really need is a list, rather than a map. If you really do need a map, take a look at the LinkedHashMap class to see if that might help you.
                    • 7. Re: how to sort mappings (double, int) retrieving after by int
                      584593
                      Let be a set of pairs, A = {(double#1, integer#1), ..., (double#n, integer#n)}, or short noted (double#i, integer#i), i = 1..n ,
                      Association between pair members must be maintained, after sorting A, in the doubles ascending order.

                      Let be now another set of pairs, B = {(Object#1, integer#1), ..., (Object#n, integer#n)}, or short noted (Object#i, integer#i), i = 1..n,
                      where integer#i, i = 1..n, is the same in both sets.

                      Also, let be an eliminateDoubleBySomeObjectComparisonStuff(Object#1, Object#2) method for testing Object#2 against Object#1 in B, if a pair (double#2, integer#2) is allowed to be accepted together with (double#1, integer#1) in A.

                      N.B. It could be considered in fact a set of tri-components objects, (double#i, integer#i, Object#i), i = 1..n, but I think it's more clear a separation between sets A and B, because of the two separated operations, doubles sorting and elimination method.

                      Finally, the complete algorithm:

                      for i -> 1..n to double#i (from A) do
                      for j -> i + 1 to double#j (from A) do
                      eliminateDoubleBySomeObjectComparisonStuff(Object#i, Object#j)

                      Question which stays is... what data structure can be used to achieve these? How can be sorted doubles in question, without loose association with corresponding integers, implicitly with corresponding objects, and then applied elimination method on doubles data structure twice, simultaneously, considering a comparison condition between objects?

                      Edited by: Lucian2 on May 29, 2013 6:22 AM

                      Edited by: Lucian2 on May 29, 2013 6:23 AM

                      Edited by: Lucian2 on May 29, 2013 6:24 AM

                      Edited by: Lucian2 on May 29, 2013 6:25 AM