Line segment tree-based ranking determination method and device, equipment and storage medium
Through the combination of line segment trees and hash tables, the number of users in the user score interval is recorded, which solves the problem of big key splitting and improves the efficiency and availability of ranking query in large-scale user scenarios.
Patent Information
- Application Number
- CN202510564601.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-15
AI Technical Summary
When the user scale is large, ranking query based on ordered string sets requires large key splitting and large amount of data processing, resulting in poor ranking query efficiency.
The ranking determination method based on the segment tree is adopted, and the number of users in different fractional intervals is recorded through the preset segment tree, and the preset hash table is used to persist the storage node marks to avoid big key splitting, and the number of users is directly queried in the preset database.
Effectively reduce the data processing volume of ranking queries, improve the efficiency of ranking queries, and enhance the high availability of ranking queries, ensuring that ranking queries can still be provided normally after the service restarts.
Smart Images

Figure CN120492469A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for determining a ranking based on a segment tree. Background Art
[0002] With the development of computer technology and Internet technology, more and more users are participating in social platforms, and the activities provided by social platforms are becoming more and more diverse. In order to stimulate users' interest in participating in activities, users are often ranked according to their scores and corresponding rankings are generated.
[0003] When calculating user rankings, we typically first query the user's score, then query the number of users with a score greater than the user's score. The number of users with a score greater than the user's score determines the user's ranking. User rankings are typically queried using an ordered string set in the database (e.g., a zset in a Redis database). This is typically done using a hash table and a skip list. The hash table is used to store user scores, and the skip list is used to sort the scores.
[0004] However, when the user scale is large, the ordered string set needs to process a large amount of data, and the ordered string set will have the problem of large keys. The ordered string set needs to be split and the data related to different users needs to be placed in different ordered string subsets. This ranking query method requires querying multiple ordered string subsets, and the ranking query efficiency is poor. Summary of the Invention
[0005] The embodiments of the present application provide a ranking determination method, apparatus, device, and storage medium based on a segment tree to address the technical problem in related technologies that, when the user scale is large, ranking queries based on ordered string sets require large key splitting and large amounts of data processing, resulting in poor ranking query efficiency. By eliminating the need for large key splitting, the data processing volume of ranking queries can be effectively reduced, thereby improving ranking query efficiency.
[0006] In a first aspect, an embodiment of the present application provides a ranking determination method based on a segment tree, comprising:
[0007] Upon receiving a ranking query request, determining a target user score indicated by the ranking query request;
[0008] Determining one or more target score intervals in a preset segment tree based on the target user score, wherein the preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node labels, the node labels and the number of users in the corresponding score intervals are recorded in a preset hash table, and the preset hash table is persistently stored in a preset database;
[0009] Determining the number of target users corresponding to one or more target score intervals in the preset hash table according to the node tags corresponding to the one or more target score intervals;
[0010] Target ranking information is determined according to one or more of the target user quantities.
[0011] In a second aspect, an embodiment of the present application provides a ranking determination device based on a segment tree, comprising a score determination module, an interval determination module, a quantity determination module, and a ranking determination module, wherein:
[0012] The score determination module is configured to, upon receiving a ranking query request, determine a target user score indicated by the ranking query request;
[0013] The interval determination module is configured to determine one or more target score intervals in a preset segment tree based on the target user score, wherein the preset segment tree includes a plurality of segment tree nodes, different segment tree nodes correspond to different score intervals and node labels, the node labels and the number of users in the corresponding score intervals are recorded in a preset hash table, and the preset hash table is persistently stored in a preset database;
[0014] The quantity determination module is configured to determine the number of target users corresponding to one or more target score intervals in the preset hash table according to the node tags corresponding to the one or more target score intervals;
[0015] The ranking determination module is configured to determine target ranking information according to one or more target user quantities.
[0016] In a third aspect, an embodiment of the present application provides a ranking determination device based on a segment tree, comprising: a memory and one or more processors;
[0017] The memory is used to store one or more programs;
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the ranking determination method based on the segment tree as described in the first aspect.
[0019] In a fourth aspect, an embodiment of the present application provides a non-volatile storage medium storing computer-executable instructions, which, when executed by a computer processor, are used to perform the ranking determination method based on the segment tree as described in the first aspect.
[0020] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor of the device reads and executes the computer program from the computer-readable storage medium, so that the device performs the ranking determination method based on the segment tree as described in the first aspect.
[0021] In an embodiment of the present application, upon receiving a ranking query request, one or more target score intervals are determined in a preset segment tree according to the target user score indicated by the ranking query request, and the number of target users corresponding to the one or more target score intervals is determined in a preset hash table according to the node tags corresponding to the one or more target score intervals. Target ranking information can be determined based on the number of target users. The preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags, and the node tags and the number of users in the corresponding score intervals are recorded through a preset hash table. The preset hash table is persistently stored in a preset database, so that the segment tree can be persistently stored in the preset database. Even if the service is restarted, the ranking query service can be provided normally, thereby enhancing the high availability of the ranking query. In addition, the number of users in different score intervals is recorded by different segment tree nodes of the preset segment tree, and user ranking queries can be implemented without major key splitting, which can effectively reduce the data processing volume of the ranking query and improve the efficiency of the ranking query. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a flowchart of a ranking determination method based on a segment tree provided in an embodiment of the present application;
[0023] Figure 2 This is a schematic diagram of the structure of a preset segment tree provided in an embodiment of the present application;
[0024] Figure 3 This is a flowchart of another method for determining a ranking based on a segment tree provided in an embodiment of the present application;
[0025] Figure 4 This is a schematic diagram of a preset segment tree establishment process provided by an embodiment of the present application;
[0026] Figure 5 1 is a schematic structural diagram of a ranking determination device based on a segment tree provided in an embodiment of the present application;
[0027] Figure 6 This is a structural diagram of a ranking determination device based on a segment tree provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solutions and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. It should also be noted that, for ease of description, only some, but not all, of the contents related to the present application are shown in the accompanying drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The above process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The above process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0029] The ranking determination method based on the segment tree provided in this application can be applied to ranking statistics in large-scale user scenarios. It aims to record the number of users in different score intervals through different segment tree nodes of the preset segment tree to realize user ranking query, reduce the data processing volume of ranking query, and improve the efficiency of ranking query.
[0030] Existing user ranking query solutions typically use an ordered string set in the database. Ordered string sets are typically used to query user rankings using hash tables and skip lists. The hash table is used to store user scores, and the skip list is used to sort scores. However, when the user base is large, the ordered string set needs to handle a large amount of data. This can lead to large keys, necessitating splitting the ordered string set, placing data related to different users into different ordered string subsets. This table swap also saves each user's score, increasing data storage costs and making it more difficult to split the larger ordered string set, resulting in poor ranking query efficiency. For bucket ranking, when the score range is small, such as within 1000, the array int s
[1001] can be initialized with {0}, indicating that the number of users with scores between 0 and 1000 is 0. When a user's score changes from x to y, the execution of s[x]--, s[y]++ is sufficient: the number of users with score x is decremented by 1, and the number of users with score y is incremented by 1. Assuming the user's final score is x, to query their ranking, we traverse the number of users with scores from 1000 to x+1 from high to low and accumulate them, that is, the ranking is rank = s
[1000] + s
[999] + ... + s[x+1]. However, when the score range is large, for example, the score range is within 1 million, then the above bucket ranking needs to be traversed during the query, which has a large O(N) complexity and poor ranking query efficiency. Based on this, a ranking determination method based on a segment tree in an embodiment of the present application is provided to solve the technical problem of poor ranking query efficiency in existing user ranking query solutions.
[0031] Figure 1 A flowchart of a segment tree-based ranking determination method provided in an embodiment of the present application is given. The segment tree-based ranking determination method provided in an embodiment of the present application can be executed by a segment tree-based ranking determination device, which can be implemented in hardware and / or software and integrated into a segment tree-based ranking determination device.
[0032] The following description is made by taking the segment tree-based ranking determination device executing the segment tree-based ranking determination method as an example. Figure 1 , the ranking determination method based on segment tree includes:
[0033] S110: Upon receiving a ranking query request, determining a target user score indicated by the ranking query request.
[0034] In one embodiment, when a user or service end needs to query the ranking corresponding to a target user, it can generate a ranking query request based on the target user and send the ranking query request to the segment tree-based ranking determination device. For example, upon receiving the ranking query request, the user score of the target user corresponding to the ranking query request is determined and determined as the target user score.
[0035] Optionally, the ranking query request provided in the present application may carry the target user score of the target user, for example, determining the target user score of the target user based on the parsing result of the ranking query request. The ranking query request may also not carry the target user score, for example, determining the target user based on the parsing result of the ranking query request, and then querying the target user score of the target user from the database.
[0036] S120: Determine one or more target score intervals in a preset segment tree according to the target user score.
[0037] This application divides the score range into multiple score intervals and records the number of users corresponding to each score interval through a preset segment tree. Among them, the preset segment tree provided by this application includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags (node subscripts), and the node tags and the number of users in the corresponding score interval are recorded through a preset hash table, and the preset hash table is persistently stored in a preset database. Optionally, the score interval can be represented by an array, for example, the score interval can be represented as [l, r], where l and r are the minimum endpoint value and the maximum endpoint value of the score interval respectively.
[0038] like Figure 2 As shown in the structural diagram of a preset segment tree, assuming that the score range is 1-8, the score range is divided into multiple score intervals, and each score interval corresponds to a segment tree node of the preset segment tree. Each segment tree node of the preset segment tree corresponds to a node label (indicated by idx in the figure), and the node labels increase from top to bottom and from left to right. For example, the score interval corresponding to the current segment tree node is [l, r], and the node label is idx. Then the score interval corresponding to the left child node of the segment tree node is [l, m], m is between l and r, and the node label is idx*2. The score interval corresponding to the right child node is [m+1, r], and the node label is idx*2+1. Figure 2As shown, the score interval [1, 8] corresponds to the root node of the preset segment tree, and the score interval [1, 1] to the score interval [8, 8] respectively correspond to a leaf node of the preset segment tree. The score interval corresponding to each segment tree node is a combination of the score intervals corresponding to the left and right child nodes of the segment tree node. The score intervals corresponding to the left and right child nodes of the segment tree node have the same length. Assuming that s[a, b] represents the number of users with scores between a and b, then s[1, 1]+s[2, 2]=s[1, 2], s[1, 2]+s[3, 4]=s[1, 4].
[0039] For example, after determining the target user score of the target user, one or more target score intervals are determined from multiple score intervals in the preset segment tree based on the target user score. The user ranking of this application requires counting the number of users whose user scores are above the target user score of the target user. The minimum endpoint value of the target score interval is greater than the target score interval. When determining multiple target score intervals, there are no intersecting intervals between the multiple target score intervals.
[0040] In one embodiment, the segment tree nodes of a preset segment tree can be recursively processed to determine whether the score intervals corresponding to each segment tree node can be used as a target score interval. When a segment tree node can be used as a target score interval, the child nodes of the segment tree can no longer be recursively processed (the child nodes of the segment tree have intersecting intervals with the child nodes of the segment tree), and the recursion on other segment tree nodes can continue.
[0041] S130: Determine the number of target users corresponding to the one or more target score intervals in a preset hash table according to the node tags corresponding to the one or more target score intervals.
[0042] Exemplarily, the node labels corresponding to the one or more target score intervals determined above are determined, and the number of target users corresponding to the one or more target score intervals is determined in a preset hash table according to the node labels.
[0043] In one embodiment, the preset hash table can record the correspondence between the node tag and the number of users in the form of a key-value pair, for example, using the preset tag as a prefix, and connecting the node tag to obtain the key corresponding to the node tag, and recording the number of users corresponding to the node tag with the number of users as the value. For example, in the preset database Redis, assuming that the preset tag is "tree", key=tree-1 represents the data with the node tag of 1 in the preset database Redis. Based on this, after determining the node tag corresponding to the target score interval, the node tag can be used as a key to query the corresponding value in the preset hash table, and the queried value can be used as the target user score.
[0044] S140: Determine target ranking information according to the number of one or more target users.
[0045] Exemplarily, the target ranking information is determined based on the one or more target user numbers determined above. For example, the target ranking information can be determined based on the one or more target user numbers by adding the one or more target user numbers to 1 to obtain the target ranking information, thereby accurately determining the target ranking information of the target user.
[0046] Combine Figure 2 Assuming the target user score is 5, the target score interval can be determined to be [6, 6] and [7, 8], and the corresponding node labels are idx=13 and idx=7. Then, the values corresponding to key=tree-13 and key=tree-7 can be queried in the preset hash table to obtain the target user scores s[6, 6] and s[7, 8] corresponding to the target score intervals [6, 6] and [7, 8]. At this time, the target ranking information rank(5)=s[6, 6]+s[7, 8]+1. Assuming the target user score is 7, the target score interval can be determined to be [8, 8], and the corresponding node label is idx=15. Then, the value corresponding to key=tree-15 can be queried in the preset hash table to obtain the target user score s[8, 8] corresponding to the target score interval [8, 8]. At this time, the target ranking information rank(7)=s[8, 8]+1. It can be seen that the query complexity of the ranking determination method based on the segment tree provided in this application is O(logM), where M is the fractional scale (i.e., the number of leaf nodes of the preset segment tree), and its storage space is O(M), while the query complexity of the ranking determination method based on the ordered string set is O(logN), where N is the user scale, and its storage space is hash table O(N) + skip table O(N).
[0047] It can be seen that in the large-scale user scenario, the query complexity and storage space of the ranking determination method based on the segment tree provided by the present application are lower than the ranking determination method based on the ordered string set, achieving a lower data processing volume for ranking queries and a higher ranking query efficiency. In addition, since the segment tree is not natively supported in the Redis database, the conventional segment tree cannot be persistently stored in the database. The present application uses a preset hash table persistently stored in the preset database to record the node mark and the corresponding number of users, thereby realizing the persistent storage of the preset segment tree in the preset database. Even if the service is restarted, the ranking query service can be provided normally, and the preset segment tree will not be deleted, thereby enhancing the high availability of the ranking query. Compared with the situation where the ranking determination method based on the ordered string set needs to split the ordered string set, the present application accesses the preset hash table through the subscript (node mark) and uses scattered keys to store the node mark and the corresponding number of users in the Redis database. The query of user ranking can be realized without the need for large key splitting. The ranking based on the ordered string set is related to the user scale, while the ranking of the segment tree is related to the score range. When the user scale is large and the score range is relatively small, the segment tree ranking can greatly reduce the data storage space while effectively avoiding the problem of large keys. In addition, the storage of discrete keys can also make the distribution of each shard data (Redis shard data) more balanced, reducing data storage pressure.
[0048] In the above, when a ranking query request is received, one or more target score intervals are determined in a preset segment tree according to the target user score indicated by the ranking query request, and the number of target users corresponding to the one or more target score intervals is determined in a preset hash table according to the node tags corresponding to the one or more target score intervals. The target ranking information can be determined according to the number of target users. The preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags, and the node tags and the number of users in the corresponding score intervals are recorded through a preset hash table. The preset hash table is persistently stored in a preset database, so that the segment tree can be persistently stored in the preset database. Even if the service is restarted, the ranking query service can be provided normally, thereby enhancing the high availability of the ranking query. Moreover, the number of users in different score intervals is recorded by different segment tree nodes of the preset segment tree, and the query of user ranking can be realized without large key splitting, which can effectively reduce the data processing volume of the ranking query and improve the efficiency of the ranking query.
[0049] Based on the above embodiments, Figure 3 A flowchart of another segment tree-based ranking determination method provided in an embodiment of the present application is given. The segment tree-based ranking determination method is a concretization of the above segment tree-based ranking determination method.
[0050] refer to Figure 3 , the ranking determination method based on segment tree includes:
[0051] S210: Upon receiving a ranking query request, determine a target user score indicated by the ranking query request.
[0052] In one possible embodiment, Figure 4 As shown in the schematic diagram of a preset segment tree establishment process, the segment tree-based ranking determination method provided in this application further includes, before receiving a ranking query request:
[0053] S201: Determine a plurality of score intervals according to the business data distribution, wherein the length of the score interval is negatively correlated with the distribution density corresponding to the business data distribution.
[0054] S202: Establish a preset segment tree according to the score interval, wherein a plurality of segment tree child nodes in the preset segment tree correspond to the score interval.
[0055] For example, business data is collected and the distribution of the business data is determined, and multiple score intervals can be determined based on the business data distribution. The length of the score interval is negatively correlated with the distribution density corresponding to the business data distribution (i.e., the greater the density, the shorter the score interval). That is, the more densely distributed the business data is, the shorter the score interval can be set, and the more sparsely distributed the business data is, the longer the score interval can be set.
[0056] Optionally, the business data may be user scores corresponding to multiple users, and the business data distribution may be the distribution of the number of users corresponding to the multiple user scores. In this case, a shorter score interval may be set in a score range where the number of users is denser, and a longer score interval may be set in a score range where the number of users is sparser.
[0057] In one embodiment, after determining multiple score intervals, a preset segment tree can be established based on the multiple score intervals. In this case, multiple segment tree child nodes in the preset segment tree correspond to the score intervals, and two score intervals with adjacent scores can serve as child nodes of the segment tree node at the previous level. This application reduces data storage and processing costs by determining multiple score intervals based on the distribution of business data and establishing a preset segment tree based on the score intervals, achieving a balance between ranking accuracy and storage space usage.
[0058] S220: Determine one or more target score intervals in a preset segment tree according to the target user score.
[0059] In one possible embodiment, the segment tree-based ranking determination method provided in the present application determines one or more target score intervals in a preset segment tree according to the target user score. It can be based on the target user score and the score intervals corresponding to multiple segment tree nodes in the preset segment tree, and determines a target score interval greater than the target user score from multiple score intervals.
[0060] For example, after determining the target user score, the target user score is compared with the score intervals corresponding to multiple segment tree nodes in a preset segment tree. Score intervals with corresponding scores greater than the target user score are determined from the multiple score intervals, and these score intervals are determined as target score intervals (multiple target score intervals do not intersect). The number of users corresponding to these target score intervals is added together to calculate the total number of users with user scores greater than the target user score. By determining a target score interval greater than the target user score from multiple score intervals, the present application accurately determines the number of users with user scores greater than the target user score and accurately evaluates the target ranking information of the target user.
[0061] In one embodiment, the segment tree-based ranking determination method provided in this application determines a target score interval greater than the target user score from multiple score intervals based on the target user score and the score intervals corresponding to multiple segment tree nodes in a preset segment tree, and may include:
[0062] S221: traverse the score intervals corresponding to the segment tree nodes of the preset segment tree, and recursively search the segment tree nodes when the minimum value of the score interval corresponding to the segment tree node is less than or equal to the target user score and the maximum value of the interval is greater than the target user score.
[0063] S222: When the maximum value of the score interval corresponding to the segment tree node is less than or equal to the target user score, skip the segment tree node.
[0064] S223: When the minimum value of the score interval corresponding to the segment tree node is greater than the target user score, determine the score interval as a target score interval greater than the target user score.
[0065] For example, the score intervals corresponding to each segment tree node of the preset segment tree are traversed. For the currently traversed score interval, the minimum and maximum values of the current score interval are determined to compare with the target user's score. The minimum and maximum values of the score interval are the left and right endpoints of the score interval, respectively.
[0066] In one embodiment, when the minimum value of the score interval corresponding to the segment tree node is less than or equal to the target user score, and the maximum value of the interval is greater than the target user score, it can be determined that the target user score is within the current score interval, and the current score interval also contains a sub-interval that is smaller than the target user score. In this case, it is necessary to recurse the segment tree node to continue to determine whether the score interval corresponding to the child node of the segment tree node can be used as the target score interval.
[0067] In one embodiment, when the maximum value of the score interval corresponding to the segment tree node is less than or equal to the target user score, it can be determined that the target user score is within or above the current score interval, and there is no need to process the current segment tree node and subsequent child nodes. In this case, the segment tree node is skipped and the segment tree nodes of other branches are processed, thereby reducing the amount of data processing and improving the efficiency of ranking determination.
[0068] In one embodiment, when the minimum value of the score interval corresponding to the segment tree node is greater than the target user score, the target user score is below the current score interval, and the current score interval is a target score interval greater than the target user score. There is no need to recurse the child nodes of the segment tree node, and the process can jump to the segment tree node that processes other branches.
[0069] For example, combined with Figure 2 Given a preset segment tree, assuming the target user score is 5, we traverse the score intervals corresponding to each segment tree node in the preset segment tree, starting from the root node. For segment tree node idx=1, corresponding to the score interval [1, 8], the interval minimum value 1 is less than the target user score 5, and the interval maximum value 8 is greater than the target user score 8. We can recursively search for the left child node idx=2 and the right child node idx=3 of segment tree node idx=1.
[0070] For the segment tree node idx=2 corresponding to the score interval [1, 4], the interval maximum value 4 of the score interval [1, 4] is less than the target user score 5, and the segment tree node idx=2 and its child nodes (segment tree nodes with idx=4, 5, 8-11) can be skipped.
[0071] For the score interval [5, 8] corresponding to the segment tree node idx=3, the interval minimum value 5 of the score interval [5, 8] is equal to the target user score 5, and the interval maximum value 8 is greater than the target user score 5. Recursively, the segment tree node can be recursively searched for the left child node idx=6 and the right child node idx=7 of the segment tree node idx=3. For the score interval [5, 6] corresponding to the segment tree node idx=6, the interval minimum value 5 of the score interval [5, 6] is equal to the target user score 5, and the interval maximum value 6 is greater than the target user score 5. Recursively, the segment tree node can be recursively searched for the left child node idx=12 and the right child node idx=13 of the segment tree node idx=6.
[0072] For the segment tree node idx = 12, which corresponds to the score interval [5, 5], the maximum value 5 of the score interval [5, 5] is equal to the target user score 5, so the segment tree node idx = 12 can be skipped. For the segment tree node idx = 13, which corresponds to the score interval [6, 6], the minimum value 6 of the score interval [6, 6] is greater than the target user score 5, so the score interval [6, 6] can be determined as a target score interval.
[0073] For the score interval [7, 8] corresponding to the segment tree node idx=7, the interval minimum value 7 of the score interval [7, 8] is greater than the target user score 5. The score interval [7, 8] can be determined as a target score interval, and the child nodes of the segment tree node idx=7 (the segment tree nodes with idx=14, 15) are skipped. This application accurately determines the target score interval by traversing the score intervals corresponding to each segment tree node of the preset segment tree, and accurately determines the number of users with scores higher than the target user score based on the comparison between the target score and the interval minimum and interval maximum values of the score interval.
[0074] S230: Determine the number of target users corresponding to the one or more target score intervals in a preset hash table according to the node tags corresponding to the one or more target score intervals.
[0075] S240: Determine target ranking information according to the number of one or more target users.
[0076] S250: When a data update notification is received, one or more target update intervals are determined in a preset segment tree according to the data update notification, and the number of users in the target update intervals is updated.
[0077] In one embodiment, when a user end or service end detects a change in a user score, it may generate a corresponding data update notification and send it to a segment tree-based ranking determination device. The data update notification may be used to indicate the user's first user score before the update and the second user score after the update. For example, if a user's score before the update was 3 and the user score after the update was 6, the first and second user scores corresponding to the data update notification would be 3 and 6, respectively, indicating that the user's score has changed from 3 to 6.
[0078] For example, when a data update notification is received, one or more score intervals affected by the user score change can be determined in a preset segment tree based on the data update notification, and the score intervals affected by the user score change can be determined as target update intervals, and the number of users in the target update interval can be updated.
[0079] The impact of a change in user scores on a score interval can be either an increase in the number of users corresponding to that score interval (corresponding to an increase in the number of users in the target update interval) or a decrease in the number of users corresponding to that score interval (corresponding to a decrease in the number of users in the target update interval). This application improves the accuracy of user ranking queries by determining a target update interval in a preset segment tree based on data update notifications and updating the number of users in the target update interval in real time.
[0080] In one embodiment, the segment tree-based ranking determination method provided in the present application determines one or more target update intervals in a preset segment tree based on a data update notification. This method may be: based on the first user score before the update and the second user score after the update corresponding to the data update notification, and the score intervals corresponding to multiple segment tree nodes in the preset segment tree, determine a first target update interval covering the first user score and a second target update interval covering the second user score from multiple score intervals. Accordingly, the number of users in the target update interval may be updated by increasing the number of users in the first target update interval and decreasing the number of users in the second target update interval.
[0081] Exemplarily, after receiving a data update notification, the first user score before the update and the second user score after the update corresponding to the data update notification are determined, and a score interval covering the first user score is determined among the score intervals corresponding to multiple segment tree nodes in a preset segment tree, and the score interval covering the first user score is determined as the first target update interval, and the score interval covering the second user score is determined, and the score interval covering the second user score is determined as the second target update interval.
[0082] In one embodiment, the number of users in the first target update interval determined above is increased (e.g., the number of users in the first target update interval is increased by one), and the number of users in the second target update interval determined above is decreased (e.g., the number of users in the second target update interval is decreased by one). Optionally, the data update notification may be issued for one user or for multiple users. When the data update notification indicates that a first number of users have their scores updated from the first user to the second user, after determining the first target update interval and the second target update interval, the number of users in the first target update interval is increased by the first number, and the number of users in the second target update interval is decreased by the first number.
[0083] For example, traverse each segment tree node of the preset segment tree to determine whether the score interval corresponding to the segment tree node covers the first user score or the second user score. If the score interval covers the first user score, the corresponding score interval is determined as the first target update interval; if the score interval covers the second user score, the corresponding score interval is determined as the second target update interval. Figure 2 In the provided preset segment tree structure, assuming that a user's score is updated from a first user score of 3 to a second user score of 6, it can be seen that the score intervals [1, 8], [1, 4], [3, 4], and [3, 3] corresponding to segment tree nodes idx = 1, 2, 5, 10 all cover the first user score of 3. Therefore, the score intervals [1, 8], [1, 4], [3, 4], and [3, 3] can be determined as the first target update interval. The score intervals [1, 8], [5, 8], [5, 6], and [6, 6] corresponding to segment tree nodes idx = 1, 3, 6, 13 all cover the second user score of 6. Therefore, the score intervals [1, 8], [5, 8], [5, 6], and [6, 6] can be determined as the second target update interval. Among them, the score interval [1, 8] serves as both the first target update interval and the second target update interval, and the number of users in it does not change.
[0084] The present application determines the first target update interval and the second target update interval based on the first user score before the update and the second user score after the update corresponding to the data update notification, as well as the score intervals corresponding to multiple segment tree nodes in a preset segment tree, and updates the number of users in the first target update interval and the second target update interval in a targeted manner, thereby achieving real-time update of the number of users in the target update interval and improving the accuracy of user ranking queries.
[0085] In the above, when a ranking query request is received, one or more target score intervals are determined in a preset segment tree according to the target user score indicated by the ranking query request, and the number of target users corresponding to the one or more target score intervals is determined in a preset hash table according to the node tags corresponding to the one or more target score intervals. The target ranking information can be determined according to the number of target users. The preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags, and the node tags and the number of users in the corresponding score intervals are recorded through a preset hash table. The preset hash table is persistently stored in a preset database, so that the segment tree can be persistently stored in the preset database. Even if the service is restarted, the ranking query service can be provided normally, thereby enhancing the high availability of the ranking query. Moreover, the number of users in different score intervals is recorded by different segment tree nodes of the preset segment tree, and the query of user ranking can be realized without large key splitting, which can effectively reduce the data processing volume of the ranking query and improve the efficiency of the ranking query. The first target update interval and the second target update interval can also be determined based on the first user score before the update and the second user score after the update corresponding to the data update notification, as well as the score intervals corresponding to multiple segment tree nodes in the preset segment tree, and the number of users in the first target update interval and the second target update interval can be updated in a targeted manner to achieve real-time update of the number of users in the target update interval, thereby improving the accuracy of user ranking queries.
[0086] Figure 5 Schematic diagram of a ranking determination device based on a segment tree provided in an embodiment of the present application. Figure 5 The ranking determination device based on the segment tree includes a score determination module 51 , an interval determination module 52 , a quantity determination module 53 and a ranking determination module 54 .
[0087] Among them, the score determination module 51 is configured to determine the target user score indicated by the ranking query request when receiving the ranking query request; the interval determination module 52 is configured to determine one or more target score intervals in a preset segment tree based on the target user score, wherein the preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags, the node tags and the number of users in the corresponding score interval are recorded through a preset hash table, and the preset hash table is persistently stored in a preset database; the quantity determination module 53 is configured to determine the number of target users corresponding to one or more target score intervals in the preset hash table based on the node tags corresponding to the one or more target score intervals; the ranking determination module 54 is configured to determine target ranking information based on the number of one or more target users.
[0088] In the above, when a ranking query request is received, one or more target score intervals are determined in a preset segment tree according to the target user score indicated by the ranking query request, and the number of target users corresponding to the one or more target score intervals is determined in a preset hash table according to the node tags corresponding to the one or more target score intervals. The target ranking information can be determined according to the number of target users. The preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node tags, and the node tags and the number of users in the corresponding score intervals are recorded through a preset hash table. The preset hash table is persistently stored in a preset database, so that the segment tree can be persistently stored in the preset database. Even if the service is restarted, the ranking query service can be provided normally, thereby enhancing the high availability of the ranking query. Moreover, the number of users in different score intervals is recorded by different segment tree nodes of the preset segment tree, and the query of user ranking can be realized without large key splitting, which can effectively reduce the data processing volume of the ranking query and improve the efficiency of the ranking query.
[0089] In a possible embodiment, the interval determination module 52 determines one or more target score intervals in a preset segment tree according to the target user score, and is configured as follows:
[0090] According to the target user score and the score intervals corresponding to the plurality of segment tree nodes in the preset segment tree, a target score interval greater than the target user score is determined from the plurality of score intervals.
[0091] In one possible embodiment, the interval determination module 52 determines a target score interval greater than the target user score from among multiple score intervals based on the target user score and the score intervals corresponding to multiple segment tree nodes in a preset segment tree, and is configured as follows:
[0092] Traversing the score intervals corresponding to the segment tree nodes of the preset segment tree, and recursively searching the segment tree nodes when the minimum value of the score interval corresponding to the segment tree node is less than or equal to the target user score and the maximum value of the interval is greater than the target user score;
[0093] If the maximum value of the score interval corresponding to the segment tree node is less than or equal to the target user score, skip the segment tree node;
[0094] When the minimum value of the score interval corresponding to the segment tree node is greater than the target user score, the score interval is determined to be a target score interval greater than the target user score.
[0095] In a possible embodiment, the ranking determination apparatus based on the segment tree further includes an update processing module, and the update processing module is configured to:
[0096] Upon receiving a data update notification, determining one or more target update intervals in a preset segment tree according to the data update notification;
[0097] Update the number of users in the target update interval.
[0098] In a possible embodiment, the update processing module determines one or more target update intervals in a preset segment tree according to the data update notification, and is configured as follows:
[0099] Determining, from the plurality of score intervals, a first target update interval covering the first user score and a second target update interval covering the second user score based on the first user score before the update and the second user score after the update corresponding to the data update notification, and score intervals corresponding to a plurality of segment tree nodes in a preset segment tree;
[0100] Accordingly, the update processing module updates the number of users in the target update interval, which is configured as follows:
[0101] The number of users in the first target update interval is increased, and the number of users in the second target update interval is decreased.
[0102] In a possible embodiment, the ranking determination module 54 determines the target ranking information according to one or more target user numbers, and is configured to add the one or more target user numbers to 1 to obtain the target ranking information.
[0103] In a possible embodiment, the ranking determination apparatus based on a segment tree further includes a segment tree creation module, and the segment tree creation module is configured to:
[0104] Determine multiple score intervals based on the business data distribution, where the length of the score interval is negatively correlated with the distribution density corresponding to the business data distribution;
[0105] A preset segment tree is established according to the score interval, and a plurality of segment tree child nodes in the preset segment tree correspond to the score interval.
[0106] It is worth noting that in the above-mentioned embodiment of the ranking determination device based on the segment tree, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present application.
[0107] The embodiment of the present application further provides a segment tree-based ranking determination device, which can integrate the segment tree-based ranking determination apparatus provided in the embodiment of the present application. Figure 6 Schematic diagram of a ranking determination device based on a segment tree provided in an embodiment of the present application. Figure 6The segment tree-based ranking determination device includes: an input device 63, an output device 64, a memory 62, and one or more processors 61. The memory 62 is used to store one or more programs. When the one or more programs are executed by the one or more processors 61, the one or more processors 61 implement the segment tree-based ranking determination method provided in the above embodiments. The segment tree-based ranking determination device, equipment, and computer provided above can be used to implement the segment tree-based ranking determination method provided in any of the above embodiments, and have corresponding functions and beneficial effects.
[0108] The embodiment of the present application also provides a non-volatile storage medium that stores computer-executable instructions, and the computer-executable instructions are used to execute the ranking determination method based on the segment tree provided in the above embodiment when executed by a computer processor. Of course, the non-volatile storage medium that stores computer-executable instructions provided in the embodiment of the present application, its computer-executable instructions are not limited to the ranking determination method based on the segment tree provided above, and can also execute the relevant operations in the ranking determination method based on the segment tree provided in any embodiment of the present application. The ranking determination device, equipment and storage medium based on the segment tree provided in the above embodiment can execute the ranking determination method based on the segment tree provided in any embodiment of the present application. For technical details not described in detail in the above embodiment, please refer to the ranking determination method based on the segment tree provided in any embodiment of the present application.
[0109] Based on the above embodiments, the embodiments of the present application also provide a computer program product. The essence of the technical solution of the present application or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer program product is stored in a storage medium and includes a number of instructions for enabling a computer device, a mobile terminal or a processor therein to execute all or part of the steps of the segment tree-based ranking determination method provided in each embodiment of the present application.
Claims
1. A ranking determination method based on a segment tree, characterized in that: include: Upon receiving a ranking query request, determining a target user score indicated by the ranking query request; Determining one or more target score intervals in a preset segment tree based on the target user score, wherein the preset segment tree includes multiple segment tree nodes, different segment tree nodes correspond to different score intervals and node labels, the node labels and the number of users in the corresponding score intervals are recorded in a preset hash table, and the preset hash table is persistently stored in a preset database; Determining the number of target users corresponding to one or more target score intervals in the preset hash table according to the node tags corresponding to the one or more target score intervals; Target ranking information is determined according to one or more of the target user quantities.
2. The ranking determination method based on segment tree according to claim 1, characterized in that: Determining one or more target score intervals in a preset segment tree according to the target user score includes: According to the target user score and score intervals corresponding to a plurality of segment tree nodes in a preset segment tree, a target score interval greater than the target user score is determined from the plurality of score intervals.
3. The ranking determination method based on segment tree according to claim 2, characterized in that: The step of determining a target score interval greater than the target user score from among the multiple score intervals based on the target user score and the score intervals corresponding to the multiple segment tree nodes in the preset segment tree includes: Traversing the score intervals corresponding to each segment tree node of the preset segment tree, and recursively searching the segment tree node when the minimum value of the score interval corresponding to the segment tree node is less than or equal to the target user score and the maximum value of the interval is greater than the target user score; If the maximum value of the score interval corresponding to the segment tree node is less than or equal to the target user score, skip the segment tree node; In a case where the minimum value of the score interval corresponding to the segment tree node is greater than the target user score, the score interval is determined to be a target score interval greater than the target user score.
4. The ranking determination method based on segment tree according to claim 1, characterized in that: The ranking query method further includes: Upon receiving a data update notification, determining one or more target update intervals in a preset segment tree according to the data update notification; Update the number of users in the target update interval.
5. The ranking determination method based on segment tree according to claim 4, characterized in that: Determining one or more target update intervals in a preset segment tree according to the data update notification includes: Determining, based on the first user score before the update and the second user score after the update corresponding to the data update notification, and score intervals corresponding to multiple segment tree nodes in a preset segment tree, a first target update interval covering the first user score and a second target update interval covering the second user score from the multiple score intervals; Accordingly, the updating of the number of users in the target update interval includes: The number of users in the first target update interval is increased, and the number of users in the second target update interval is decreased.
6. The ranking determination method based on segment tree according to claim 1, characterized in that: The determining target ranking information according to one or more target user numbers includes: The number of one or more target users is added to 1 to obtain target ranking information.
7. The ranking determination method based on segment tree according to claim 1, characterized in that: Before receiving the ranking query request, the method further includes: Determine a plurality of score intervals according to the business data distribution, wherein the length of the score interval is negatively correlated with the distribution density corresponding to the business data distribution; A preset segment tree is established according to the score interval, and a plurality of segment tree child nodes in the preset segment tree correspond to the score interval.
8. A ranking determination device based on a segment tree, characterized in that: It includes a score determination module, an interval determination module, a quantity determination module and a ranking determination module, wherein: The score determination module is configured to, upon receiving a ranking query request, determine a target user score indicated by the ranking query request; The interval determination module is configured to determine one or more target score intervals in a preset segment tree based on the target user score, wherein the preset segment tree includes a plurality of segment tree nodes, different segment tree nodes correspond to different score intervals and node labels, the node labels and the number of users in the corresponding score intervals are recorded in a preset hash table, and the preset hash table is persistently stored in a preset database; The quantity determination module is configured to determine the number of target users corresponding to one or more target score intervals in the preset hash table according to the node tags corresponding to the one or more target score intervals; The ranking determination module is configured to determine target ranking information according to one or more target user quantities.
9. A ranking determination device based on a segment tree, characterized in that: include: memory and one or more processors; The memory is used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the ranking determination method based on the segment tree according to any one of claims 1 to 7.
10. A non-volatile storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to perform the ranking determination method based on a segment tree according to any one of claims 1 to 7.
11. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the ranking determination method based on a segment tree according to any one of claims 1 to 7 is implemented.