Trie adjustment methods, devices, equipment, storage media, and products
By constructing shared nodes and merging child nodes in the trie, the problem of low storage efficiency of the trie is solved, and more efficient storage utilization is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG ZEEKR INTELLIGENT TECH CO LTD
- Filing Date
- 2024-12-17
- Publication Date
- 2026-04-21
AI Technical Summary
Trie storage is inefficient; as the number and length of strings increase, the storage space grows linearly, leading to a lot of redundancy.
By obtaining the occurrence count of a trie node and determining whether it exceeds a preset threshold, frequently accessed nodes and their parent nodes are constructed as shared nodes, and the structures are merged to achieve shared storage of characters.
It improves the space utilization of the trie, reduces the redundancy of character storage, and enhances storage efficiency.
Smart Images

Figure CN119807478B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, and in particular to methods, apparatus, devices, storage media, and products for adjusting trie trees. Background Technology
[0002] Currently, with the rapid development of information technology, the demand for processing and storing large-scale string data is increasing. Against this backdrop, the trie, as an efficient string retrieval data structure, is widely used in fields such as auto-completion, spell checking, and word frequency statistics.
[0003] In related technologies, a trie is composed of nodes, each containing a character and a mapping to the next level node, and each node stores the character independently. However, as the number and length of strings increase, the storage space of the trie grows linearly. The structure of storing characters independently leads to a large amount of data redundancy, resulting in low storage efficiency for the trie.
[0004] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0005] The main purpose of this application is to provide a method for adjusting a trie, which aims to solve the technical problem of low storage efficiency of tries.
[0006] To achieve the above objectives, this application proposes a method for adjusting a trie, the method comprising:
[0007] After the nodes of the trie are updated, obtain the occurrence count of each node in the current trie;
[0008] Determine whether there exists a node in the trie whose occurrence count exceeds a preset threshold.
[0009] If a node appears more than a preset threshold number of times, then that node and at least one of its parent nodes are constructed as a shared node of the trie, and based on the shared node, the child nodes of that node are structurally merged to obtain a trie with an adjusted structure.
[0010] Optionally, the step of constructing the node and at least one of its parent nodes as a shared node of the trie includes:
[0011] Get the length of the character sequence for this node;
[0012] Determine whether the length of the character sequence is less than a preset length threshold;
[0013] If the length of the character sequence is less than a preset length threshold, then the node and the corresponding number of parent nodes of the character sequence length are constructed as shared nodes of the trie.
[0014] Optionally, before the step of determining whether there exists a node in the trie whose occurrence count exceeds a preset threshold, the method includes:
[0015] Obtain the performance metrics size and count threshold of the current trie;
[0016] Based on the magnitude of the performance index, the number of times threshold is adjusted to obtain the adjusted number of times threshold;
[0017] The step of determining whether there exists a node in the trie whose occurrence count is greater than a preset threshold includes:
[0018] Determine whether there exists a node in the trie whose occurrence count is greater than the adjusted threshold.
[0019] Optionally, the step of adjusting the frequency threshold based on the performance index to obtain the adjusted frequency threshold includes:
[0020] Determine whether the magnitude of the performance index meets the preset index conditions;
[0021] If the performance index size does not meet the preset index conditions, an index mapping table is obtained, wherein the index mapping table includes the mapping relationship between the size of each performance index and the corresponding number threshold.
[0022] Based on the index mapping table, the target number threshold for the corresponding performance index is determined, and the number threshold is adjusted to the target number threshold to obtain the adjusted number threshold.
[0023] Optionally, after the step of merging the child nodes of the shared node to obtain a structurally adjusted trie, the method includes:
[0024] Get the string to be inserted;
[0025] The character information of the shared node is matched with the string to be inserted to obtain the matching result;
[0026] If the matching result is successful, the string to be inserted is merged into the shared node to obtain the updated trie.
[0027] Optionally, after the step of merging the string to be inserted into the shared node to obtain the updated trie if the matching result is successful, the method includes:
[0028] If the matching result is a failure, then a child node of the string to be inserted is created in the trie, resulting in an expanded and updated trie.
[0029] Furthermore, to achieve the above objectives, this application also proposes a trie adjustment device, which includes:
[0030] The acquisition module is used to obtain the occurrence count of each node in the current trie after the nodes of the trie are updated;
[0031] The judgment module is used to determine whether there is a node in the trie whose occurrence count is greater than a preset threshold.
[0032] The adjustment module is used to construct a node and at least one of its parent nodes as a shared node of the trie if the number of occurrences of a node exceeds a preset threshold, and to merge the child nodes of the node based on the shared node to obtain a trie with adjusted structure.
[0033] In addition, to achieve the above objectives, this application also proposes a trie adjustment device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the trie adjustment method as described above.
[0034] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the trie adjustment method described above.
[0035] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the trie adjustment method described above.
[0036] One or more technical solutions proposed in this application have at least the following technical effects:
[0037] In contrast to related technologies where a trie is composed of nodes, each containing a character and a mapping to the next level node, and each node independently stores the character, the storage space of the trie increases linearly with the number and length of strings. The structure of independently storing characters leads to significant data redundancy, resulting in low storage efficiency. This application, however, after updating the nodes of the trie, obtains the occurrence count of each node in the current trie; determines whether any node in the trie has an occurrence count greater than a preset threshold; if such a node has an occurrence count greater than the preset threshold, then constructs that node and at least one of its parent nodes as a shared node in the trie, and based on the shared node, merges the child nodes of that node to obtain a structurally adjusted trie. Understandably, this application constructs nodes that appear more than a preset threshold number of times in the trie, along with at least one of their parent nodes, as shared nodes of the trie, and merges the child nodes of these nodes into the shared nodes. This dynamically adjusts the structure of the trie, compressing frequently accessed nodes into shared nodes, thus achieving shared storage of characters rather than independent storage. This improves the space utilization of the trie, reduces the redundancy of character storage in the trie, and enhances the storage efficiency of the trie. Attached Figure Description
[0038] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0039] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 A flowchart illustrating the first embodiment of the method for adjusting the trie in this application;
[0041] Figure 2 This is a schematic diagram of the trie structure for the trie adjustment method of this application;
[0042] Figure 3 A flowchart illustrating the second embodiment of the method for adjusting the trie in this application;
[0043] Figure 4 This is a schematic diagram of the module structure of the dictionary tree adjustment device according to an embodiment of this application;
[0044] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the method for adjusting the trie in this embodiment of the application.
[0045] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0046] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0047] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0048] The main solution of this application embodiment is: when the nodes of the trie are updated, the occurrence count of each node under the current trie is obtained; it is determined whether there is a node in the trie whose occurrence count is greater than a preset threshold; if there is a node whose occurrence count is greater than the preset threshold, then the node and at least one of its parent nodes are constructed as a shared node of the trie, and based on the shared node, the child nodes of the node are structurally merged to obtain a trie with adjusted structure.
[0049] In this embodiment, the dictionary tree adjustment device is the main execution body, and for ease of description, it will be referred to as "device" below.
[0050] In related technologies, trie (prefix tree) is composed of nodes, each containing a character and a mapping to the next level node, with each node storing the character independently. However, as the number and length of strings increase, the storage space of the trie grows linearly. The structure of storing characters independently leads to a large amount of data redundancy, resulting in low storage efficiency for the trie.
[0051] This application provides a solution for dynamically adjusting the trie and improving its storage efficiency.
[0052] As can be seen from the above embodiments, this application constructs nodes that appear more than a preset threshold number of times in the trie and at least one of their parent nodes as shared nodes of the trie, and merges the child nodes of the node into the shared node, thereby dynamically adjusting the structure of the trie. In other words, frequently accessed nodes are compressed into shared nodes, realizing shared storage of characters instead of independent storage of characters, thereby improving the space utilization of the trie, reducing the redundancy of character storage in the trie, and improving the storage efficiency of the trie.
[0053] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or terminal system capable of performing the above functions. The following description uses a dictionary tree adjustment device as an example to illustrate this embodiment and the subsequent embodiments.
[0054] Based on this, embodiments of this application provide a method for adjusting a trie, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the method for adjusting the trie in this application.
[0055] In this embodiment, the method for adjusting the trie includes steps S100 to S300:
[0056] Step S100: After the nodes of the trie are updated, obtain the occurrence count of each node under the current trie;
[0057] It should be noted that, referring to Figure 2 A trie is a tree-like data structure commonly used to store collections of strings. Each node represents a character, and the path from the root node to a node represents a string. Node updates refer to changes in nodes within a trie due to insertion, deletion, or modification operations. For example, inserting a new string into a trie or deleting a string from a trie.
[0058] Understandably, the node occurrence count refers to the number of times the character corresponding to each node appears in all stored strings in the trie. The node occurrence count reflects the frequency of access to that character, and this information is used to optimize storage or improve retrieval efficiency.
[0059] In the actual implementation, after the nodes of the trie are updated, it is necessary to recalculate and record the occurrence count of each node to ensure that these statistics are up-to-date and reflect the latest data status of the trie.
[0060] Step S200: Determine whether there is a node in the trie whose occurrence count is greater than a preset threshold.
[0061] It should be noted that the preset number threshold is a predefined value used to determine whether the number of times a node appears meets the corresponding standard. The number threshold is set based on application requirements or performance optimization considerations.
[0062] In its implementation, the device determines whether any node in the trie has an occurrence count greater than a preset threshold. This process involves traversing the trie or checking related data structures to determine if any node's counter (which records the occurrence count) exceeds the set threshold. Specifically, when constructing the compressed trie, nodes exceeding the threshold are identified as shared nodes to reduce storage redundancy.
[0063] In a specific implementation, before determining whether a node in the trie appears more than a preset threshold number of times, the method includes:
[0064] Obtain the current performance index size and frequency threshold of the trie; adjust the frequency threshold based on the performance index size to obtain the adjusted frequency threshold.
[0065] It should be noted that the performance metrics refer to the size or value of a series of key data points used to measure the performance of the trie. These data reflect the efficiency and effectiveness of the trie in different aspects. Performance metrics include, but are not limited to, storage efficiency, i.e., the memory space occupied by the trie; retrieval efficiency, i.e., the average response time or speed of query operations; insertion and deletion efficiency, i.e., the speed at which entries are added to or deleted from the trie; node depth or width, i.e., the distribution of nodes that affect the length of the retrieval path; and the number of operations threshold, which refers to the preset number of operations currently used for the trie.
[0066] In its implementation, the device dynamically adjusts the number of operations threshold based on collected performance metrics data. This adjustment aims to optimize the performance of the trie, making it more adaptable to current usage and data characteristics. Specific adjustment strategies include, but are not limited to: lowering the number of operations threshold if performance metrics indicate low storage efficiency to reduce redundant node storage and improve storage efficiency; raising the number of operations threshold if retrieval efficiency decreases to merge more shared prefixes, reduce the number of nodes, and thus improve retrieval speed; and adjusting the number of operations threshold based on the efficiency of insertion and deletion operations to balance memory usage and operation speed.
[0067] In practical implementation, after the above adjustment process, the device obtains an adjusted count threshold, which will be used for subsequent trie operations to achieve a better performance balance. That is, the above process is a dynamic optimization process involving monitoring the current trie performance and adjusting the operation parameters (count threshold) based on performance data, aiming to find the optimal balance between different performance metrics, thereby improving the overall performance of the trie.
[0068] In a specific implementation, the step of adjusting the number of times threshold based on the performance index to obtain the adjusted number of times threshold includes:
[0069] Determine whether the size of the performance indicator meets the preset indicator conditions; if the size of the performance indicator does not meet the preset indicator conditions, obtain an indicator mapping table, wherein the indicator mapping table includes the mapping relationship between each performance indicator size and the corresponding number threshold; based on the indicator mapping table, determine the target number threshold for the corresponding performance indicator size, and adjust the number threshold to the target number threshold to obtain the adjusted number threshold.
[0070] In practical implementation, the device first needs to compare the currently measured performance indicators (such as storage efficiency, retrieval efficiency, etc.) with pre-set performance targets or thresholds, where the pre-set indicator conditions correspond to a standard value set for the performance management of the trie. If the current performance indicators fail to meet the pre-set standard, further adjustment measures are required.
[0071] Furthermore, the metric mapping table is a predefined data structure that contains the mapping relationship between different performance metric sizes and their corresponding frequency thresholds. This mapping table serves as a decision support tool, used to select an appropriate frequency threshold based on the current performance metric size. Using the metric mapping table, a target frequency threshold is determined based on the current performance metric size. This target frequency threshold represents the performance optimization goal expected to be achieved by adjusting the frequency threshold. The current node occurrence frequency threshold is adjusted to the target frequency threshold. This adjustment is guided by the performance metric mapping table and aims to make the trie's performance closer to the preset performance metric conditions. After the above adjustments, a new frequency threshold is obtained, which will be used in subsequent trie operations to achieve a better performance balance.
[0072] In a specific implementation, the step of determining whether a node in the trie appears more than a preset threshold number of times further includes:
[0073] Based on the number of occurrences, the device determines whether there are any nodes in the trie that satisfy the adjusted frequency threshold.
[0074] In the specific implementation, after the above adaptive adjustment mechanism based on performance feedback, the performance of the trie is optimized by comparing the actual performance with the preset target, using the mapping table to determine the adjustment direction, and finally adjusting the threshold number of times, so as to keep it efficient and stable under different workloads.
[0075] Step S300: If the number of occurrences of a node is greater than a preset threshold, then the node and at least one of its parent nodes are constructed as a shared node of the trie, and based on the shared node, the child nodes of the node are structurally merged to obtain a trie with adjusted structure.
[0076] In the specific implementation, if a node appears more often than a preset threshold, that is, if the number of times a node appears exceeds the pre-set threshold, then that node is a high-frequency node. The device constructs this high-frequency node and at least one of its parent nodes as a shared node, where a shared node is a node shared by multiple paths in the trie, thus reducing redundant storage.
[0077] In its implementation, based on shared nodes, the device performs structural merging on the child nodes of that node. That is, multiple child nodes with the same subsequent path can be merged into a single path, thereby reducing the number of nodes and optimizing the structure of the trie.
[0078] In the actual implementation, after the above steps, the structure of the trie will change, nodes will be merged, shared nodes will be created, and finally a trie with a more compact structure and higher storage efficiency will be obtained.
[0079] In a specific embodiment, the device records the occurrence count of each node, tracking the frequency of its access. When the occurrence count of a node reaches or exceeds a threshold (e.g., 5 times), the device considers it a high-frequency node. Once the device detects that the occurrence count of a node exceeds the threshold, it begins compressing that node and the structures below it. Specifically, the device merges shared prefixes into a single node and merges all similar structures below it. For example, when multiple strings share the prefix "ap", the device merges the prefix, reducing the storage of redundant nodes.
[0080] In a specific implementation, the step of constructing the node and at least one of its parent nodes as a shared node of the trie includes:
[0081] Obtain the character sequence length of the node; determine whether the character sequence length is less than a preset length threshold; if the character sequence length is less than the preset length threshold, construct the node and the corresponding number of parent nodes of the character sequence length as shared nodes of the trie.
[0082] It should be noted that each node in the trie is usually associated with a character. The character sequence length refers to the total number of characters on the path from the root node to the current node. For example, if the path is "cat", then the character sequence length to the node with "cat" as a suffix is 3. The preset length threshold is a predefined value used to determine whether the node meets the requirements for being constructed as a shared node. Specifically, the length threshold proposed in this application is to avoid the shared prefix being too long and affecting query efficiency. If the prefix length exceeds this limit, the device will retain the first few bits of the prefix, and the remaining part will continue to be allocated to different child nodes.
[0083] In the implementation, if the character sequence length is less than a preset length threshold, then the current node and its parent nodes (the number of which equals the character sequence length) are constructed as a shared node. That is, these nodes are shared by multiple strings in the trie, and therefore can be merged to reduce redundant storage. For example, if the character sequence length is 2, then counting upwards from the current node, these two nodes, along with the current node, will all be constructed as shared nodes.
[0084] In practice, this optimization aims to reduce the total number of nodes in the trie by merging short, shared paths to improve storage efficiency. Creating shared nodes reduces memory usage and can potentially improve query performance because they only need to be stored once. The above process is a character sequence length-based decision mechanism used to determine whether to merge certain nodes into shared nodes to optimize the trie's structure and performance.
[0085] In a specific embodiment, when the device detects that the occurrence frequency of a node exceeds a threshold, it will begin to compress the node and the structure below it. Specifically, it will merge shared prefixes into a single node and merge all similar structures below it. For example, when multiple strings share the prefix 'ap' and the prefix length is less than a length threshold, the device will merge the prefix to reduce the storage of redundant nodes.
[0086] In its implementation, this application effectively compresses storage space and improves space utilization by analyzing and adjusting the trie structure in real time, especially when storing strings with a large number of repeating prefixes. Furthermore, through an adaptive adjustment mechanism, this application can dynamically adjust the trie structure according to the actual data situation, adapting to different storage needs, making it more flexible than a static structure. It also adopts a strategy of dynamically creating nodes on demand, avoiding unnecessary node allocation, reducing memory consumption, and improving runtime efficiency.
[0087] In contrast to related technologies where a trie is composed of nodes, each containing a character and a mapping to the next level node, and each node independently stores the character, the storage space of the trie increases linearly with the number and length of strings. The structure of independently storing characters leads to significant data redundancy, resulting in low storage efficiency. This application, however, after updating the nodes of the trie, obtains the occurrence count of each node in the current trie; determines whether any node in the trie has an occurrence count greater than a preset threshold; if such a node has an occurrence count greater than the preset threshold, then constructs that node and at least one of its parent nodes as a shared node in the trie, and based on the shared node, merges the child nodes of that node to obtain a structurally adjusted trie. Understandably, this application constructs nodes that appear more than a preset threshold number of times in the trie, along with at least one of their parent nodes, as shared nodes of the trie, and merges the child nodes of these nodes into the shared nodes. This dynamically adjusts the structure of the trie, compressing frequently accessed nodes into shared nodes, thus achieving shared storage of characters rather than independent storage. This improves the space utilization of the trie, reduces the redundancy of character storage in the trie, and enhances the storage efficiency of the trie.
[0088] Based on the first embodiment described above, this application also proposes another embodiment, which is referred to below. Figure 3 The method for adjusting the trie includes:
[0089] In a specific implementation, after the device performs structural merging on the child nodes of the shared node to obtain a structurally adjusted trie, the method includes:
[0090] Step A100: Obtain the string to be inserted;
[0091] In the specific implementation, the step of the device obtaining the string to be inserted is the beginning of the insertion operation. The string to be inserted refers to the string to be inserted into the trie, that is, the string is the data item to be added to the trie.
[0092] Step A200: Match the character information of the shared node with the string to be inserted to obtain the matching result;
[0093] In the specific implementation, a shared node refers to a node that is shared by multiple strings. The device compares the characters of the string to be inserted with the character information of the shared node to check whether the prefix of the string to be inserted already exists in the trie.
[0094] Understandably, the matching result may be either a successful match or a failed match, depending on whether the prefix of the string to be inserted matches the path of the shared node.
[0095] Step A300: If the matching result is a successful match, then the string to be inserted is merged into the shared node to obtain the updated trie.
[0096] In the specific implementation, if the matching result is successful, that is, if the prefix of the string to be inserted matches the path of the shared node, it means that this prefix already exists in the trie. In this case, it is not necessary to create a new node to store this common prefix; instead, the remaining part of the string to be inserted (if any) is merged into the shared node.
[0097] For example, if the trie already has "cat" as a shared node, and the string to be inserted is "catalog", then you only need to add "alog" under the "cat" node.
[0098] Step A400: If the matching result is a failure, then create a child node of the string to be inserted in the trie to obtain the expanded and updated trie.
[0099] In the actual implementation, if the prefix of the string to be inserted does not match the path of the shared node, it means that the prefix does not exist in the trie. In this case, a new child node needs to be created for each character of the string to be inserted and added to the trie.
[0100] For example, if the trie already has "cat" as a shared node, and the string to be inserted is "dog", then a "d" node needs to be created under the root node, followed by an "og" node, to form the path of "dog".
[0101] In its implementation, the above process describes two scenarios for inserting strings into a trie: one is when the prefix of the string to be inserted already exists in the trie, allowing for direct merging; the other is when the prefix of the string to be inserted does not exist in the trie, requiring the creation of a new node. This insertion mechanism enables the trie to efficiently store and retrieve string sets while reducing redundant storage.
[0102] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the method of adjusting the dictionary tree of this application. Any simple transformations based on this technical concept are within the protection scope of this application.
[0103] This application also provides a device for adjusting a dictionary tree, please refer to... Figure 4 The trie adjustment device includes:
[0104] The acquisition module 10 is used to acquire the occurrence count of each node in the current trie after the nodes of the trie are updated;
[0105] The judgment module 20 is used to determine whether there is a node in the trie whose occurrence count is greater than a preset threshold.
[0106] The adjustment module 30 is used to construct the node and at least one of its parent nodes as a shared node of the trie if the number of occurrences of a node is greater than a preset threshold, and to perform structural merging on the child nodes of the node based on the shared node to obtain a trie with adjusted structure.
[0107] Optionally, the adjustment module 30 includes:
[0108] The length acquisition module is used to obtain the length of the character sequence of the node;
[0109] The length determination module is used to determine whether the length of the character sequence is less than a preset length threshold;
[0110] A construction module is used to construct the node and a number of parent nodes corresponding to the length of the character sequence as shared nodes of the trie if the length of the character sequence is less than a preset length threshold.
[0111] Optionally, the trie adjustment device further includes:
[0112] The performance metric acquisition module is used to acquire the size and frequency threshold of the performance metrics of the current trie.
[0113] The threshold adjustment module is used to adjust the number of times threshold based on the performance index value to obtain the adjusted number of times threshold.
[0114] Optionally, the determination module 20 further includes:
[0115] The threshold determination module is used to determine whether there is a node in the trie whose occurrence count is greater than the adjusted threshold.
[0116] Optionally, the threshold adjustment module includes:
[0117] The indicator judgment module is used to determine whether the size of the performance indicator meets the preset indicator conditions.
[0118] The mapping table acquisition module is used to acquire an indicator mapping table if the size of the performance indicator does not meet the preset indicator conditions. The indicator mapping table includes the mapping relationship between the size of each performance indicator and the corresponding number threshold.
[0119] The frequency threshold adjustment module is used to determine the target frequency threshold corresponding to the performance index based on the index mapping table, and adjust the frequency threshold to the target frequency threshold to obtain the adjusted frequency threshold.
[0120] Optionally, the trie adjustment device further includes:
[0121] The string retrieval module is used to retrieve the string to be inserted;
[0122] The matching module is used to match the character information of the shared node with the string to be inserted to obtain the matching result;
[0123] The insertion module is used to merge the string to be inserted into the shared node if the matching result is successful, so as to obtain the updated trie.
[0124] Optionally, the trie adjustment device further includes:
[0125] A module is created to generate a child node of the string to be inserted in the trie if the matching result is a failure, thus obtaining an expanded and updated trie.
[0126] The trie adjustment device provided in this application, employing the trie adjustment method described in the above embodiments, can solve the technical problem of trie adjustment. Compared with the prior art, the beneficial effects of the trie adjustment device provided in this application are the same as those of the trie adjustment method provided in the above embodiments, and other technical features in the trie adjustment device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0127] This application provides a trie adjustment device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the trie adjustment method in the first embodiment described above.
[0128] The following is for reference. Figure 5 The diagram illustrates a structural schematic of a device suitable for adjusting a trie in implementing embodiments of this application. The trie adjustment device in embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The illustrated trie adjustment device is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0129] like Figure 5As shown, the dictionary tree adjustment device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the dictionary tree adjustment device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the dictionary tree adjustment device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows dictionary tree adjustment devices with various systems, it should be understood that it is not required to implement or possess all of the systems shown. More or fewer systems may be implemented alternatively.
[0130] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0131] The dictionary tree adjustment device provided in this application, employing the dictionary tree adjustment method described in the above embodiments, can solve the technical problem of dictionary tree adjustment. Compared with the prior art, the beneficial effects of the dictionary tree adjustment device provided in this application are the same as those of the dictionary tree adjustment method provided in the above embodiments, and other technical features of the dictionary tree adjustment device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0132] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0133] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0134] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the trie adjustment method in the above embodiments.
[0135] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0136] The aforementioned computer-readable storage medium may be included in the trie adjustment device; or it may exist independently and not be assembled into the trie adjustment device.
[0137] The aforementioned computer-readable storage medium carries one or more programs that, when executed by the trie adjustment device, cause the trie adjustment device to adjust the trie.
[0138] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0139] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0140] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0141] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described method for adjusting the trie, thereby solving the technical problem of trie adjustment. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the trie adjustment method provided in the above embodiments, and will not be repeated here.
[0142] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described trie adjustment method.
[0143] The computer program product provided in this application can solve the technical problem of adjusting the trie. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as the beneficial effects of the trie adjustment method provided in the above embodiments, and will not be repeated here.
[0144] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for adjusting a trie, characterized in that, The methods for adjusting the trie include: After the nodes of the trie are updated, obtain the occurrence count of each node in the current trie; Determine whether there exists a node in the trie whose occurrence count exceeds a preset threshold. If a node appears more than a preset threshold number of times, then the node and at least one of its parent nodes are constructed as a shared node of the trie, and based on the shared node, the child nodes of the node are structurally merged to obtain a trie with adjusted structure. Prior to the step of determining whether a node in the trie appears more than a preset threshold number of times, the method includes: Obtain the performance metrics size and count threshold of the current trie; Based on the magnitude of the performance index, the number of times threshold is adjusted to obtain the adjusted number of times threshold; The step of determining whether there exists a node in the trie whose occurrence count is greater than a preset threshold includes: Determine whether there exists a node in the trie whose occurrence count is greater than the adjusted threshold.
2. The method for adjusting the trie as described in claim 1, characterized in that, The step of constructing the node and at least one of its parent nodes as a shared node of the trie includes: Get the length of the character sequence for this node; Determine whether the length of the character sequence is less than a preset length threshold; If the length of the character sequence is less than a preset length threshold, then the node and the corresponding number of parent nodes of the character sequence length are constructed as shared nodes of the trie.
3. The method for adjusting the trie as described in claim 1, characterized in that, The step of adjusting the frequency threshold based on the performance index to obtain the adjusted frequency threshold includes: Determine whether the magnitude of the performance index meets the preset index conditions; If the performance index size does not meet the preset index conditions, an index mapping table is obtained, wherein the index mapping table includes the mapping relationship between the size of each performance index and the corresponding number threshold. Based on the index mapping table, the target number threshold for the corresponding performance index is determined, and the number threshold is adjusted to the target number threshold to obtain the adjusted number threshold.
4. The method for adjusting the trie as described in claim 1, characterized in that, After the step of merging the child nodes of the shared node to obtain the structurally adjusted trie, the method includes: Get the string to be inserted; The character information of the shared node is matched with the string to be inserted to obtain the matching result; If the matching result is successful, the string to be inserted is merged into the shared node to obtain the updated trie.
5. The method for adjusting the trie as described in claim 4, characterized in that, After the step of merging the string to be inserted into the shared node to obtain the updated trie if the matching result is successful, the method includes: If the matching result is a failure, then a child node of the string to be inserted is created in the trie, resulting in an expanded and updated trie.
6. A device for adjusting a trie, characterized in that, The device includes: The acquisition module is used to obtain the occurrence count of each node in the current trie after the nodes of the trie are updated; The judgment module is used to determine whether there is a node in the trie whose occurrence count is greater than a preset threshold. The adjustment module is used to construct a node and at least one of its parent nodes as a shared node of the trie if the number of occurrences of a node exceeds a preset threshold, and to perform structural merging on the child nodes of the node based on the shared node to obtain a trie with adjusted structure. The performance metric acquisition module is used to acquire the size and frequency threshold of the performance metrics of the current trie. The threshold adjustment module is used to adjust the number of times threshold based on the performance index value to obtain the adjusted number of times threshold. The judgment module further includes: The threshold determination module is used to determine whether there is a node in the trie whose occurrence count is greater than the adjusted threshold.
7. A device for adjusting a trie, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the method for adjusting the trie as described in any one of claims 1 to 5.
8. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the trie adjustment method as described in any one of claims 1 to 5.
9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the trie adjustment method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Log compression and decompression method and device, electronic equipment and storage medium
CN116471336A