CN111666302A - User ranking query method, device, equipment and storage medium - Google Patents
User ranking query method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN111666302A CN111666302A CN202010469645.5A CN202010469645A CN111666302A CN 111666302 A CN111666302 A CN 111666302A CN 202010469645 A CN202010469645 A CN 202010469645A CN 111666302 A CN111666302 A CN 111666302A
- Authority
- CN
- China
- Prior art keywords
- score
- key value
- value pair
- key
- target
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 74
- 230000008569 process Effects 0.000 claims abstract description 29
- 238000009825 accumulation Methods 0.000 claims abstract description 18
- 238000012217 deletion Methods 0.000 claims description 24
- 230000037430 deletion Effects 0.000 claims description 24
- 238000004590 computer program Methods 0.000 claims description 6
- 238000013507 mapping Methods 0.000 claims description 6
- 238000013500 data storage Methods 0.000 abstract description 7
- 238000012545 processing Methods 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 6
- 230000006870 function Effects 0.000 description 4
- 241000422846 Sequoiadendron giganteum Species 0.000 description 2
- 230000008859 change Effects 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 238000005192 partition Methods 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000002688 persistence Effects 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24553—Query execution of query operations
- G06F16/24554—Unary operations; Data partitioning operations
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention discloses a query method, a query device and a query device for user ranking and a storage medium. The method comprises the following steps: according to the scores of the inquiry users, inquiring each key value pair in the key value pair list step by step from top to bottom, wherein the key value pairs in the key value pair list are associated with nodes in a set tree structure; the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node; in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score; and when the query is finished, determining the user ranking of the query user according to the accumulation result. According to the technical scheme of the embodiment of the invention, the specific ranking of the user can be acquired in real time under large-scale data volume, and the data storage space is saved.
Description
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a user ranking query method, device, equipment and storage medium.
Background
Currently, displaying a ranking list is a common requirement of various applications, and in addition to a user list showing the TOPN in the ranking list, a specific ranking of a current user needs to be displayed.
In the prior art, common databases or storage engines such as MySQL generally use memory sorting, and the user ranking cannot be acquired well and quickly under large-scale data volume. Moreover, if too many applications of the list exceed the memory limit, the ranking acquisition speed is obviously reduced, and the system restart becomes a burden when data is required to be downloaded.
Disclosure of Invention
The embodiment of the invention provides a query method, a query device, equipment and a storage medium for user ranking, which can be used for acquiring the user ranking in real time under large-scale data volume and saving data storage space.
In a first aspect, an embodiment of the present invention provides a user ranking query method, including:
according to the scores of the inquiry users, inquiring each key value pair in the key value pair list step by step from top to bottom, wherein the key value pairs in the key value pair list are associated with nodes in a set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score;
and when the query is finished, determining the user ranking of the query user according to the accumulation result.
Optionally, the step-by-step accumulation of the number of users greater than the score according to the sub-score interval in each key value pair hit by the score includes:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a first sub-score interval of which the score hits in the key values of the target key-value pair, and determining all second sub-score intervals which are larger than the first sub-score interval;
accumulating the number of users corresponding to each second sub-score interval and a set accumulated value, wherein the accumulated value has a set initial value;
and in the key-value pair list, after the key-value pair with the key name matched with the first sub-score interval is obtained as a new target key-value pair, returning to execute the operation of obtaining the first sub-score interval with the score hit in the key-values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
Optionally, before querying each key-value pair in the key-value pair list step by step from top to bottom according to the score of the querying user, the method further includes:
acquiring a target user identifier of a query user;
and acquiring a score corresponding to the target user identifier as the score of the query user according to the mapping relation between the user identifier and the score.
Optionally, the method further includes:
responding to a score adjustment request matched with the key value pair list, and acquiring at least one score to be adjusted matched with the score adjustment request;
and according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted.
Optionally, the score adjustment request includes a newly added score request, and a score to be adjusted, which is matched with the newly added score request, is a newly added score;
according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a first target sub-score interval hit by the newly added score in the key value of the target key value pair, and adding one to the number of users corresponding to the first target sub-score interval;
and after key value pairs with key names matched with the first target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning and executing the operation of determining the first target sub-score intervals hit by the newly-added scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
Optionally, the score adjustment request includes a deletion score request, and the score to be adjusted, which is matched with the deletion score request, is a deletion score;
according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a second target sub-score interval of which the deletion score hits in the key values of the target key value pairs, and subtracting one from the number of users corresponding to the second target sub-score interval;
and after key value pairs with key names matched with the second target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of determining the second target sub-score intervals with the deleted scores hit in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
Optionally, the score adjustment request includes a score adjustment request, and the scores to be adjusted, which are matched with the score adjustment request, are scores before adjustment and scores after adjustment;
according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a third target sub-score interval of which the score hits in the key values of the target key value pairs before adjustment, and subtracting one from the number of users corresponding to the third target sub-score interval;
in the key-value pair list, after the key-value pair with the key name matched with the third target sub-score interval is obtained as a new target key-value pair, the operation of determining the third target sub-score interval with the score hit in the key-values of the target key-value pair before adjustment is returned until the key-value pair corresponding to the leaf node is processed;
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a fourth target sub-score interval of which the adjusted score hits in the key values of the target key value pairs, and adding one to the number of users corresponding to the fourth target sub-score interval;
and in the key-value pair list, after the key-value pair with the key name matched with the fourth target sub-score interval is obtained as a new target key-value pair, returning to execute the operation of determining the fourth target sub-score interval with the adjusted score hit in the key values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
Optionally, the tree structure is a 16-order balanced multi-way tree;
and associating each key value pair with the corresponding tree node according to the sequence of the designated score intervals in the key value pairs from small to large and the sequence of the tree structure from the left child node to the right child node.
Optionally, the list of key-value pairs is stored in RocksDB.
In a second aspect, an embodiment of the present invention further provides an apparatus for querying a user rank, including:
the query module is used for querying each key value pair in the key value pair list step by step from top to bottom according to the score of the query user, and the key value pairs in the key value pair list are associated with the nodes in the set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
the accumulation module is used for accumulating the number of users larger than the score step by step according to the sub-score intervals of each key value pair hit by the score in the inquiry process;
and the ranking determining module is used for determining the user ranking of the query user according to the accumulation result when the query is finished.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
one or more processors;
a storage device for storing one or more programs,
when executed by one or more processors, cause the one or more processors to implement the user-ranked query method provided by any of the embodiments of the invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the user-ranked query method provided in any embodiment of the present invention.
In the embodiment of the invention, according to the score of an inquiry user, each key value pair in a key value pair list is inquired step by step from top to bottom, and the key value pairs in the key value pair list are associated with nodes in a set tree structure; the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node; in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score; when the query is finished, determining the user rank of the query user according to the accumulated result, solving the problem that the user rank cannot be quickly obtained under the condition of large-scale data volume in the prior art, saving the data storage space by setting the key value pair corresponding to the score interval, and obtaining the specific rank of the user in real time under the condition of large-scale data volume.
Drawings
FIG. 1a is a flowchart of a user-ranked query method according to a first embodiment of the present invention;
FIG. 1b is a schematic diagram of a tree structure according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a user-ranked query method according to a second embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a user ranking query device in a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device in a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1a is a flowchart of a user ranking query method in a first embodiment of the present invention, which is applicable to a case where a user ranking is obtained in real time in a large amount of data, and the method may be performed by a user ranking query apparatus, which may be implemented by hardware and/or software, and may be generally integrated in an electronic device, such as a server, that provides a user ranking query service. As shown in fig. 1a, the method comprises:
and step 110, inquiring each key value pair in the key value pair list step by step from top to bottom according to the scores of the inquired users, wherein the key value pairs in the key value pair list are associated with the nodes in the set tree structure.
The key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; and the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node.
In this embodiment, the query user refers to a user who is to query the rank in an application program, and the key-value pair list is used to query the rank corresponding to any score. The key value pair list comprises a plurality of key value pairs, the key name of each key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval. Each key value pair is associated with one node in the set tree structure, the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node, the designated score interval in the key value pair corresponding to the root node is the largest, and the scores of all users fall into the designated score interval corresponding to the root node.
For example, assuming that the designated score interval is [0,5], the sub-score interval under the designated score interval includes [0,2], [3,4] and [5,5], and the number of users included in the sub-score interval [0,2] is 2, the number of users included in the sub-score interval [3,4] is 4, and the number of users included in the sub-score interval [5,5] is 0, the key name in the corresponding key-value pair is [0,5], and the key value is [2,4,0 ].
In this embodiment, after determining the score of the query user, each key-value pair in the key-value pair list may be queried from top to bottom step by step according to the score of the query user until a key-value pair corresponding to a leaf node is found. In the embodiment, a new data structure is adopted to represent the key value pairs, that is, the key name in the key value pair is a designated score interval, the key value is the number of users respectively contained in each sub-score interval under the designated score interval, and a tree structure relationship exists between each key value pair, so that the key value pair corresponding to the leaf node can be found by reducing the score interval for a few times. That is to say, the present embodiment can improve the efficiency of obtaining the ranking corresponding to the score by performing the segmentation query on the score.
Optionally, before querying each key-value pair in the key-value pair list step by step from top to bottom according to the score of the querying user, the method may further include: acquiring a target user identifier of a query user; and acquiring a score corresponding to the target user identifier as the score of the query user according to the mapping relation between the user identifier and the score.
In this embodiment, the user identifier may be information such as a registered account, a contact address, or a nickname of the user in the current application program, and is used to uniquely identify the user. And responding to a ranking query request of a query user, acquiring a target user identifier of the query user, querying a mapping relation between the user identifier and the score according to the target user identifier, obtaining a score corresponding to the target user identifier, and taking the score as the score of the query user. The mapping relationship between the user mark and the score can be stored through a key-value pair, for example, the key name is user a, and the corresponding key value is score B.
And step 120, in the query process, accumulating the number of users larger than the score step by step according to the sub-score intervals of each key value pair hit by the score.
In this embodiment, since the number of users included in each sub-score interval under the designated score interval is stored in the key value of each key value pair, in the process of querying each key value pair in the key value pair list from top to bottom step by step according to the score of the querying user, the number of users included in other sub-score intervals higher than the hit sub-score interval can be found and accumulated in the key value according to the sub-score interval in each key value pair hit by the score, so as to obtain the user rank corresponding to the score.
Optionally, the step-by-step accumulation of the number of users greater than the score according to the sub-score interval of each key value pair hit by the score may include: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a first sub-score interval of which the score hits in the key values of the target key-value pair, and determining all second sub-score intervals which are larger than the first sub-score interval; accumulating the number of users corresponding to each second sub-score interval and a set accumulated value, wherein the accumulated value has a set initial value; and in the key-value pair list, after the key-value pair with the key name matched with the first sub-score interval is obtained as a new target key-value pair, returning to execute the operation of obtaining the first sub-score interval with the score hit in the key-values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
In this embodiment, since the layer-by-layer reduction from the large-score interval to the small-score interval is realized by querying each key value pair in the key value pair list step by step from top to bottom, and the position of the score is found, when the query is started, the key value pair corresponding to the root node of the tree structure is obtained in the key value pair list as the target key value pair. Then, according to a predetermined sub-score interval calculation mode, determining each sub-score interval under the designated score interval of the target key-value pair, determining a first sub-score interval with the score hit in the key value of the target key-value pair, and determining all second sub-score intervals larger than the first sub-score interval. Since the user ranking corresponding to the score falling in the second sub-score interval is necessarily before the inquiring user, the number of users respectively corresponding to each second sub-score interval is accumulated with the set accumulated value, so as to record the total number of users with the score higher than that of the inquiring user through the accumulated value. The set initial value of the accumulation value is an initial value of the ranking, for example, if the ranking starts from 0, the set initial value of the accumulation value is 0, and if the ranking starts from 1, the set initial value of the accumulation value is 1. And judging whether the first sub-score interval only contains one score, if so, judging that the first sub-score interval is an appointed score interval in the key value pair corresponding to the leaf node, otherwise, after acquiring the key value pair with the key name matched with the first sub-score interval in the key value pair list as a new target key value pair, returning to execute the operation of acquiring the first sub-score interval with the score hit in the key value of the target key value pair, and continuously searching the sub-score interval matched with the score in each sub-score interval of the first sub-score interval until the key value pair corresponding to the leaf node is processed.
In this embodiment, the designated score intervals in the key-value pairs corresponding to the parent node are equally divided to obtain the designated score intervals in the key-value pairs corresponding to the child nodes, for example, the designated score interval corresponding to the parent node is [0,9], and the designated score intervals corresponding to 5 child nodes of the parent node are [0,1], [2,3], [4,5], [6,7], [8,9], respectively. If the designated score intervals cannot be evenly divided, the redundant data are uniformly distributed to each child node in sequence, for example, the designated score interval corresponding to the parent node is [0,9], and the designated score intervals corresponding to the 4 child nodes of the parent node are [0,2], [3,5], [6,7], [8,9], respectively.
In the present embodiment, when the score is a value of the double type, the division of the section is difficult to determine, and considering that when data of the uint64 type is used as the score, it is sufficient for the business to use the integer in the application of the leader board, so the division of the section can be performed by multiplying the score of the double type by a large integer of a fixed size, converting the score from the double type to the integer.
Illustratively, as shown in FIG. 1b, the list of key-value pairs includes key-value pairs: a key name [0,9] -key value [5,3,2], a key name [0,3] -key value [2,2,1], a key name [4,6] -key value [3,0,0], a key name [7,9] -key value [2,0,0], a key name [0,1] -key value [1,1,0], and assuming that the score of the query user is 3 and the initial value of the accumulated value is 1, the process of obtaining the user rank corresponding to 3 is as follows: using the key name [0,9] -key value [5,3,2] as a target key value pair, equally dividing the interval [0,9] to calculate sub-intervals [0,3], [4,6] and [7,9], determining that the sub-interval [0,3] of 3 hits is a first sub-fraction interval, the sub-intervals [4,6] and [7,9] are second sub-fraction intervals, and accumulating an accumulated value with the user numbers 3 and 2 contained in the sub-intervals [4,6] and [7,9 ]. At this time, the sub-interval [0,3] contains 4 scores from 0 to 3, and the interval range needs to be further reduced, so the key name [0,3] -key value [2,2,1] is taken as a new target key value pair, the above process is repeated, the first sub-score interval [3,3] containing only one score is determined, at this time, the second sub-interval is not determined, the accumulated value does not need to be accumulated, and at this time, the user rank corresponding to the score 3 can be determined.
In this embodiment, the number of users included in the designated sub-score interval corresponding to each child node under the same parent node is stored in the key value of the key value pair corresponding to the parent node, so that when the user rank is calculated, a final result can be obtained only by reading the currently searched parent node, and reading of the child nodes of the parent node is reduced. Meanwhile, in order to reduce data redundancy, the total number of users contained in the designated score interval corresponding to the parent node and the designated sub-score interval corresponding to each sub-node of the parent node are not stored in the key value corresponding to the parent node. The total number of users contained in the designated score interval corresponding to the parent node can be obtained by accumulating the number of users contained in each sub-score interval stored in the key value corresponding to the parent node, and the designated sub-score interval corresponding to each sub-node can be calculated by the key value corresponding to the parent node.
And step 130, when the query is finished, determining the user rank of the query user according to the accumulation result.
In this embodiment, when the queried first sub-score interval only includes one score, after the number of users respectively corresponding to each second sub-score interval and the set accumulated value are accumulated, the current accumulated value is the user rank of the querying user. For example, in the example of step 120, when the score of the querying user is 3, the user is ranked as 6.
In this embodiment, since the key name of the node corresponds to a score interval instead of a score, storing the information of each child node in the key value corresponding to the parent node does not introduce a nesting problem. In addition, the same score corresponds to the same leaf node and the same key value pair, so that the data storage space can be saved, and the user ranking obtained by the same score is the same and is more practical.
In the embodiment of the invention, according to the score of an inquiry user, each key value pair in a key value pair list is inquired step by step from top to bottom, and the key value pairs in the key value pair list are associated with nodes in a set tree structure; the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node; in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score; when the query is finished, determining the user rank of the query user according to the accumulated result, solving the problem that the user rank cannot be quickly obtained under the condition of large-scale data volume in the prior art, saving the data storage space by setting the key value pair corresponding to the score interval, and obtaining the specific rank of the user in real time under the condition of large-scale data volume.
Example two
Fig. 2 is a flowchart of a user ranking query method in the second embodiment of the present invention, which is further detailed based on the above embodiments in this embodiment, and provides descriptions of a score adjustment request and a score to be adjusted, and specific steps of adjusting, according to the score to be adjusted, the number of users in a sub-score interval in each key value pair in a key value pair list under different descriptions. A user ranking query method provided in a second embodiment of the present application is described below with reference to fig. 2, including the following steps:
And step 220, inquiring each key value pair in the key value pair list step by step from top to bottom according to the scores of the inquired users, wherein the key value pairs in the key value pair list are associated with the nodes in the set tree structure.
Optionally, the list of key-value pairs is stored in RocksDB.
In this embodiment, the rocksbb is a key-value pair database that uses a Log-structured merge-Tree (LSM Tree) storage engine based on a Log structure, and has a perfect persistence mechanism while ensuring performance and security. The key-value pairs in the RocksDB are stored in key-name order, so that the scope query can be well supported. The principle of the LSM tree is to split a big tree into N small trees, and first write data into a memory, construct an ordered small tree in the memory, and as the small trees become larger, the small trees in the memory will be output to a disk. The trees in the disk can be regularly merged to generate a big tree so as to optimize the reading performance.
In the embodiment, the key value pair list is stored in the RocksDB, and the storage characteristics of the RocksDB or the LSM tree are utilized, so that the function of acquiring the user ranking in real time is realized without being limited by the size of a memory, and the data can be permanently stored in a disk.
Optionally, the tree structure is a 16-order balanced multi-way tree; and associating each key value pair with the corresponding tree node according to the sequence of the designated score intervals in the key value pairs from small to large and the sequence of the tree structure from the left child node to the right child node.
In this embodiment, considering that the reading performance of the RocksDB is affected by the number of layers of the tree corresponding to the key value pair list, and the performance is low when the number of layers is too large, a structure of a B tree is constructed on the RocksDB and optimized. The B-tree is a multi-path balanced search tree, and when describing a B-tree, the order of the B-tree needs to be specified, and the order represents how many child nodes a node has at most. Considering the actually used score space and the finally generated hierarchy, in order to make the number of the tree layers corresponding to the key-value pair list not larger than 10, the tree is set to be a balanced multi-branch tree of 16 orders, so that the tree corresponding to the key-value pair list in the space of the uint32_ t has only 8 layers, and each time the user rank is calculated, only 8 times of search operations of rocksDB are needed, and the query rate per second for searching the user rank can be greatly improved.
In this embodiment, since the key value pairs in the RocksDB are stored according to the key name sequence, each key value pair may be associated with a corresponding tree node according to the sequence from small to large of the designated score interval in the key value pair and the sequence from the left child node to the right child node of the tree structure, so that the left child node is a low-partition interval and the right child node is a high-partition interval, and therefore, in the key value, it is easy to determine all the users whose scores are greater than a certain sub-score interval, even if the user ranking is calculated.
And step 230, in the query process, accumulating the number of users larger than the score step by step according to the sub-score intervals of each key value pair hit by the score.
And 240, determining the user rank of the query user according to the accumulation result when the query is finished.
In the embodiment of the invention, according to the score of an inquiry user, each key value pair in a key value pair list is inquired step by step from top to bottom, and the key value pairs in the key value pair list are associated with nodes in a set tree structure; the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node; in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score; when the query is finished, determining the user rank of the query user according to the accumulated result, solving the problem that the user rank cannot be quickly obtained under the condition of large-scale data volume in the prior art, saving the data storage space by setting the key value pair corresponding to the score interval, and obtaining the specific rank of the user in real time under the condition of large-scale data volume.
It should be noted that, on the basis of the above embodiment, the method may further include: responding to a score adjustment request matched with the key value pair list, and acquiring at least one score to be adjusted matched with the score adjustment request; and according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted.
In this embodiment, when the score of the user changes, a score adjustment request matched with the key-value pair list is generated, so as to perform corresponding update adjustment on the key-value pairs in the key-value pair list according to the score change condition of the user. When the score changes, the score can be realized by a Delete interface and an Insert interface theoretically, but actually, the score change is generally small, and the purpose can be achieved by only updating a few score intervals or even not updating the score intervals. In general, the number of score intervals to be updated is related to the score variation det, and the two have a log (det) relationship.
Optionally, the score adjustment request includes a new score request, and the score to be adjusted, which is matched with the new score request, is a new score.
In this embodiment, the score adjustment request may be a new score addition request, and the score to be adjusted, which is matched with the new score addition request, may be a new score, for example, when a new user is added to the application program and a score of the new user is generated, the score of the new user needs to be added to the key value pair list.
Optionally, according to at least one score to be adjusted, querying each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users in a sub-score interval in each key value pair hit by the score to be adjusted, may include: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a first target sub-score interval hit by the newly added score in the key value of the target key value pair, and adding one to the number of users corresponding to the first target sub-score interval; and after key value pairs with key names matched with the first target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning and executing the operation of determining the first target sub-score intervals hit by the newly-added scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
In this embodiment, when each key value pair in the key value pair list is adjusted according to a newly added score, a key value pair corresponding to a root node, that is, a key value pair corresponding to a maximum specified score interval is first obtained in the key value pair list as a target key value pair, the newly added score is inevitably within the specified score interval of the target key value pair, and if not, an error is considered. And then determining each sub-score interval under the appointed score interval of the target key value pair, determining a first target sub-score interval hit by a newly added score in the key values of the target key value pair, adding one to the number of users corresponding to the first target sub-score interval, judging whether the first target sub-score interval only contains one score, if so, determining that the key value pair in the key value pair list is adjusted, otherwise, obtaining the key value pair with the key name matched with the first target sub-score interval in the key value pair list as a new target key value pair, returning to execute the operation of determining the first target sub-score interval hit by the newly added score in the key values of the target key value pair, and continuing to search the sub-score interval matched with the newly added score in each sub-score interval of the first target sub-score interval until processing to the key value pair corresponding to the leaf node.
For example, assuming that the key-value pair list corresponds to the tree structure in fig. 1b and the new score is equal to 3, the process of adjusting each key-value pair in the key-value pair list according to the new score is as follows: and (3) taking the key name [0,9] -key value [5,3,2] as a target key value pair, determining that the subinterval [0,3] hit by the score 3 is a first target subinterval, adding 1 to the number of users contained in the subinterval [0,3] in the key value in the target key value pair, taking the key name [0,3] -key value [2,2,1] as a new target key value pair, repeating the process, determining the first target subinterval [3,3] only containing one score, adding 1 to the number of users contained in the subinterval [3,3] in the key value pair, and finishing the adjustment of the key value pair in the key value pair list.
Optionally, the score adjustment request includes a deletion score request, and the score to be adjusted, which is matched with the deletion score request, is a deletion score.
In this embodiment, the score adjustment request may be a delete score request, and the score to be adjusted that is matched with the delete score request may be a delete score, for example, when a user logs out an application account and is no longer used, the score of the user needs to be deleted from the key-value pair list.
Optionally, according to at least one score to be adjusted, querying each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users in a sub-score interval in each key value pair hit by the score to be adjusted, may include: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a second target sub-score interval of which the deletion score hits in the key values of the target key value pairs, and subtracting one from the number of users corresponding to the second target sub-score interval; and after key value pairs with key names matched with the second target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of determining the second target sub-score intervals with the deleted scores hit in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
In this embodiment, when each key value pair in the key value pair list is adjusted according to the deletion score, the key value pair corresponding to the largest specified score interval is first obtained as the target key value pair in the key value pair list, and the deletion score is inevitably within the specified score interval of the target key value pair, and if not, an error is considered. And then determining each sub-score interval under the appointed score interval of the target key value pair, determining a second target sub-score interval in which the deletion score hits in the key values of the target key value pair, reducing the number of users corresponding to the second target sub-score interval by one, judging whether the second target sub-score interval only contains one score, if so, determining that the key value pair in the key value pair list is adjusted, otherwise, obtaining the key value pair with the key name matched with the second target sub-score interval in the key value pair list as a new target key value pair, returning to execute the operation of determining the second target sub-score interval in which the deletion score hits in the key values of the target key value pair, and continuing to search the sub-score interval matched with the deletion score in each sub-score interval of the second target sub-score interval until processing to the key value pair corresponding to the leaf node.
And if the number of users corresponding to the second target sub-score interval is reduced by one and then the number of users is changed to-1, determining that no deletion score exists in the key value pair list, and returning an error. If all the data in the key value of the target key value pair are 0 after the number of the users corresponding to the second target sub-score interval is reduced by one, the parent node is considered to have no child node, and the target key value pair can be deleted.
For example, assuming that the list of key-value pairs corresponds to the tree structure of fig. 1b and the deletion score is equal to 3, the process of adjusting each key-value pair in the list of key-value pairs according to the deletion score is as follows: and (3) taking the key name [0,9] -key value [5,3,2] as a target key value pair, determining that the subinterval [0,3] hit by the score 3 is a second target subinterval, subtracting 1 from the number of users contained in the subinterval [0,3] in the key value in the target key value pair, taking the key name [0,3] -key value [2,2,1] as a new target key value pair, repeating the process, determining a second target subinterval [3,3] only containing one score, subtracting 1 from the number of users contained in the subinterval [3,3] in the key value pair, and finishing the adjustment of the key value pair in the key value pair list.
Optionally, the score adjustment request includes a score adjustment request, and the score to be adjusted, which is matched with the score adjustment request, is a pre-adjustment score and a post-adjustment score.
In this embodiment, the score adjustment request may be a score adjustment request, and the scores to be adjusted that are matched with the score adjustment request may be pre-adjustment scores and post-adjustment scores, for example, when the score of a certain user rises, the score of the user needs to be replaced from the pre-adjustment score to the post-adjustment score in the key-value pair list.
Optionally, according to at least one score to be adjusted, querying each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users in a sub-score interval in each key value pair hit by the score to be adjusted, may include: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a third target sub-score interval of which the score hits in the key values of the target key value pairs before adjustment, and subtracting one from the number of users corresponding to the third target sub-score interval; in the key-value pair list, after the key-value pair with the key name matched with the third target sub-score interval is obtained as a new target key-value pair, the operation of determining the third target sub-score interval with the score hit in the key-values of the target key-value pair before adjustment is returned until the key-value pair corresponding to the leaf node is processed;
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a fourth target sub-score interval of which the adjusted score hits in the key values of the target key value pairs, and adding one to the number of users corresponding to the fourth target sub-score interval; and in the key-value pair list, after the key-value pair with the key name matched with the fourth target sub-score interval is obtained as a new target key-value pair, returning to execute the operation of determining the fourth target sub-score interval with the adjusted score hit in the key values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
In this embodiment, the process of adjusting each key value pair in the key value pair list according to the pre-adjustment score and the post-adjustment score is actually a process of deleting the pre-adjustment score from the key value pair list and adding the post-adjustment score to the key value pair list. The process of deleting the score before adjustment from the key-value pair list is the same as the process of adjusting each key-value pair in the key-value pair list according to the deletion score, and the process of adding the score after adjustment to the key-value pair list is the same as the process of adjusting each key-value pair in the key-value pair list according to the newly added score, and the detailed description is omitted here.
In this embodiment, the process of adjusting each key value pair in the key value pair list according to the pre-adjustment score and the post-adjustment score may also be as follows: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a third target sub-score interval of which the score hits in the key values of the target key value pairs before adjustment and a fourth target sub-score interval of which the score hits in the key values of the target key value pairs after adjustment; and if the third target sub-score interval is equal to the fourth target sub-score interval, the number of users in the sub-score interval is unchanged, after a key value pair with a key name matched with the third target sub-score interval is obtained as a new target key value pair, returning to execute the operation of determining the third target sub-score interval with the score hit in the key values of the target key value pair before adjustment until the third target sub-score interval is not equal to the fourth target sub-score interval, at the moment, subtracting one from the number of users corresponding to the third target sub-score interval, and adding one to the number of users corresponding to the fourth target sub-score interval.
Then, obtaining a key value pair matched with the key name and a third target sub-score interval as a new target key value pair, determining a second target sub-score interval hit by the score before adjustment in the key values of the target key value pair, and subtracting one from the number of users corresponding to the second target sub-score interval; and in the key-value pair list, after the key-value pair with the key name matched with the second target sub-score interval is obtained as a new target key-value pair, returning to execute the operation of determining the second target sub-score interval with the score before adjustment hit in the key values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
Then, obtaining a key value pair matched with the key name and the fourth target sub-score interval as a new target key value pair, determining a first target sub-score interval with the adjusted score hitting in the key values of the target key value pair, and adding one to the number of users corresponding to the first target sub-score interval; and in the key-value pair list, after the key-value pair with the key name matched with the first target sub-score interval is obtained as a new target key-value pair, returning to execute the operation of determining the first target sub-score interval with the adjusted score hit in the key values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
For example, assuming that the list of key-value pairs corresponds to the tree structure of fig. 1b, the pre-adjustment score is equal to 3, and the post-adjustment score is equal to 6, the adjustment of each key-value pair in the list of key-value pairs according to the pre-adjustment score and the post-adjustment score is as follows: and taking the key name [0,9] -key value [5,3,2] as a target key value pair, determining that the subinterval [0,3] hit by the score 3 is a third target subinterval, determining that the subinterval [4,6] hit by the score 6 is a fourth target subinterval, and the third target subinterval is not equal to the fourth target subinterval, so that the number of users included in the subinterval [0,3] in the key value of the target key value pair is reduced by 1, and the number of users included in the subinterval [4,6] in the key value pair is increased by 1. Then, the key name [0,3] -key value [2,2,1] is used as a new target key value pair, and the sub-interval [3,3] with the score of 3 hit only contains the score of 3, so that the number of users contained in the sub-interval [3,3] in the key value in the target key value pair is reduced by 1. Then, the key name [4,6] -key value [3,0,0] is used as a new target key value pair, and it is determined that the subinterval [6,6] with the score of 6 hit only contains the score of 6, so that the number of users contained in the subinterval [6,6] in the key value in the target key value pair is added with 1, and the adjustment of each key value pair in the key value pair list is completed.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a user ranking query device in a third embodiment of the present invention, which is applicable to a case where a user ranking is obtained in real time in a large amount of data, and the device may be implemented by hardware and/or software, and may be generally integrated in an electronic device, such as a server, that provides a user ranking query service. As shown in fig. 3, the user ranking query device includes:
the query module 310 is configured to query, from top to bottom, each key-value pair in the key-value pair list step by step according to the score of the query user, where the key-value pairs in the key-value pair list are associated with nodes in the set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
the accumulation module 320 is used for accumulating the number of users larger than the score step by step according to the sub-score intervals of each key value pair hit by the score in the inquiry process;
and the ranking determining module 330 is configured to determine, when the query is finished, the user ranking of the query user according to the accumulated result.
In the embodiment of the invention, according to the score of an inquiry user, each key value pair in a key value pair list is inquired step by step from top to bottom, and the key value pairs in the key value pair list are associated with nodes in a set tree structure; the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node; in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score; when the query is finished, determining the user rank of the query user according to the accumulated result, solving the problem that the user rank cannot be quickly obtained under the condition of large-scale data volume in the prior art, saving the data storage space by setting the key value pair corresponding to the score interval, and obtaining the specific rank of the user in real time under the condition of large-scale data volume.
Optionally, the accumulation module 320 is specifically configured to: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a first sub-score interval of which the score hits in the key values of the target key-value pair, and determining all second sub-score intervals which are larger than the first sub-score interval; accumulating the number of users corresponding to each second sub-score interval and a set accumulated value, wherein the accumulated value has a set initial value; and in the key-value pair list, after the key-value pair with the key name matched with the first sub-score interval is obtained as a new target key-value pair, returning to execute the operation of obtaining the first sub-score interval with the score hit in the key-values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
Optionally, the method further includes: the score acquisition module is used for acquiring a target user identifier of the inquiry user before inquiring each key value pair in the key value pair list step by step from top to bottom according to the score of the inquiry user; and acquiring a score corresponding to the target user identifier as the score of the query user according to the mapping relation between the user identifier and the score.
Optionally, the method further includes: the adjusting module is used for responding to the score adjusting request matched with the key value pair list and acquiring at least one score to be adjusted matched with the score adjusting request; and according to at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted.
Optionally, the score adjustment request includes a newly added score request, and a score to be adjusted, which is matched with the newly added score request, is a newly added score;
the adjustment module comprises a newly added unit and is used for: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a first target sub-score interval hit by the newly added score in the key value of the target key value pair, and adding one to the number of users corresponding to the first target sub-score interval; and after key value pairs with key names matched with the first target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning and executing the operation of determining the first target sub-score intervals hit by the newly-added scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
Optionally, the score adjustment request includes a deletion score request, and the score to be adjusted, which is matched with the deletion score request, is a deletion score;
an adjustment module comprising a deletion unit for: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a second target sub-score interval of which the deletion score hits in the key values of the target key value pairs, and subtracting one from the number of users corresponding to the second target sub-score interval; and after key value pairs with key names matched with the second target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of determining the second target sub-score intervals with the deleted scores hit in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
Optionally, the score adjustment request includes a score adjustment request, and the scores to be adjusted, which are matched with the score adjustment request, are scores before adjustment and scores after adjustment;
an adjustment module comprising a score adjustment unit to: acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a third target sub-score interval of which the score hits in the key values of the target key value pairs before adjustment, and subtracting one from the number of users corresponding to the third target sub-score interval; in the key-value pair list, after the key-value pair with the key name matched with the third target sub-score interval is obtained as a new target key-value pair, the operation of determining the third target sub-score interval with the score hit in the key-values of the target key-value pair before adjustment is returned until the key-value pair corresponding to the leaf node is processed;
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair; determining a fourth target sub-score interval of which the adjusted score hits in the key values of the target key value pairs, and adding one to the number of users corresponding to the fourth target sub-score interval; and in the key-value pair list, after the key-value pair with the key name matched with the fourth target sub-score interval is obtained as a new target key-value pair, returning to execute the operation of determining the fourth target sub-score interval with the adjusted score hit in the key values of the target key-value pair until the key-value pair corresponding to the leaf node is processed.
Optionally, the tree structure is a 16-order balanced multi-way tree; and associating each key value pair with the corresponding tree node according to the sequence of the designated score intervals in the key value pairs from small to large and the sequence of the tree structure from the left child node to the right child node.
Optionally, the list of key-value pairs is stored in RocksDB.
The user ranking query device provided by the embodiment of the invention can execute the user ranking query method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention. Fig. 4 illustrates a block diagram of an exemplary device 12 suitable for use in implementing embodiments of the present invention. The device 12 shown in fig. 4 is only an example and should not bring any limitation to the function and scope of use of the embodiments of the present invention.
As shown in FIG. 4, device 12 is in the form of a general purpose computing device. The components of device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. Device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, and commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
The processing unit 16 executes various functional applications and data processing, such as implementing a user-ranked query method provided by embodiments of the present invention, by executing programs stored in the system memory 28.
Namely: a query method for realizing user ranking comprises the following steps: according to the scores of the inquiry users, inquiring each key value pair in the key value pair list step by step from top to bottom, wherein the key value pairs in the key value pair list are associated with nodes in a set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score;
and when the query is finished, determining the user ranking of the query user according to the accumulation result.
EXAMPLE five
The fifth embodiment of the present invention further discloses a computer storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a user ranking query method, including:
according to the scores of the inquiry users, inquiring each key value pair in the key value pair list step by step from top to bottom, wherein the key value pairs in the key value pair list are associated with nodes in a set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
in the query process, the number of users larger than the score is accumulated step by step according to the sub-score intervals of each key value pair hit by the score;
and when the query is finished, determining the user ranking of the query user according to the accumulation result.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims (12)
1. A user ranking query method is characterized by comprising the following steps:
according to the scores of the inquiry users, inquiring each key value pair in a key value pair list step by step from top to bottom, wherein the key value pairs in the key value pair list are associated with nodes in a set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
in the query process, according to sub-score intervals of all key value pairs hit by the scores, accumulating the number of users larger than the scores step by step;
and when the query is finished, determining the user ranking of the query user according to the accumulation result.
2. The method of claim 1, wherein accumulating the number of users larger than the score step by step according to sub-score intervals in each key value pair hit by the score during the query process comprises:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a first sub-score interval of the score hit in the key value of the target key-value pair, and determining all second sub-score intervals larger than the first sub-score interval;
accumulating the number of users corresponding to each second sub-score interval and a set accumulated value, wherein the accumulated value has a set initial value;
and after key value pairs with key names matched with the first sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of obtaining the first sub-score intervals hit by the scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
3. The method of claim 1, further comprising, prior to querying each key-value pair in the list of key-value pairs top-down in a stepwise manner based on a score of a querying user:
acquiring a target user identifier of a query user;
and acquiring a score corresponding to the target user identifier as the score of the query user according to the mapping relation between the user identifier and the score.
4. The method of claim 1, further comprising:
responding to a score adjustment request matched with a key value pair list, and acquiring at least one score to be adjusted matched with the score adjustment request;
and inquiring each key value pair in the key value pair list step by step from top to bottom according to the at least one score to be adjusted, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted.
5. The method according to claim 4, wherein the score adjustment request comprises a new score request, and the score to be adjusted matched with the new score request is a new score;
according to the at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a first target sub-score interval hit by the newly added score in a key value of a target key value pair, and adding one to the number of users corresponding to the first target sub-score interval;
and after key value pairs with key names matched with the first target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning and executing the operation of determining the first target sub-score intervals hit by the newly added scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
6. The method of claim 4, wherein the score adjustment request comprises a delete score request, and wherein the score to be adjusted that matches the delete score request is a delete score;
according to the at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a second target sub-score interval hit by the deletion score in the key value of the target key value pair, and subtracting one from the number of users corresponding to the second target sub-score interval;
and after key value pairs with key names matched with the second target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of determining the second target sub-score intervals hit by the deletion scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
7. The method of claim 4, wherein the score adjustment request comprises an adjustment score request, and the scores to be adjusted that match the adjustment score request are pre-adjustment scores and post-adjustment scores;
according to the at least one score to be adjusted, inquiring each key value pair in the key value pair list step by step from top to bottom, and adjusting the number of users of sub-score intervals in each key value pair hit by the score to be adjusted, wherein the method comprises the following steps:
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a third target sub-score interval of which the score hits in the key values of the target key value pairs before adjustment, and subtracting one from the number of users corresponding to the third target sub-score interval;
after key value pairs with key names matched with the third target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, the operation of determining the third target sub-score intervals with scores hitting in the key values of the target key value pairs before adjustment is returned to be executed until the key value pairs corresponding to the leaf nodes are processed;
acquiring a key value pair corresponding to a root node of the tree structure in the key value pair list as a target key value pair;
determining a fourth target sub-score interval of which the adjusted score hits in the key values of the target key value pairs, and adding one to the number of users corresponding to the fourth target sub-score interval;
and after key value pairs with key names matched with the fourth target sub-score intervals are obtained in the key value pair list and serve as new target key value pairs, returning to execute the operation of determining the fourth target sub-score intervals hit by the adjusted scores in the key values of the target key value pairs until the key value pairs corresponding to the leaf nodes are processed.
8. The method according to any of claims 1-7, wherein the tree structure is a balanced multi-way tree of order 16;
and associating each key value pair with the corresponding tree node according to the sequence of the designated score intervals in the key value pairs from small to large and the sequence of the tree structure from the left child node to the right child node.
9. The method of any of claims 1-7, wherein the list of key-value pairs is stored in a RocksDB.
10. A user-ranked query device, comprising:
the query module is used for querying each key value pair in the key value pair list step by step from top to bottom according to the score of a query user, and the key value pairs in the key value pair list are associated with nodes in the set tree structure;
the key name of the key value pair is a designated score interval, and the key value is the number of users respectively contained in each sub-score interval under the designated score interval; the sum of the designated score intervals in the key value pairs corresponding to all the child nodes under the same father node is the designated score interval in the key value pair corresponding to the father node;
the accumulation module is used for accumulating the number of users larger than the score step by step according to the sub-score intervals of each key value pair hit by the score in the inquiry process;
and the ranking determining module is used for determining the user ranking of the query user according to the accumulation result when the query is finished.
11. An electronic device, characterized in that the electronic device comprises:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the user-ranked query method of any of claims 1-9.
12. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a user-ranked query method according to any one of claims 1 to 9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010469645.5A CN111666302A (en) | 2020-05-28 | 2020-05-28 | User ranking query method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010469645.5A CN111666302A (en) | 2020-05-28 | 2020-05-28 | User ranking query method, device, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111666302A true CN111666302A (en) | 2020-09-15 |
Family
ID=72384916
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010469645.5A Pending CN111666302A (en) | 2020-05-28 | 2020-05-28 | User ranking query method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111666302A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113568917A (en) * | 2021-08-13 | 2021-10-29 | 网易(杭州)网络有限公司 | Data ranking method and device, electronic equipment and storage medium |
CN115145954A (en) * | 2022-09-01 | 2022-10-04 | 北京奥星贝斯科技有限公司 | Data query method, data storage method and device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105512320A (en) * | 2015-12-18 | 2016-04-20 | 北京金山安全软件有限公司 | User ranking obtaining method and device and server |
CN110362758A (en) * | 2019-06-24 | 2019-10-22 | 北京奇艺世纪科技有限公司 | Record binary tree generation and account ranking acquisition methods, device, system and medium |
CN110377611A (en) * | 2019-07-12 | 2019-10-25 | 北京三快在线科技有限公司 | Integrate the method and device of ranking |
CN110833696A (en) * | 2019-11-06 | 2020-02-25 | 网易(杭州)网络有限公司 | Player ranking method and device, storage medium and electronic equipment |
-
2020
- 2020-05-28 CN CN202010469645.5A patent/CN111666302A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105512320A (en) * | 2015-12-18 | 2016-04-20 | 北京金山安全软件有限公司 | User ranking obtaining method and device and server |
CN110362758A (en) * | 2019-06-24 | 2019-10-22 | 北京奇艺世纪科技有限公司 | Record binary tree generation and account ranking acquisition methods, device, system and medium |
CN110377611A (en) * | 2019-07-12 | 2019-10-25 | 北京三快在线科技有限公司 | Integrate the method and device of ranking |
CN110833696A (en) * | 2019-11-06 | 2020-02-25 | 网易(杭州)网络有限公司 | Player ranking method and device, storage medium and electronic equipment |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113568917A (en) * | 2021-08-13 | 2021-10-29 | 网易(杭州)网络有限公司 | Data ranking method and device, electronic equipment and storage medium |
CN113568917B (en) * | 2021-08-13 | 2023-07-28 | 网易(杭州)网络有限公司 | Data ranking method and device, electronic equipment and storage medium |
CN115145954A (en) * | 2022-09-01 | 2022-10-04 | 北京奥星贝斯科技有限公司 | Data query method, data storage method and device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110321344B (en) | Information query method and device for associated data, computer equipment and storage medium | |
CN109766497B (en) | Ranking list generation method and device, storage medium and electronic equipment | |
US10055509B2 (en) | Constructing an in-memory representation of a graph | |
US20070198591A1 (en) | Partition by growth table space | |
US10678779B2 (en) | Generating sub-indexes from an index to compress the index | |
US20120072412A1 (en) | Evaluating execution plan changes after a wakeup threshold time | |
EP2788896B1 (en) | Fuzzy full text search | |
US9229960B2 (en) | Database management delete efficiency | |
CN110928882B (en) | Memory database indexing method and system based on improved red black tree | |
US10990573B2 (en) | Fast index creation system for cloud big data database | |
US20230315727A1 (en) | Cost-based query optimization for untyped fields in database systems | |
US20110179013A1 (en) | Search Log Online Analytic Processing | |
CN111666302A (en) | User ranking query method, device, equipment and storage medium | |
CN114840487A (en) | Metadata management method and device for distributed file system | |
CN108549666B (en) | Data table sorting method, device, equipment and storage medium | |
CN115809268B (en) | Adaptive query method and device based on fragment index | |
US20160004749A1 (en) | Search system and search method | |
US9092472B1 (en) | Data merge based on logical segregation | |
WO2013097065A1 (en) | Index data processing method and device | |
CN112000666B (en) | Database management system of facing array | |
CN114218277A (en) | Efficient query method and device for relational database | |
CN113742346A (en) | Asset big data platform architecture optimization method | |
CN113761102A (en) | Data processing method, device, server, system and storage medium | |
KR20220099745A (en) | A spatial decomposition-based tree indexing and query processing methods and apparatus for geospatial blockchain data retrieval | |
CN103891244B (en) | A kind of method and device carrying out data storage and search |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200915 |
|
RJ01 | Rejection of invention patent application after publication |