Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.

How can I do this in an efficient manner? I’ve thought of the following options:

  1. Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don’t really like this solution.

  2. Add a “priority” field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform’s float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.

  3. Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.

Am I missing the obvious? Is there a better way?

2

You’re probably overthinking the efficiency aspect. Any list small enough for a human to reasonably reorder via drag and drop is trivial for a computer to manipulate, even with very “inefficient” algorithms. Also keep in mind that humans are very slow, and updating the order is a relatively infrequent operation compared to querying for it.

However, I believe the algorithm with the best tradeoffs between query time and update time would be what I call the BASIC algorithm. BASIC programs used to have integer line numbers to make interactive programming easier. Because you might need to insert a line between two lines, you would start out numbering them by 10s. If you needed to insert a line between, you’d make it a multiple of 5, and so on. If you ran out of space in between, there was a renum command that put everything back to multiples of 10.

Using this method to sort objects would mean most of the time, you just need to update the one row, with the occasional renumbering of the entire list when you run out of space in between. Since the numbers wouldn’t be user-visible, you can put quite a bit of space in between, so the renumberings should be relatively rare. That gives you a worst case update of O(n), but an amortized update close to O(1).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật