The most efficient way to store arbitrary sort order?

I am currently working on an Android application where users can order their list using drag and drop in any order. Therefore, I have to keep the sort order in a variable in the column. I thought to give each line the number 100000, 200000, 300000, etc., And if the user moves the item between 100000 and 200000, then his sort number becomes the average for his neighbors, that is, 150,000. Thus, I only need to update the sort number one row, unlike each row in the table, if I did the usual sort value, I + 1.

Which is most effective? Do larger numbers use more resources or take more time? I expect only 100 lines, so if larger numbers take longer to sort, I might be better off using smaller numbers and "reloading" more often (when the two types of sorting converge). I know with so many rows, it would not matter if I just made the sorting method I + 1 and updated each row in my db every time. But I also synchronize my SQLite data with BAAS, and most of them do not allow to save lots. Therefore, for each line that I am changing, I have to make 1 API request. This is why I am trying to minimize the number of lines that I change when changing the order of the elements.

Any help would be greatly appreciated.

+7
android sorting mysql sqlite
source share
1 answer

I ended up using only my original way of giving each line the number 100000, 200000, 300000, etc., and if the user moves the item between 100000 and 200000, then his sort number becomes the average for his neighbors, that is, 150,000. Since the number of lines is relatively small ~ 50, I chose this method, which may not be effective, but is the simplest.

0
source share

All Articles