简体   繁体   English

存储任意排序顺序的最有效方法是什么?

[英]Most efficient way to store arbitrary sort order?

I am currently working on an Android app where users can order their list via drag and drop in any order they want. 我目前正在开发一个Android应用程序,用户可以通过任意顺序拖放来订购列表。 Therefore, I must store the sort order in a variable in a column. 因此,我必须将排序顺序存储在列中的变量中。 I was thinking of giving each row a number like 100000, 200000, 300000, etc and if a user moves an item between 100000 and 200000, then its sort number becomes the average of its neighbours ie 150000. This way, I only have to update the single row's sort number as opposed to every row in the table if I did a normal i+1 sort value. 我想给每一行提供100000,200000,300000等数字,如果用户在100000到200000之间移动一个项目,那么它的排序数就会变成其邻居的平均数,即150000.这样,我只需要更新单行的排序编号,而不是表格中的每一行,如果我做了正常的i + 1排序值。

What is the most efficient? 什么是最有效的? Do large numbers use more resources or take longer to sort? 大数字使用更多资源还是需要更长时间才能排序? I only expect <100 rows so if large numbers take longer to sort, I might be better off using smaller numbers and "resetting" more often (when two sort numbers converge onto each other). 我只期望<100行,所以如果大数字需要更长的时间来排序,我可能会更好地使用较小的数字和更频繁地“重置”(当两个排序数字相互聚合时)。 I know with so few rows, it wouldn't really matter if I just did a i+1 sort method and update every row in my db every time. 我知道有这么几行,如果我只是做了一个i + 1排序方法并且每次更新我的数据库中的每一行都没关系。 But I am also syncing my SQLite data with a BAAS and most of them do not allow batch saving. 但我也在将我的SQLite数据与BAAS同步,其中大多数都不允许批量保存。 So for every row I modify, I have to make 1 API request. 因此,对于我修改的每一行,我必须提出1个API请求。 That is why I am trying to minimize the amount of rows I modify when I reorder an item. 这就是为什么我尝试最小化我在重新排序项目时修改的行数。

Any help would be appreciated. 任何帮助,将不胜感激。

我最后只使用我的原始方法为每行提供一个数字,如100000,200000,300000等,如果用户在100000和200000之间移动一个项目,那么它的排序数将成为其邻居的平均值,即150000。我所拥有的行相对较小~50,我选择了这种方法可能效率不高但最简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 高效和跨平台的方式来存储任意排序顺序? - Efficient and cross-platform way to store arbitrary sort order? 在SQLite中将字符串数转换为整数的最有效方法是什么,以便按最高值排序? - What is the most efficient way to convert String numbers to Integers in SQLite, in order to sort by highest value? 最有效的存储位图信息的方式 - Most Efficient Way to Store Bitmap Info Android 在Java中同时对三个ArrayLists进行排序的最有效方法是什么? - What is the most efficient way to simultaneously sort three ArrayLists in Java 在Android开发中存储文本和媒体的最有效方法 - Most efficient way to store text and media in android development Java/Android - 存储许多变量的最有效方法 - Java/Android - Most efficient way to store many variables 在android中存储和检索大量文本数据的最有效方法 - Most efficient way to store and retrieve large amounts of text data in android 在 Realm 中存储长对象列表的最有效方法是什么? - What is the most efficient way to store long list of Objects in Realm? 存储和搜索大量字符串的最有效方法 - Most efficient way to store and search through a large number of strings 在Android的SharedPreferences中存储数组的最有效方法是什么? - What is the most efficient way to store an array in SharedPreferences in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM