In my application users have lists. They can either add a new item to their list or add an item from a previous list. The set of all items I'll call G (global) (each user's global list is their own).
G = { a1, a2, a3,...,an}
After (or during) a user has created a list they can sort it. This has been no problem. The problem happens when try to apply an items order globally. For example, if list one has m items:
L1 = {b1, b2, b3,...,bm}
And the user changes the order of b1 from 1 to 9 in L1. Then when the user saves the list I'd like its global order to change as well. But I'm not sure what to change it to.
Here's how I'm doing this now. Take our list L1:
L1 = {b1, b2, b3,...,bm}
Move b1:
L1 = {b2, b3, b1,...,bm}
Find out the global index of b3 (say 41), add one (42) and that's b1's index. Then find all other items that have a global index greater than or equal to 42 and add one.
What's the best (or at least better) way to do this?