The tree-like structure algorithm of BBS

Source: Internet
Author: User
In the design of algorithm database, the Order_value is used to sort, and the concrete realization is
* * Note that the following discussion is for a topic, that is, for a tree!
If you add a new sticker that order_value=0
If the order_value is bigger than the parent sticker Order_value
If there is a hypothesis for next_value, then the new post
Order_value for the parent (Order_value+next_value)/2;
If there are so new posts of Order_value for the father of the order_value+1000
In other words, if a is affixed to the post, if A is a copybook, the order_value of A is order_value (parent) +1000,
It's not a order_value, it's a bigger than a, and the new order_value is half the size!
Sort implementation: ORDER BY groupid,order_value Desc
* * Skills if you want to achieve a more level can add a little more than +100000, that should be better

Deficiencies:
1: Use two fields to sort with a bit slower speed
2: Using Order_value is a floating-point number, using float is not estimated, or using double
3: Can only realize the theoretical infinity layer actually more than 10 layers using float problem, use double may not
4: Insert is needed to find the next Order_value

Dim OrderValue, NextValue as Double
sql = "Select Gorders where gid=" & GId & "and goders>" & Gorders & "ORDER by Goders"
Rs1. Open sql, CONN1, adopenforwardonly, adlockoptimistic ' queries larger than the parent
Order_value
If (rs1. EOF and Rs1. BOF) Then
Gorders = gorders + 256
Glayer = Glayer + 1
Else
NextValue = Rs1 ("Gorders")
If (nextvalue-gorders) > 1 Then
Gorders = Int ((gorders + nextvalue)/2)
Glayer = Glayer
Else
' Gorders,glayer like a reply.
End If
End If

End Sub



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.