ID lookup methods, devices, electronic devices, and storage media
By using ordered character combinations and child node position sequences in a trie to perform character-by-character searches, the problem of large memory usage in ID queries in existing technologies is solved, enabling ID queries applicable to any character composition and expanding the applicable scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-03
- Publication Date
- 2026-04-07
AI Technical Summary
Existing technologies require loading all IDs into memory for querying a set of IDs, resulting in a large memory footprint and limited applicability, making it difficult to apply to different business scenarios.
After querying the first set of IDs corresponding to the target ID, if the target ID is not found, then obtain the ordered character combination and child node sequence. Use these to perform a character-by-character search using the trie indicating the second set of IDs corresponding to the target ID, reducing memory usage and making it suitable for ID queries composed of any characters.
When querying the second ID set, only the ordered character combination and child node position sequence need to be loaded, avoiding complex operations, reducing memory usage, and expanding the applicable scenarios.
Smart Images

Figure CN116431866B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data query technology, and in particular to an ID query method, apparatus, electronic device, and storage medium. Background Technology
[0002] In the field of data query technology, a single data object is sometimes associated with a large number of IDs, that is, an ID set. For example, in a game, the game rewards or related achievements received by a player object are bound to that player object as a set of IDs. When querying whether the set of IDs associated with this data object contains a certain ID, it is usually necessary to load all IDs in the set of IDs into memory and then query from memory to obtain the query result.
[0003] To reduce the memory footprint of ID lookups in memory, existing technologies typically record similar IDs using a combination of characters and bitmaps, thereby minimizing the memory usage of locally identical characters. However, this approach requires IDs to be integers, and the numerical differences between IDs in the set cannot exceed a certain limit. While this method can reduce the memory usage of ID lookups, its applicability is too narrow and difficult to apply to different business scenarios. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide an ID query method, apparatus, electronic device and storage medium to reduce the memory space occupied by ID query and expand the applicable scenarios of ID query.
[0005] In a first aspect, embodiments of the present invention provide an ID query method, the method comprising: responding to a query instruction for a target ID, querying the target ID through a first ID set corresponding to the target ID to obtain a first query result; if the first query result indicates that the first ID set does not contain the target ID, then obtaining an ordered character combination and a child node position sequence corresponding to the target ID, wherein the ordered character combination and the child node position sequence are used to indicate a trie of a second ID set corresponding to the target ID, the ordered character combination is used to indicate the breadth-first node traversal result of the trie, the child node position sequence is used to indicate the number of child nodes of each node in the trie, and the order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination; and performing a character-by-character search of the target ID through the ordered character combination and the child node position sequence to obtain a second query result, wherein the second query result is used to indicate whether the second ID set contains the target ID.
[0006] Secondly, embodiments of the present invention provide an ID query device, comprising: a response module, configured to, in response to a query instruction for a target ID, query the target ID through a first ID set corresponding to the target ID to obtain a first query result; an acquisition module, configured to, if the first query result indicates that the first ID set does not contain the target ID, acquire an ordered character combination and a child node position sequence corresponding to the target ID, wherein the ordered character combination and the child node position sequence are used to indicate a trie of a second ID set corresponding to the target ID, the ordered character combination is used to indicate the breadth-first node traversal result of the trie, the child node position sequence is used to indicate the number of child nodes of each node in the trie, and the order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination; and a search module, configured to, through the ordered character combination and the child node position sequence, search for each character of the target ID to obtain a second query result, wherein the second query result is used to indicate whether the second ID set contains the target ID.
[0007] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned ID query method.
[0008] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are invoked and executed by a processor, the computer-executable instructions cause the processor to implement the aforementioned ID query method.
[0009] The embodiments of the present invention bring the following beneficial effects:
[0010] The aforementioned ID query method, apparatus, electronic device, and storage medium, in response to a query instruction for a target ID, perform a query on the target ID through a first ID set corresponding to the target ID to obtain a first query result; if the first query result indicates that the first ID set does not contain the target ID, then obtain an ordered character combination and a child node position sequence corresponding to the target ID, wherein the ordered character combination and the child node position sequence are used to indicate a trie of a second ID set corresponding to the target ID, the ordered character combination is used to indicate the breadth-first node traversal result of the trie, and the child node position sequence is used to indicate the number of child nodes of each node in the trie, and the order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination; perform a character-by-character search on the target ID through the ordered character combination and the child node position sequence to obtain a second query result, wherein the second query result is used to indicate whether the second ID set contains the target ID. In this method, the query range of the target ID includes a first set of IDs and a second set of IDs. The second set of IDs is indicated by two simple characters generated by a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second set of IDs. Only these two simple characters need to be loaded into memory, and the target ID can be directly queried without complex operations such as decompression and deserialization. Since the trie does not restrict the node characters, this method is applicable to ID queries composed of any characters, thereby reducing the memory space occupied by ID queries and expanding the applicable scenarios of ID queries.
[0011] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0014] Figure 1 This is a flowchart of one embodiment of the ID query method in this invention;
[0015] Figure 2 This is a schematic diagram of an ID query method in an embodiment of the present invention;
[0016] Figure 3 This is a flowchart of another embodiment of the ID query method in this invention;
[0017] Figure 4 This is another schematic diagram of the ID query method in an embodiment of the present invention;
[0018] Figure 5 A schematic diagram of an ID query device provided in an embodiment of the present invention;
[0019] Figure 6 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” or “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0022] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 One embodiment of the ID query method in this invention includes:
[0023] Step S10: In response to the query instruction of the target ID, query the target ID through the first ID set corresponding to the target ID to obtain the first query result;
[0024] It should be noted that the target ID refers to the ID to be queried. The complete set of IDs corresponding to the target ID includes all IDs in the first ID set and all IDs in the second ID set. Therefore, in this embodiment of the invention, when responding to a query command for the target ID, it is necessary to determine whether the first ID set and the second ID set contain the target ID. This step first determines whether the first ID set contains the target ID, obtaining a first query result. The first query result is used to indicate whether the first ID set contains the target ID. In one implementation, the complete set of IDs corresponding to the target ID can be determined through a query command. Specifically, the complete set of IDs corresponding to the target ID can be determined through the query set identifier in the query command. For example, when querying whether a target item is included among all the items obtained by a game player, the query command sent by the game player's terminal can include the game player ID and the target item ID. Then, the game player ID can be used as the query set identifier, and the target item ID is the target ID. The complete set of items corresponding to the game player can be determined through the game player ID, which is to say, the complete set of IDs corresponding to the target ID can be determined. The specific details are not limited here.
[0025] Understandably, to avoid requiring a complete reconstruction of the trie every time the entire set of IDs corresponding to the target ID is updated, thus incurring additional computational overhead, in this embodiment, the first ID set dynamically increases as the entire set of IDs corresponding to the target ID increases, while the second ID set is used to build a stable trie and does not dynamically increase with the increase of the entire set of IDs corresponding to the target ID. In one embodiment, under preset reconstruction conditions, all IDs in the first ID set are merged into the second ID set, and the trie is reconstructed for all IDs in the second ID set, resulting in a new trie corresponding to the second ID set. Based on the above, the first ID set is a dynamic data set; when a new ID needs to be added, the newly added ID is actually added to the first ID set, while the second ID set is a relatively static data set, and when the preset reconstruction conditions are met, all IDs in the first ID set are merged in batches. It should be noted that after all IDs in the first ID set are merged into the second ID set, the data in the first ID set is cleared to store subsequently added IDs.
[0026] It should be noted that the IDs in the first ID set can be raw IDs without encryption or compression, or IDs that have been encrypted and / or compressed. In one implementation, the IDs in the first ID set are IDs processed by a preset encryption algorithm and / or a preset compression algorithm. For example, the preset encryption algorithm can be a Secure Hash Algorithm (SHA), a Message-Digest Algorithm (MD), a Data Encryption Standard (DES), an Advanced Encryption Standard (AES), etc., and the preset compression algorithm can be a DEFLATE lossless data compression algorithm, a LZO (Lempel-Ziv-Oberhumer) lossless compression algorithm, an LZ4 compression algorithm, etc., and the specifics are not limited here. In this embodiment, if the IDs in the first ID set are processed by a preset encryption algorithm and / or a preset compression algorithm, then, in response to the query instruction for the target ID, the first ID set corresponding to the target ID is decrypted and / or decompressed to obtain the decrypted and / or decompressed first ID set, and then the target ID is queried on the decrypted and / or decompressed first ID set to obtain the first query result.
[0027] Step S20: If the first query result indicates that the first ID set does not contain the target ID, then obtain the ordered character combination and child node position sequence corresponding to the target ID. The ordered character combination and child node position sequence are used to indicate the trie of the second ID set corresponding to the target ID. The ordered character combination is used to indicate the width-first node traversal result of the trie. The child node position sequence is used to indicate the number of child nodes of each node in the trie. The order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination.
[0028] It should be noted that if the first ID set does not contain the target ID, then it is necessary to further query whether the second ID set contains the target ID. If the first ID set contains the target ID, then it is not necessary to query whether the second ID set contains the target ID; that is, steps S20-S30 do not need to be executed, and the first query result can be output directly. In one implementation, if the first query result indicates that the first ID set contains the target ID, then steps S20-S30 are skipped, and the first query result is output, thereby improving the efficiency of ID query and reducing the memory space occupied by ID query.
[0029] In this embodiment, when performing an ID query for the second ID set, the second ID set is not directly obtained. Instead, an ordered combination of characters and a sequence of child nodes from a trie used to indicate the second ID set are obtained. The trie for the second ID set is constructed based on all IDs in the second ID set. It is understood that a trie, also known as a prefix tree, has the following properties: the root node contains no characters; each node except the root node contains only one character; the characters along the path from the root node to a target node (i.e., the terminal / end node) form the ID string corresponding to that target node; and all child nodes of each node contain distinct characters. Since the advantage of a trie is that it can utilize common prefixes of strings to reduce memory usage, storing more data in less space, this embodiment, by obtaining an ordered combination of characters and a sequence of child nodes generated based on the trie for subsequent character queries, enables ID queries without parsing the queried data and with reduced memory usage. Furthermore, because nodes in a trie can store arbitrary characters, ID queries are not only applicable to integers but also to ID queries containing arbitrary characters, thus expanding the applicable scenarios.
[0030] In one implementation, since the embodiments of the present invention do not directly query the ID from the trie, to improve the efficiency of ID lookup, a terminal symbol is added to the trie to indicate the end of a complete ID. This terminal symbol can be any character other than all the characters that make up the entire ID set. For example, assuming the entire ID set consists of the digits 0-9, the terminal symbol can be any special symbol, such as the $ symbol, # symbol, @ symbol, etc., or any English letter, such as the letter M. If the entire ID set consists of the digits 0-9, lowercase letters az, and uppercase letters AZ, then the terminal symbol can be any symbol / character other than digits and letters; no specific limitation is made here. Based on this, since the ordered character combination is generated based on the trie of the second ID set, the ordered character combination also includes the terminal symbol from the trie. As an example, and not a limitation, such as... Figure 2 The diagram shows a trie with terminal symbols, where `root` is the root node, and each node except the root node contains a single character. Nodes containing the `$` character are terminal / end nodes. By performing a breadth-first traversal of this trie, ordered character combinations can be obtained. The root node may or may not be included in the ordered character combinations; this is not limited here. In one implementation, if the root node is included in the ordered character combinations, it can be replaced by a preset character. The preset character only needs to be different from the characters constituting the entire ID set and the terminal symbol; this is also not limited here.
[0031] It is understandable that an ordered character combination can be in array format, string format, or other sequence format, and the order of characters in the ordered character combination is the same as the breadth-first traversal order of the trie nodes. For example, ... Figure 2 The trie shown can be traversed in a breadth-first manner as a string: "178008$12128$$$$$", or as an array: [1,7,8,0,0,8,$,1,2,1,2,8,$,$,$,$,$]. The specific result is not limited here. As an example, and not a limitation, if the root node is contained within an ordered combination of characters, for example... Figure 2 The set of all IDs corresponding to the trie shown consists of the numbers 0-9 and the terminal symbol is $. Therefore, the ordered character combination corresponding to this trie can be the string "#178008$12128$$$$$", or the array [#,1,7,8,0,0,8,$,1,2,1,2,8,$,$,$,$,$], where the symbol # is used to indicate the root node, and the specific meaning is not limited here.
[0032] In this embodiment, to represent the parent-child relationship between characters in an ordered character combination, a child node position sequence is used to record this relationship. This allows the complete trie to be reconstructed using only two simple strings: the ordered character combination and the child node position sequence. The child node position sequence indicates the number of child nodes for each node in the trie. For example, ... Figure 2 As shown, the root node has 3 child nodes. Child node 1 of the root node has 1 child node (child node 0), which in turn has 3 child nodes (child node $, child node 1, and child node 2), and so on. The number of child nodes for each node is recorded in the child node position sequence according to the node traversal order of the ordered character combination. The representation of the number of child nodes can be any method that can represent the number; no specific restriction is imposed here. For example, the number of child nodes can be represented using decimal numbers. Figure 2 The corresponding child node sequence of the trie can be "3111321011111". The number of child nodes can also be represented by binary numbers. For example, one 1 represents one child node, and a node ends with a 0. Then, three child nodes are represented as 1110, and two child nodes are represented as 110. Correspondingly, another way to represent the number of child nodes by binary numbers is to use one 0 to represent one child node, and a node ends with a 1. Then, three child nodes are represented as 0001, and two child nodes are represented as 001. The specific representation is not limited here.
[0033] Step S30: Search for the target ID character by character using ordered character combinations and child node bit sequences to obtain a second query result. The second query result is used to indicate whether the target ID is contained in the second ID set.
[0034] It is understandable that since a complete trie for the second ID set can be generated using ordered character combinations and child node bit sequences, this implementation does not require traversing the trie of the second ID set. Instead, it directly searches for each character of the target ID using ordered character combinations and child node bit sequences to obtain the second query result, thereby determining whether the second ID set contains the target ID. It should be noted that if the second query result indicates that every character in the target ID has a corresponding match, it can be determined that the second ID set contains the target ID; conversely, if the second query result indicates that no character in the target ID has a corresponding match, it can be determined that the second ID set does not contain the target ID. This implementation can perform the target ID query by loading two simple ordered character combinations and child node bit sequences into memory, which saves more memory space compared to loading a trie and other bitmap data, thus reducing the memory usage of ID queries.
[0035] In one implementation, since a complete trie of the second ID set can be generated through ordered character combinations and child node position sequences, the second query result can be obtained by searching the ordered character combinations and child node position sequences character by character using a preset character query algorithm. The preset character query algorithm employs different algorithm designs based on different data formats of the ordered character combinations, different character compositions, and different representations of the number of child nodes in the child node position sequences, to adapt to different business scenarios. As an example, and not a limitation, assuming the ordered character combinations are in array format, composed of node characters (including terminal symbols) excluding the root node character, and the child node position sequence's child node format is not a decimal number representation, then... Figure 2Taking a trie as an example, the ordered character combination corresponding to this trie is [1,7,8,0,0,8,$,1,2,1,2,8,$,$,$,$,$], and the corresponding child node position sequence is 3111321011111. Assuming the target ID is "10", then the first character to be searched is "1". According to the first digit "3" in the child node position sequence, we know that the root node of the trie has 3 child nodes. Therefore, the first 3 characters in the ordered character combination are the 3 child node characters of the root node, namely "1, 7, 8", which includes the first character to be searched. Therefore, we continue searching for the second character "0". Since the character "1" is the first child node of the root node, shifting the root node one position to the right in the child node sequence gives us the number of child nodes for the first character "1", which is "1". The last node of the three child nodes of the root node in the ordered character combination is the child node character for the first character "1", which is "0", the same as the second character we are searching for. Finally, we check if any of the child nodes of the second character contains a terminal character. This determines whether the second ID set contains the target ID "10". If it does, the second ID set contains the target ID "10"; otherwise, it does not.
[0036] The ID query method provided in the above embodiments includes a first ID set and a second ID set as the query scope. The second ID set is indicated by two simple characters generated by a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second ID set by simply loading these two simple characters into memory. The target ID can be queried directly without complex operations such as decompression and deserialization. Since the trie does not restrict the node characters, this method is applicable to ID queries composed of any characters, thereby reducing the memory space occupied by ID queries and expanding the applicable scenarios of ID queries.
[0037] Please see Figure 3 Another embodiment of the ID query method in this invention includes:
[0038] Step S301: In response to the query instruction of the target ID, query the target ID through the first ID set corresponding to the target ID to obtain the first query result;
[0039] In one implementation, before step S301, the method further includes: in response to the number of IDs in the first ID set exceeding a preset threshold, merging the first ID set into the second ID set to obtain a new second ID set; and constructing a trie for the new second ID set based on the ordered character combination and child node sequence corresponding to the target ID, thus obtaining a trie for the new second ID set. It is understood that to ensure the stability of the trie for the second ID set, the trie is constructed / reconstructed only under preset reconstruction conditions. In this implementation, the reconstruction condition is triggered when the number of IDs in the first ID set exceeds the preset threshold. After triggering the trie construction / reconstruction, the first ID set is merged into the second ID set to obtain a new second ID set, which contains all IDs. Then, a trie is constructed for all IDs in the new second ID set, thus obtaining a trie for the second ID set. It should be noted that after the first ID set is merged into the second ID set, the new first ID set is an empty data set, which continues to be used to record newly added IDs.
[0040] In one implementation, the construction of the trie of the new second ID set can be achieved by obtaining / constructing the trie of the original second ID set based on the ordered character combination and child node sequence corresponding to the target ID, and then inserting all IDs from the first ID set into the trie of the original second ID set to obtain the trie of the new second ID set; alternatively, the trie can be constructed directly on all IDs in the new second ID set to obtain the trie of the new second ID set.
[0041] In one implementation, prior to step S301, the method further includes: in response to the completion of the construction of the trie of the second ID set, performing a breadth-first node traversal of the trie of the second ID set corresponding to the target ID, and storing the traversed characters sequentially into a preset array to obtain an ordered character combination corresponding to the target ID, wherein the trie includes the terminal symbol of the ID; performing a traversal of the number of child nodes of each node in the trie of the second ID set corresponding to the target ID, and recording each child node using the first symbol in binary and the second symbol recording the end of each node to obtain the child node bit sequence corresponding to the target ID.
[0042] In this embodiment, when the trie of the second ID set is constructed, the ordered character combinations and child node sequence corresponding to the trie (i.e., the ordered character combinations and child node sequence corresponding to the target ID) are immediately generated for target ID lookup. Specifically, when generating the ordered character combinations, the trie of the second ID set is traversed using a breadth-first algorithm. Each node character obtained from the traversal is then stored sequentially in a preset array, thus obtaining the ordered character combinations corresponding to the trie. The preset array is an empty array. For example, as shown... Figure 2 The trie shown is traversed from top to bottom and left to right using a breadth-first search algorithm. This stores the characters of each trie node in an array in top-to-bottom, left-to-right order, resulting in an ordered combination of characters for the trie. When generating the child node sequence, the number of child nodes for each node in the trie is counted. Each traversed child node is recorded as the first symbol in binary. After traversing all child nodes of a node, a second symbol in binary is added to indicate the end of that node. This results in the child node sequence, where the first and second symbols are 1 and 0 respectively. If the first symbol is 1, the second symbol is 0; conversely, if the first symbol is 0, the second symbol is 1. The specific values are not limited here. For example, as shown... Figure 2 In the trie shown, each child node of the root node is recorded as a first symbol (assumed to be 1). After all child nodes are recorded, a second symbol is added. Then the root node is represented in the child node bit sequence as 1110. The specific representation is not limited here.
[0043] In one implementation, the first ID set corresponding to the target ID is used to indicate the hash ID set. To improve the data security of ID queries, the IDs in the first ID set are IDs encrypted using a hash algorithm, that is, the first ID set is a hash ID set, making ID queries more secure.
[0044] Step S302: If the first query result indicates that the first ID set does not contain the target ID, then obtain the ordered character combination and child node position sequence corresponding to the target ID. The ordered character combination and child node position sequence are used to indicate the trie of the second ID set corresponding to the target ID. The ordered character combination is used to indicate the width-first node traversal result of the trie. The child node position sequence is used to indicate the number of child nodes of each node in the trie. The order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination.
[0045] The execution process of step S302 is similar to that of step S20, and will not be described in detail here.
[0046] Step S303: Determine the starting position of the current parent node and the starting position of the current child node corresponding to the current character of the target ID. The starting position of the current parent node is used to indicate the starting position of the current character in the child node position sequence, and the starting position of the current child node is used to indicate the starting position of all child nodes of the current character in the ordered character combination. The starting position of the current parent node corresponding to the first current character of the target ID is the starting position of the root node.
[0047] It should be noted that steps S303-S306 are one implementation of step S30. In this process, when querying each character of the target ID, it is necessary to record / update the starting position of the current parent node (denoted as pos1) and the starting position of the current child node (denoted as pos2) corresponding to the current character. Here, pos1 refers to the starting position of the current character in the child node position sequence (denoted as b), and pos2 refers to the starting position of all child nodes of the current character in the ordered character combination (denoted as c). According to the character order of the target ID, the current character of the target ID is determined starting from the first character. The pos1 of the first current character is the starting position of the root node, that is, pos1 = 1 for the first current character of the target ID. The pos2 of the first current character also starts from the first character, that is, pos2 = 0 or pos2 = 1 for the first current character of the target ID, depending on whether the substitute character of the root node is in c. If the substitute character of the root node is in c, then pos2 = 1; otherwise, pos2 = 0. For intuitive illustration, this is presented as an example rather than a limitation. Figure 4 Based on Figure 2 The trie generates b (a 1 represents a child node) and c, where pos1 and pos2 are pointers to each other, used to indicate the starting position of the current character in b and c, respectively. The specific position is not limited here.
[0048] Step S304: Based on the starting position of the current parent node and the starting position of the current child node corresponding to the current character, determine all child node characters of the current character in the ordered character combination, and obtain at least one child node character;
[0049] Understandably, after determining pos1 and pos2 corresponding to the current character, we can determine whether the current character and its position exist in the trie of the second ID set by checking if all child nodes of the current character contain the current character. This allows us to decide whether to proceed with the next character query or whether the target ID is contained in the second ID set. Specifically, this step first determines all child nodes of the current character in c based on pos1 and pos2. Here, "all child nodes of the first current character" refers to all child nodes of the root node. For example, ... Figure 4As shown, assuming the target ID is "10", then the first current character "1" corresponds to pos2=1 and pos1=0. By traversing b through pos1 until the first 0 is encountered, that is, when pos1=4, the traversal yields 3 1s. Therefore, it can be determined that the number of child nodes of the first current character is 3. That is, when pos2=1, pos2=2, and pos2=3, the value of c is the child node character of the first current character, and the at least one child node character obtained is 1, 7, and 8 respectively.
[0050] In one implementation, the ordered character combination is used to indicate the character array of the breadth-first node traversal of the trie, the child node bit sequence is used to indicate the binary bit sequence, the number of first symbols in the binary bit sequence is used to indicate the number of child nodes of each node in the trie, and the number of second symbols in the binary bit sequence is used to indicate the end of each node in the trie; the above step S304 includes: calculating the number of first symbols between the current parent node start position and the nearest second symbol in the child node bit sequence according to the current parent node start position corresponding to the current character, to obtain the number of child nodes of the current character; determining all child node characters of the current character in the character array according to the current child node start position and the number of child nodes of the current character, to obtain at least one child node character. In this implementation, the ordered character combination is an array, and the child node bit sequence is a sequence of binary bits. When determining at least one child node character corresponding to the current character, firstly, according to the pos1 corresponding to the current character, the number of first symbols between pos1 in b and the nearest second symbol is calculated, thereby obtaining the number of child nodes of the current character. Figure 4 As shown, the first symbol is 1, and the second symbol is 0. When pos1 = 1, pos1 and the nearest 0 are in the 4th position. The positions from the 1st to the 4th contain three 1s; therefore, the current character has 3 child nodes. Next, based on pos2 and the current character's child node count of 3, all child node characters of the current character are determined, as follows: Figure 4 As shown, the three child node characters of pos2=0, pos2=1 and pos2=2 are all child node characters of the current character, and the specifics are not limited here.
[0051] Step S305: Determine whether all child node characters contain the current character;
[0052] In this step, after obtaining all the child node characters of the current character, it is possible to determine whether the current character is contained among all the child node characters. For example, in the example above, assuming that at least one child node character of the current character "1" is 1, 7 and 8, then it is possible to determine whether the current character "1" is contained among 1, 7 and 8.
[0053] Step S306: If all child node characters contain the current character, then determine the parent node start position and child node start position corresponding to the next character based on the position of the current character among all child node characters. Then, determine the next character as the current character, and determine the parent node start position and child node start position corresponding to the next character as the current parent node start position and current child node start position corresponding to the current character. Repeat steps S303-S306 until it is determined that the ordered character combination contains all characters of the target ID, or that all child node characters of any current character in the ordered character combination do not contain the current character, and obtain the second query result.
[0054] In this step, if the current character is contained in all child node characters, the next character in the target ID is further processed. First, based on the position of the current character among all child node characters, the pos1 and pos2 corresponding to the next character are determined. Then, the pos1 and pos2 corresponding to the next character are determined as the pos1 and pos2 corresponding to the current character. Steps S303-S306 are repeated until all characters (including terminal symbols) of the target ID match their corresponding child node characters, or no character in the target ID matches its corresponding child node character. At this point, a second query result is generated to indicate whether the target ID is contained in the second ID set. As an example, and not a limitation, such as... Figure 4 As shown, assuming the target ID is "10", after determining that all child node characters contain the first current character "1", since the current character "1" is in the 1st position among all child node characters, its position is 1. The number of child nodes for the current character is 3. Therefore, the pos1 of the next character is 3 + 1 + 1 = 5, and the pos2 is 3. Figure 4 In the process, pos2 is moved to the position of the first 0, pos1 is moved to the position of the first 1 after the first 0, and steps S303-S306 are repeated.
[0055] In one implementation, if all child node characters contain the current character, then determining the parent node start position and child node start position corresponding to the next character based on the position of the current character among all child node characters includes: step S3061, if all child node characters contain the current character, then performing a first preset position sequence operation on the position of the current character among all child node characters and the current child node start position to obtain the parent node start position corresponding to the next character, and performing a second preset position sequence operation on the position of the current character among all child node characters and the current child node start position to obtain the child node start position corresponding to the next character.
[0056] Understandably, for binary, there are two pre-defined bit sequence operations: one for calculating the position of the i-th 1 (i.e., the select1(i) operation), such as...Figure 4 In b shown, select1(4) = 5; another operation is used to calculate the position of the i-th 0 (i.e., select0(i) operation), such as Figure 4 In the example b, select0(2) = 6. In this embodiment, when determining the pos1 and pos2 of the next character, it can be achieved using select1(i) or select0(i), for example, as shown in the example b. Figure 5 As shown, assuming the target ID is "10", after determining that all child node characters contain the first current character "1", since the current character "1" is in the first position among all child node characters, the position of the current character among all child node characters is 1 (denoted as j). The number of child nodes of the current character is 3. Since the pos2 of the first current character is 0, then the pos1 of the next character is select0(pos2+j)+1=select0(0+1)+1=select0(1)+1=4+1=5, and the pos2 of the next character is select0(pos2+j)-(pos2+j)=select0(0+1)-(0+1)=select0(1)-1=4-1=3. That is, the pos1 of the next character is 5 and the pos2 is 3. Similarly, the select1(i) operation can achieve the same effect as the above calculation process. The specific process will not be repeated here. Based on this, the first preset bit sequence operation and the second preset bit sequence operation refer to the select0(i) operation or the select1(i) operation. The specifics are not limited here.
[0057] In one embodiment, step S3061 includes: if all child node characters contain the current character, then based on the position of the current character among all child node characters and the starting position of the current child node, obtain the preset bit sequence first operation result, and determine the parent node starting position corresponding to the next character based on the bit sequence first operation result; based on the position of the current character among all child node characters and the starting position of the current child node, obtain the preset bit sequence second operation result, and determine the child node starting position corresponding to the next character based on the bit sequence second operation result. In this embodiment, in order to improve the operation efficiency of bit sequence and avoid traversing each value of pos1 for each ID query, the bit sequence operation results of each bit of pos1 are pre-recorded in memory. When performing bit sequence operation, the preset bit sequence first operation result and bit sequence second operation result can be directly obtained, thereby improving the efficiency of ID query. For example, in the previous example, select0(1) = 4 is the bit sequence first operation result. Since the second preset bit sequence operation is also select0(1), select0(1) = 4 is also the bit sequence second operation result. The specific details are not limited here.
[0058] The ID query method provided in the above embodiments includes a first ID set and a second ID set as the query scope. The second ID set is indicated by two simple characters generated by a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second ID set by simply loading these two simple characters into memory. The target ID can be queried directly without complex operations such as decompression and deserialization. Since the trie does not restrict the node characters, this method is applicable to ID queries composed of any characters, thereby reducing the memory space occupied by ID queries and expanding the applicable scenarios of ID queries.
[0059] For the corresponding method embodiments described above, see [link to relevant documentation]. Figure 6 The diagram illustrates an ID query device, comprising: a response module 50, configured to, in response to a query instruction for a target ID, query the target ID through a first ID set corresponding to the target ID to obtain a first query result; an acquisition module 52, configured to, if the first query result indicates that the first ID set does not contain the target ID, acquire an ordered character combination and a child node sequence corresponding to the target ID, wherein the ordered character combination and the child node sequence are used to indicate a trie of a second ID set corresponding to the target ID, the ordered character combination is used to indicate the breadth-first node traversal result of the trie, and the child node sequence is used to indicate the number of child nodes of each node in the trie, the order of each node in the child node sequence being the same as the node traversal order of the ordered character combination; and a search module 54, configured to, through the ordered character combination and the child node sequence, search for each character of the target ID to obtain a second query result, the second query result being used to indicate whether the second ID set contains the target ID.
[0060] The aforementioned ID query device allows the target ID to be queried within a first ID set and a second ID set. The second ID set is indicated by two simple characters generated from a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second ID set by simply loading these two simple characters into memory, without the need for complex operations such as decompression or deserialization. Since the trie does not restrict the characters used in the nodes, this method is applicable to ID queries composed of any characters, thereby reducing the memory space required for ID queries and expanding the applicable scenarios for ID queries.
[0061] Optionally, the above apparatus includes: a first determining unit, configured to determine the current parent node start position and the current child node start position corresponding to the current character of the target ID, wherein the current parent node start position is used to indicate the start position of the current character in the child node position sequence, and the current child node start position is used to indicate the start position of all child nodes of the current character in the ordered character combination, wherein the current parent node start position corresponding to the first current character of the target ID is the root node start position; a second determining unit, configured to determine all child node characters of the current character in the ordered character combination based on the current parent node start position and the current child node start position corresponding to the current character, thereby obtaining at least one child node character; and a character judging unit, configured to judge all of the... The third determining unit is used to determine whether the child node characters contain the current character. If all the child node characters contain the current character, then based on the position of the current character among all the child node characters, the starting position of the parent node and the starting position of the child node corresponding to the next character are determined, and the next character is determined as the current character. The starting position of the parent node and the starting position of the child node corresponding to the next character are determined as the starting position of the current parent node and the starting position of the current child node corresponding to the current character. The first determining unit, the second determining unit, the character judging unit and the third determining unit are repeated until it is determined that the ordered character combination contains all the characters of the target ID, or that all the child node characters of any current character in the ordered character combination do not contain the current character, and a second query result is obtained.
[0062] Optionally, the ordered character combination is used to indicate the character array of the breadth-first node traversal of the trie, the child node bit sequence is used to indicate the binary bit sequence, the number of each first symbol in the binary bit sequence is used to indicate the number of child nodes of each node in the trie, and each second symbol in the binary bit sequence is used to indicate the end of each node in the trie; the second determining unit is further used to: calculate the number of first symbols between the current parent node starting position and the nearest second symbol in the child node bit sequence according to the current parent node starting position corresponding to the current character, to obtain the number of child nodes of the current character; and determine all child node characters of the current character in the character array according to the current child node starting position and the number of child nodes of the current character, to obtain at least one child node character.
[0063] Optionally, the third determining unit further includes: an operation subunit, configured to, if all the child node characters contain the current character, perform a first preset position sequence operation on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character, and perform a second preset position sequence operation on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character.
[0064] Optionally, the above-mentioned operation subunit is further configured to: if all the child node characters contain the current character, obtain a preset bit sequence first operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determine the starting position of the parent node corresponding to the next character based on the bit sequence first operation result; obtain a preset bit sequence second operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determine the starting position of the child node corresponding to the next character based on the bit sequence second operation result.
[0065] Optionally, the above apparatus further includes: an incorporation module, configured to, in response to the number of IDs in the first ID set being greater than a preset number threshold, merge the first ID set into the second ID set to obtain a new second ID set; and a construction module, configured to, based on the ordered character combination and child node position sequence corresponding to the target ID, construct a trie for the new second ID set to obtain a trie of the new second ID set.
[0066] Optionally, the above apparatus further includes: a first traversal module, configured to, in response to the completion of the construction of the trie of the second ID set, perform a breadth-first node traversal of the trie of the second ID set corresponding to the target ID, and store the traversed characters sequentially into a preset array to obtain an ordered character combination corresponding to the target ID, wherein the trie includes the terminal symbol of the ID; and a second traversal module, configured to traverse the trie of the second ID set corresponding to the target ID by counting the number of child nodes of each node, and record each child node using a first symbol in binary and a second symbol to record the end of each node, to obtain the child node bit sequence corresponding to the target ID.
[0067] Optionally, the first ID set corresponding to the target ID is used to indicate the hash ID set.
[0068] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the aforementioned ID query method. This electronic device can be a server or a terminal device.
[0069] See Figure 6 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the above-mentioned ID query method.
[0070] Furthermore, Figure 6 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0071] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0072] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101. The processor 100 reads information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments, for example:
[0073] In response to a query command for a target ID, the system queries the target ID using the first set of IDs corresponding to the target ID to obtain a first query result. If the first query result indicates that the first set of IDs does not contain the target ID, the system obtains the ordered character combination and child node sequence corresponding to the target ID. The ordered character combination and child node sequence are used to indicate the trie of the second set of IDs corresponding to the target ID. The ordered character combination is used to indicate the breadth-first node traversal result of the trie, and the child node sequence is used to indicate the number of child nodes of each node in the trie. The order of each node in the child node sequence is the same as the node traversal order of the ordered character combination. The system then searches for each character of the target ID using the ordered character combination and child node sequence to obtain a second query result. The second query result is used to indicate whether the second set of IDs contains the target ID.
[0074] In this method, the query range of the target ID includes a first set of IDs and a second set of IDs. The second set of IDs is indicated by two simple characters generated by a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second set of IDs. Only these two simple characters need to be loaded into memory, and the target ID can be directly queried without complex operations such as decompression and deserialization. Since the trie does not restrict the node characters, this method is applicable to ID queries composed of any characters, thereby reducing the memory space occupied by ID queries and expanding the applicable scenarios of ID queries.
[0075] In this method, the above-mentioned character-by-character search of the target ID through ordered character combinations and child node position sequences to obtain the second query result includes: S1, determining the starting position of the current parent node and the starting position of the current child node corresponding to the current character of the target ID. The starting position of the current parent node is used to indicate the starting position of the current character in the child node position sequence, and the starting position of the current child node is used to indicate the starting position of all child nodes of the current character in the ordered character combination. Among them, the starting position of the current parent node corresponding to the first current character of the target ID is the starting position of the root node; S2, determining all child node characters of the current character in the ordered character combination based on the starting position of the current parent node and the starting position of the current child node corresponding to the current character. S1-S4: First, obtain at least one child node character. Second, determine whether all child node characters contain the current character. Third, if all child node characters contain the current character, determine the parent node start position and child node start position corresponding to the next character based on the position of the current character among all child node characters. Then, determine the next character as the current character, and determine the parent node start position and child node start position corresponding to the next character as the current parent node start position and current child node start position corresponding to the current character. Repeat steps S1-S4 until it is determined that the ordered character combination contains all characters of the target ID, or that all child node characters of any current character in the ordered character combination do not contain the current character, and obtain the second query result.
[0076] In this method, the aforementioned ordered character combination is used to indicate the character array of the breadth-first node traversal of the trie, the child node bit sequence is used to indicate the binary bit sequence, the number of each first symbol in the binary bit sequence is used to indicate the number of child nodes of each node in the trie, and the number of each second symbol in the binary bit sequence is used to indicate the end of each node in the trie. The above method of determining all child node characters of the current character in the ordered character combination based on the starting position of the current parent node and the starting position of the current child node, and obtaining at least one child node character, includes: calculating the number of first symbols between the starting position of the current parent node and the nearest second symbol in the child node bit sequence based on the starting position of the current parent node, and obtaining the number of child nodes of the current character; determining all child node characters of the current character in the character array based on the starting position of the current child node and the number of child nodes of the current character, and obtaining at least one child node character.
[0077] In this method, if all child node characters contain the current character, then the starting position of the parent node and the starting position of the child node corresponding to the next character are determined according to the position of the current character among all child node characters. This includes: if all child node characters contain the current character, then the first preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character, and the second preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character.
[0078] In this method, if all child node characters contain the current character, a first preset bit sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character. Then, a second preset bit sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character. This includes: if all child node characters contain the current character, obtaining the preset first bit sequence operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determining the starting position of the parent node corresponding to the next character based on the first bit sequence operation result; obtaining the preset second bit sequence operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determining the starting position of the child node corresponding to the next character based on the second bit sequence operation result.
[0079] In this method, the above method further includes: in response to the number of IDs in the first ID set being greater than a preset number threshold, merging the first ID set into the second ID set to obtain a new second ID set; constructing a trie for the new second ID set based on the ordered character combination and child node position sequence corresponding to the target ID to obtain a trie for the new second ID set.
[0080] In this method, the above method further includes: in response to the completion of the construction of the trie of the second ID set, performing a breadth-first node traversal of the trie of the second ID set corresponding to the target ID, and storing the characters obtained by the traversal into a preset array in sequence to obtain an ordered character combination corresponding to the target ID, wherein the trie includes the terminal symbol of the ID; performing a traversal of the number of child nodes of each node in the trie of the second ID set corresponding to the target ID, and recording each child node by the first symbol in binary and recording the end of each node by the second symbol to obtain the child node bit sequence corresponding to the target ID.
[0081] In this approach, the first set of IDs corresponding to the aforementioned target ID is used to indicate the hash ID set.
[0082] This embodiment also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are invoked and executed by a processor, they cause the processor to implement the aforementioned ID lookup method, for example:
[0083] In response to a query command for a target ID, the system queries the target ID using the first set of IDs corresponding to the target ID to obtain a first query result. If the first query result indicates that the first set of IDs does not contain the target ID, the system obtains the ordered character combination and child node sequence corresponding to the target ID. The ordered character combination and child node sequence are used to indicate the trie of the second set of IDs corresponding to the target ID. The ordered character combination is used to indicate the breadth-first node traversal result of the trie, and the child node sequence is used to indicate the number of child nodes of each node in the trie. The order of each node in the child node sequence is the same as the node traversal order of the ordered character combination. The system then searches for each character of the target ID using the ordered character combination and child node sequence to obtain a second query result. The second query result is used to indicate whether the second set of IDs contains the target ID.
[0084] In this method, the query range of the target ID includes a first set of IDs and a second set of IDs. The second set of IDs is indicated by two simple characters generated by a pre-constructed trie: an ordered combination of characters and a sequence of child nodes. This allows the query to determine whether the target ID is contained in the second set of IDs. Only these two simple characters need to be loaded into memory, and the target ID can be directly queried without complex operations such as decompression and deserialization. Since the trie does not restrict the node characters, this method is applicable to ID queries composed of any characters, thereby reducing the memory space occupied by ID queries and expanding the applicable scenarios of ID queries.
[0085] In this method, the above-mentioned character-by-character search of the target ID through ordered character combinations and child node position sequences to obtain the second query result includes: S1, determining the starting position of the current parent node and the starting position of the current child node corresponding to the current character of the target ID. The starting position of the current parent node is used to indicate the starting position of the current character in the child node position sequence, and the starting position of the current child node is used to indicate the starting position of all child nodes of the current character in the ordered character combination. Among them, the starting position of the current parent node corresponding to the first current character of the target ID is the starting position of the root node; S2, determining all child node characters of the current character in the ordered character combination based on the starting position of the current parent node and the starting position of the current child node corresponding to the current character. S1-S4: First, obtain at least one child node character. Second, determine whether all child node characters contain the current character. Third, if all child node characters contain the current character, determine the parent node start position and child node start position corresponding to the next character based on the position of the current character among all child node characters. Then, determine the next character as the current character, and determine the parent node start position and child node start position corresponding to the next character as the current parent node start position and current child node start position corresponding to the current character. Repeat steps S1-S4 until it is determined that the ordered character combination contains all characters of the target ID, or that all child node characters of any current character in the ordered character combination do not contain the current character, and obtain the second query result.
[0086] In this method, the aforementioned ordered character combination is used to indicate the character array of the breadth-first node traversal of the trie, the child node bit sequence is used to indicate the binary bit sequence, the number of each first symbol in the binary bit sequence is used to indicate the number of child nodes of each node in the trie, and the number of each second symbol in the binary bit sequence is used to indicate the end of each node in the trie. The above method of determining all child node characters of the current character in the ordered character combination based on the starting position of the current parent node and the starting position of the current child node, and obtaining at least one child node character, includes: calculating the number of first symbols between the starting position of the current parent node and the nearest second symbol in the child node bit sequence based on the starting position of the current parent node, and obtaining the number of child nodes of the current character; determining all child node characters of the current character in the character array based on the starting position of the current child node and the number of child nodes of the current character, and obtaining at least one child node character.
[0087] In this method, if all child node characters contain the current character, then the starting position of the parent node and the starting position of the child node corresponding to the next character are determined according to the position of the current character among all child node characters. This includes: if all child node characters contain the current character, then the first preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character, and the second preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character.
[0088] In this method, if all child node characters contain the current character, a first preset bit sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character. Then, a second preset bit sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character. This includes: if all child node characters contain the current character, obtaining the preset first bit sequence operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determining the starting position of the parent node corresponding to the next character based on the first bit sequence operation result; obtaining the preset second bit sequence operation result based on the position of the current character among all child node characters and the starting position of the current child node, and determining the starting position of the child node corresponding to the next character based on the second bit sequence operation result.
[0089] In this method, the above method further includes: in response to the number of IDs in the first ID set being greater than a preset number threshold, merging the first ID set into the second ID set to obtain a new second ID set; constructing a trie for the new second ID set based on the ordered character combination and child node position sequence corresponding to the target ID to obtain a trie for the new second ID set.
[0090] In this method, the above method further includes: in response to the completion of the construction of the trie of the second ID set, performing a breadth-first node traversal of the trie of the second ID set corresponding to the target ID, and storing the characters obtained by the traversal into a preset array in sequence to obtain an ordered character combination corresponding to the target ID, wherein the trie includes the terminal symbol of the ID; performing a traversal of the number of child nodes of each node in the trie of the second ID set corresponding to the target ID, and recording each child node by the first symbol in binary and recording the end of each node by the second symbol to obtain the child node bit sequence corresponding to the target ID.
[0091] In this approach, the first set of IDs corresponding to the aforementioned target ID is used to indicate the hash ID set.
[0092] The computer program product of the ID query method, apparatus, electronic device and storage medium provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0093] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0094] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0095] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0096] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0097] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for querying an ID, characterized in that, The method includes: In response to a query command for a target ID, the target ID is queried through the first set of IDs corresponding to the target ID to obtain a first query result; If the first query result indicates that the first ID set does not contain the target ID, then obtain the ordered character combination and child node position sequence corresponding to the target ID. The ordered character combination and the child node position sequence are used to indicate the trie of the second ID set corresponding to the target ID. The ordered character combination is used to indicate the width-first node traversal result of the trie. The child node position sequence is used to indicate the number of child nodes of each node in the trie. The order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination. By performing a character-by-character search of the target ID using the ordered character combination and the child node position sequence, a second query result is obtained. The second query result is used to indicate whether the target ID is contained in the second ID set. The second query result is obtained by performing a character-by-character search of the target ID using a preset character query algorithm on the ordered character combination and the child node position sequence.
2. The method according to claim 1, characterized in that, The step of searching the target ID character by character using the ordered character combination and the child node position sequence to obtain the second query result includes: S1. Determine the starting position of the current parent node and the starting position of the current child node corresponding to the current character of the target ID. The starting position of the current parent node is used to indicate the starting position of the current character in the child node position sequence. The starting position of the current child node is used to indicate the starting position of all child nodes of the current character in the ordered character combination. The starting position of the current parent node corresponding to the first current character of the target ID is the starting position of the root node. S2. Based on the starting position of the current parent node and the starting position of the current child node corresponding to the current character, determine all child node characters of the current character in the ordered character combination, and obtain at least one child node character; S3. Determine whether all the child node characters contain the current character; S4. If all the child node characters contain the current character, then based on the position of the current character among all the child node characters, determine the parent node start position and child node start position corresponding to the next character, and determine the next character as the current character. The parent node start position and child node start position corresponding to the next character are determined as the current parent node start position and current child node start position corresponding to the current character. Repeat steps S1-S4 until it is determined that the ordered character combination contains all the characters of the target ID, or that all the child node characters of any current character in the ordered character combination do not contain the current character, and obtain the second query result.
3. The method according to claim 2, characterized in that, The ordered character combination is used to indicate the character array traversed by the width-first node of the trie; the child node bit sequence is used to indicate the binary bit sequence; the number of each first symbol in the binary bit sequence is used to indicate the number of child nodes of each node in the trie; and each second symbol in the binary bit sequence is used to indicate the end of each node in the trie. The step of determining all child node characters of the current character in the ordered character combination based on the starting position of the current parent node and the starting position of the current child node corresponding to the current character, to obtain at least one child node character, includes: Based on the starting position of the current parent node corresponding to the current character, calculate the number of the first symbols between the starting position of the current parent node and the nearest second symbol in the child node position sequence, and obtain the number of child nodes of the current character; Based on the starting position of the current child node and the number of child nodes of the current character, determine all child node characters of the current character in the character array, and obtain at least one child node character.
4. The method according to claim 2, characterized in that, If all the child node characters contain the current character, then based on the position of the current character among all child node characters, the starting position of the parent node and the starting position of the child node corresponding to the next character are determined, including: If all the child node characters contain the current character, then perform a first preset position sequence operation on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character, and perform a second preset position sequence operation on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character.
5. The method according to claim 4, characterized in that, If all the child node characters contain the current character, then a first preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the parent node corresponding to the next character, and a second preset position sequence operation is performed on the position of the current character among all child node characters and the starting position of the current child node to obtain the starting position of the child node corresponding to the next character, including: If all the child node characters contain the current character, then based on the position of the current character among all the child node characters and the starting position of the current child node, the first operation result of the preset bit sequence is obtained, and based on the first operation result of the bit sequence, the starting position of the parent node corresponding to the next character is determined; Based on the position of the current character among all child node characters and the starting position of the current child node, obtain the preset second operation result of the bit sequence, and determine the starting position of the child node corresponding to the next character based on the second operation result of the bit sequence.
6. The method according to claim 1, characterized in that, The method further includes: In response to the fact that the number of IDs in the first ID set is greater than a preset threshold, the first ID set is merged into the second ID set to obtain a new second ID set; Based on the ordered character combination and child node sequence corresponding to the target ID, a trie is constructed for the new second ID set to obtain the trie of the new second ID set.
7. The method according to claim 1, characterized in that, The method further includes: In response to the completion of the construction of the trie of the second ID set, a breadth-first node traversal is performed on the trie of the second ID set corresponding to the target ID, and the characters obtained by the traversal are stored in a preset array in sequence to obtain the ordered character combination corresponding to the target ID, wherein the trie includes the terminal symbol of the ID; The number of child nodes of each node in the trie of the second ID set corresponding to the target ID is traversed, and the first symbol in the binary representation is used to record the number of child nodes, and the second symbol is used to record the end of each node, so as to obtain the child node bit sequence corresponding to the target ID.
8. The method according to claim 1, characterized in that, The first set of IDs corresponding to the target ID is used to indicate the hash ID set.
9. An ID lookup device, characterized in that, The device includes: The response module is used to respond to a query command for a target ID, and to query the target ID through a first set of IDs corresponding to the target ID to obtain a first query result; The acquisition module is configured to, if the first query result indicates that the first ID set does not contain the target ID, acquire the ordered character combination and child node position sequence corresponding to the target ID, wherein the ordered character combination and the child node position sequence are used to indicate the trie of the second ID set corresponding to the target ID, the ordered character combination is used to indicate the width-first node traversal result of the trie, and the child node position sequence is used to indicate the number of child nodes of each node in the trie, wherein the order of each node in the child node position sequence is the same as the node traversal order of the ordered character combination; The search module is used to search for the target ID character by character using the ordered character combination and the child node position sequence to obtain a second query result. The second query result is used to indicate whether the target ID is contained in the second ID set. The second query result searches for the target ID character by character using a preset character query algorithm using the ordered character combination and the child node position sequence.
10. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the ID lookup method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the ID lookup method according to any one of claims 1-8.
Citation Information
Patent Citations
Dictionary tree-based search processing method,device and equipment,and storage medium
CN110851722A
Information search method and device, terminal equipment and computer readable storage medium
CN113342848A