Character string encoding method, configuration method, device, medium, and program product

By using a trie with enhanced statistical values ​​to automatically configure compression code, the problem of high memory and time overhead in string compression in existing technologies is solved, achieving more efficient string encoding and storage.

WO2025248336A1PCT designated stage Publication Date: 2025-12-04CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/IB2025/053737
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-05-27
Filing Date
2025-04-09
Publication Date
2025-12-04

AI Technical Summary

Technical Problem

Existing technologies suffer from significant memory and time consumption during string compression, especially in database systems, where existing string encoding methods require substantial time and memory to identify shared prefixes and statistical information.

Method used

By employing a trie with enhanced statistics, compression codes are automatically configured to reduce memory and time overhead by identifying shared prefixes and usage frequencies of strings.

Benefits of technology

By using a trie, the memory usage and time overhead in the string encoding process can be reduced efficiently, thus optimizing the efficiency of string compression.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2025053737_04122025_PF_FP_ABST
    Figure IB2025053737_04122025_PF_FP_ABST
Patent Text Reader

Abstract

The present disclosure provides a character string encoding method, a configuration method, a device, a medium, and a program product. The character string encoding method comprises: determining, among a plurality of candidate character string nodes of a target dictionary tree, a specified character string node corresponding to a character string to be encoded, each candidate character string node being pre-configured with a character string usage frequency and a compression code that is determined on the basis of the character string usage frequency thereof; and on the basis of the compression code corresponding to the specified character string node, encoding the character string to be encoded. According to the technical solution of the present disclosure, memory occupation and time overhead during character string encoding can be reduced by using the dictionary tree having enhanced statistical values as a data structure.
Need to check novelty before this filing date? Find Prior Art

Description

[0001]Encoding method, configuration method, device, medium and program product of string technical field The present disclosure relates to the technical field of computers, and in particular to an encoding method of a string, a configuration method of a dictionary tree, an electronic device, a computer-readable storage medium and a computer program product. Background art String compression technology involves compressing strings into codes and is widely used in the fields of data storage and data transmission. For example, in a database system, string compression can reduce the demand for storage space and improve storage efficiency, especially when storing a large amount of text data (such as log files, historical records and documents); string compression is also often used in file systems to reduce disk space occupation. Also, when transmitting data over a network, compressing data can reduce the amount of data transmitted, increase transmission speed and reduce bandwidth consumption. With the continuous growth of data volume, compression technology will continue to be a key component in the field of computer science and information technology. Therefore, it is important to optimize string compression technology. Content The present disclosure provides an encoding method of a string, a configuration method of a dictionary tree, an electronic device, a computer-readable storage medium and a computer program product to alleviate or solve one or more technical problems in the prior art. In a first aspect, the present disclosure provides an encoding method of a string, comprising: determining a specified string node corresponding to a to-be-encoded string from a plurality of candidate string nodes of a target dictionary tree; wherein the candidate string nodes are pre-configured with a string usage frequency and a compression code determined based on the string usage frequency; and encoding the to-be-encoded string according to the compression code corresponding to the specified string node. In a second aspect, the present disclosure provides a configuration method of a dictionary tree, comprising: obtaining a string usage frequency corresponding to a candidate string node of a target dictionary tree; and configuring a corresponding compression code for the candidate string node according to the string usage frequency corresponding to the candidate string node, so as to encode the string represented by the candidate string node into the corresponding compression code. In a third aspect, the present disclosure provides an electronic device, comprising a memory, a processor and a computer program stored in the memory, wherein the processor implements the method of any one of the present disclosure when executing the computer program. In a fourth aspect, the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method of any one of the present disclosure. In a fifth aspect, the present disclosure provides a computer program product, comprising a computer program, wherein the computer program is executed by a processor to implement the method of any one of the present disclosure.The technical scheme of the present disclosure adopts an enhanced statistical value dictionary tree (target dictionary tree), each string node corresponds to an attribute value, the attribute value represents the string usage frequency of the corresponding string node, and further, each string node is configured with a compression code set based on the string usage frequency. In a string compression scenario, if the string corresponding to the candidate string node is queried in the target dictionary tree, the string is encoded as the compression code corresponding to the candidate string node to reduce memory and disk space occupation. Since the target dictionary tree naturally has the ability to identify the shared prefix of the string and the string usage frequency, the string usage frequency corresponding to each candidate string node can be automatically obtained based on this, and the corresponding compression code is configured, so that the memory occupation and time overhead of the string encoding process can be reduced. The above description is only a summary of the technical scheme of the present disclosure, in order to more clearly understand the technical means of the present disclosure, the contents of the specification can be implemented, and in order to make the above and other purposes, features and advantages of the present disclosure more obvious and easy to understand, the specific embodiments of the present disclosure are described below. BRIEF DESCRIPTION OF DRAWINGS In the drawings, unless otherwise specified, the same reference numerals throughout the drawings represent the same or similar components or elements. The drawings are not necessarily drawn to scale. It should be understood that the drawings merely depict some embodiments in accordance with the present disclosure and should not be considered limiting of the scope of the present disclosure. FIG. 1 shows an example diagram of a dictionary tree; FIG. 2 shows an example diagram of an enhanced statistical value dictionary tree used in an embodiment of the present disclosure; FIG. 3 is an architectural schematic diagram of an exemplary system provided by an embodiment of the present disclosure; FIG. 4 shows a flowchart of a configuration method of a dictionary tree according to an embodiment of the present disclosure; FIG. 5 shows a flowchart of an encoding method of a string according to an embodiment of the present disclosure; and FIG. 6 is a block diagram of an electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION In the following, only some exemplary embodiments are simply described. As those skilled in the art can recognize, the described embodiments can be modified in various different ways without departing from the concept or scope of the present disclosure. Therefore, the drawings and the description are considered to be exemplary in nature rather than limiting. In order to facilitate understanding of the technical scheme of the embodiments of the present disclosure, the related technologies of the embodiments of the present disclosure are described below. The following related technologies are optional solutions that can be combined with the technical scheme of the embodiments of the present disclosure, and all belong to the protection scope of the embodiments of the present disclosure. A string (String) is a data type composed of a sequence of characters. A string can include letters, numbers, spaces, punctuation marks, and other printable or non-printable characters.It should be noted that the "string" in the embodiments of the present disclosure should be understood in a broad sense, that is, a string can include multiple characters or a single character. String compression technology involves compressing a string into a more compact form and is widely used in the field of data storage and data transmission. From the technical field, string compression technology can be applied to scenarios where string encoding is required. The encoding (compression) of a string refers to converting a string into a more compact data to reduce the space it occupies. For example, a simple string encoding algorithm can identify a string and use a shorter code to represent the string. In a database system, it is necessary to collect the use data of the string, so as to find the frequently occurring string and convert it into a short compressed code, that is, the encoding of the string. In an implementation manner, all possible prefixes are identified by traversing the string one by one. Then, all possible prefixes are inserted into a key-value data structure, where the key represents the prefix and the value represents the statistical information, and then the string is encoded based on the mapping. This implementation manner requires two steps of operation, that is, generating a prefix and collecting statistical information, which will consume a lot of time, and for all possible prefixes (not just shared prefixes), statistical information needs to be collected, which will consume a lot of memory. In order to reduce the memory occupation and time consumption of the string encoding process, in the technical solution of the present disclosure, an enhanced statistical value dictionary tree is used as a data structure. The dictionary tree is a type of search tree, also known as a prefix tree, and its data structure is defined as a tree-shaped data structure for searching from a specific set of keys, which are usually strings. If two strings have a shared prefix, they have a common parent node in the dictionary tree. This data structure directly uses the numerical representation of the key, rather than hashing or comparing the key. The basic idea is similar to the thumb index in many alphabetically ordered dictionary books: the first character of a word can be used to jump directly to all words starting with that character, so it is called a dictionary tree. FIG. 1 shows an example diagram of a dictionary tree. As shown in FIG. 1, the dictionary tree has a root node (root), which can be used to identify the dictionary tree, so the root node can represent a string or not. In the dictionary tree, each node is composed of a hash mapping or a pointer array, which is used to represent a character or a string, such as "t", "te", "tea", "ten", "i", "in", and "inn".Each edge represents a character as an index, such as the character "i" between the root node and the node "i", the character "e" between the node "t" and the node "te", the character "n" between the node "in" and the node "inn", and the like. Exemplarily, the trie can also be configured with a flag indicating whether a string ends at the current node. Thus, in the data structure of the trie shown in FIG. 1, any number of strings including letters, numbers, and special characters can be contained. FIG. 2 shows an example diagram of an enhanced statistical value trie employed by an embodiment of the present disclosure. As shown in FIG. 2, the trie has a root node (root) and other nodes. The nodes are used to represent a string, such as "te", "tea", "ted", "ten", "teach", "inn", which is called a string node. Among them, the leaf nodes have no child nodes, such as "ted", "ten", "teach", "inn". There is one or more intermediate nodes on the path from the root node to the leaf node, such as "te", "tea". Both the leaf nodes and the intermediate nodes are string nodes, which are used to represent a string. The intermediate nodes are shared string prefixes of their child nodes, such as the intermediate nodes "te", "tea". Each edge represents a character as an index, such as the character "a" between the node "te" and the node "tea", the character "c" between the node "tea" and the node "teach", and the like. Further, in the trie shown in FIG. 2, each string node corresponds to an attribute value, which represents the string usage frequency (represented by a number in FIG. 2) of the corresponding string node, that is, both the leaf nodes and the intermediate nodes correspond to a string usage frequency. Exemplarily, by scanning 2 "tea", 2 "teach", 4 "ted", 3 "ten", and 5 "inn", the enhanced trie shown in FIG. 2 is generated, which can automatically identify shared prefixes and string usage frequencies. Exemplarily, the trie of the data structure supports insertion, search, and deletion operations, including the implementation of the longest shared prefix, pattern search. When a string is inserted into the trie, it traverses all nodes with shared prefixes. If the string has a different prefix, it generates a new node for the new shared prefix. Each intermediate node with only one child node will be merged with its parent node, and an intermediate node will only be created when at least two leaf nodes need to be distinguished.As shown in FIG. 2, when a string with a string usage frequency is inserted, the traversal starts from the root node. When a shared prefix (i.e., an intermediate node) is found in the path, the string usage frequency of the string is aggregated into the string usage frequency of the parent node. As the string is inserted, a new path can be added to the trie. The intermediate node of the new path will have the string usage frequency of the inserted string as its string usage frequency. The newly added leaf node will also have the string usage frequency of the inserted string. When a string is deleted, the string usage frequency of the string is subtracted from the string usage frequencies of all the ancestor nodes of the string. Therefore, the data structure of the trie shown in FIG. 2 naturally has the ability to identify shared prefixes of strings and the string usage frequencies. Based on the trie shown in FIG. 2, the string usage frequencies can be automatically obtained, so that the corresponding compression codes of the string nodes can be preconfigured according to the string usage frequencies of the string nodes, for encoding the strings. FIG. 3 is a schematic architecture diagram of an exemplary system provided in an embodiment of the present disclosure. As shown in FIG. 3, the system includes a storage device, a database client, and a database server. The storage device is hardware for persistently storing data, i.e., storing persistent data. In an embodiment, the database client sends a string encoding request to the database server, the database server responds to the encoding request, determines a specified string node corresponding to a to-be-encoded string from a plurality of candidate string nodes of a target trie (e.g., the trie shown in FIG. 2), and then encodes the to-be-encoded string according to the compression code corresponding to the specified string node, thereby converting the to-be-encoded string into its corresponding compression code. In another embodiment, the database client sends a configuration request of a trie to the database server, the database server responds to the configuration request, generates a target trie, and obtains the string usage frequencies corresponding to the candidate string nodes of the target trie, respectively, and configures the compression codes corresponding to the candidate string nodes, respectively. It should be noted that the above application scenarios or application examples provided in the embodiments of the present disclosure are for the convenience of understanding, and the application of the string encoding method and the configuration method of the trie provided in the embodiments of the present disclosure is not limited specifically. In addition, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present disclosure are all information and data authorized by the user or authorized by all parties, and the collection, use, and processing of the related data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions, and provide corresponding operation portals for the user to select or edit authorization or rejection.The encoding method of the string and the configuration method of the dictionary tree are described in detail below with specific embodiments. The specific embodiments listed can be combined with each other, and the same or similar concepts or processes can not be described again in some embodiments. To facilitate understanding, the configuration method of the dictionary tree provided by the embodiments of the present disclosure is described in detail first. FIG. 4 shows a flowchart of the configuration method of the dictionary tree according to the embodiments of the present disclosure, which can be applied to a database system, for example, executed by a database server. As shown in FIG. 4, the method can include steps S401 and S402. Step S401: Obtain the string usage frequency corresponding to the candidate string node of the target dictionary tree. The target dictionary tree can be a dictionary tree enhanced with statistical values. For example, as shown in FIG. 2, the leaf nodes and the intermediate nodes are all candidate string nodes, which are used to represent strings, and the intermediate nodes are shared string prefixes of their child nodes. Each candidate string node is pre-configured with an attribute value representing the string usage frequency thereof, that is, both the leaf nodes and the intermediate nodes correspond to a string usage frequency. Therefore, using the data structure shown in FIG. 2 as the target dictionary tree naturally has the ability to identify the shared prefix of the string and the string usage frequency. Based on the target dictionary tree, the string usage frequency of each candidate string can be automatically obtained. Step S402: Configure the corresponding compression code for the candidate string node according to the string usage frequency corresponding to the candidate string node. In one example, the corresponding compression code can be configured for any candidate string node in the target dictionary tree, and the compression code can be taken as the attribute value or the mapping value of the candidate string node. By scanning the target dictionary tree, the compression code corresponding to any candidate string node in the target dictionary tree can be obtained. Further, the corresponding compression code can be configured for the candidate string node according to the string usage frequency corresponding to the candidate string node. For example, a plurality of compression codes for selection can be preset, and if the string usage frequency of the candidate string node belongs to a certain frequency range, one of the plurality of compression codes is selected as the compression code corresponding to the candidate string node. For another example, a plurality of groups of compression codes for selection can be preset, and each group of compression codes has different lengths. Meanwhile, a plurality of frequency ranges are preset, and the greater the usage frequency corresponding to the frequency range, the shorter the length of the compression code corresponding to the frequency range. If the string usage frequency of the candidate string node belongs to a certain frequency range, one of the compression codes in the group corresponding to the frequency range is selected as the compression code corresponding to the candidate string node.In yet another example, the first N (N is an integer greater than 1) candidate string nodes corresponding to the string usage frequency can be selected according to the string usage frequency corresponding to each candidate string node of the target dictionary tree, and the corresponding compression codes are configured for the candidate string nodes respectively. In the embodiment of the present disclosure, the target dictionary tree has the ability to identify the shared prefix of the string and the string usage frequency, based on which the string usage frequency corresponding to each candidate string node can be automatically obtained, and the corresponding compression code is configured, so that the memory occupation and time consumption of the string coding process can be reduced. In an implementation, the compression code length corresponding to the candidate string node is negatively correlated with the string usage frequency corresponding to the candidate string node. In a database system, the usage data of the string needs to be collected, so that the frequently used string is found and converted into a short compression code, thereby reducing the memory occupation. Therefore, the higher the string usage frequency is, the shorter the compression code length configured is, for example, for the string node "ted" with high string usage frequency, a compression code with a short length (for example, 1) is selected, thereby further reducing the memory occupation. Exemplarily, a plurality of groups of compression codes for selection can be preset, and the lengths of the compression codes in each group are different; meanwhile, a plurality of frequency ranges are preset, and the greater the usage frequency corresponding to the frequency range is, the shorter the length of the compression code in the corresponding group is, if the string usage frequency of the candidate string node belongs to a certain frequency range, a compression code in the group corresponding to the frequency range is selected as the compression code corresponding to the candidate string node, thereby realizing the negative correlation between the compression code length corresponding to the candidate string node and the string usage frequency corresponding to the candidate string node. Alternatively, for two candidate string nodes, the string usage frequency of node 1 is higher than that of node 2, and the length of the compression code corresponding to node 1 is shorter than that of the compression code corresponding to node 2. In a database system, the dictionary tree used for string compression usually exists in a database page (page), which occupies memory and disk space, that is, the compression code also occupies a certain memory and disk space, therefore, the string usage frequency, the string length and the compression code length need to be considered comprehensively to determine which strings need to be compressed. In an implementation, an initial dictionary tree can be constructed first, then the strings that need to be compressed are determined, and the corresponding string nodes are retained to generate a target dictionary tree.Specifically, the method of the embodiments of the present disclosure can further include: for the plurality of initial string nodes of the initial dictionary tree, in the order from the leaf node to the root node, determining whether to retain the initial string node in the initial dictionary tree according to the string usage frequency, the string length and the compression code length of the string corresponding to the initial string node, to generate the target dictionary tree. Since the target dictionary tree is obtained by retaining some string nodes of the initial dictionary tree, the initial dictionary tree has the same data structure as the target dictionary tree, i.e., the same data structure as the dictionary tree shown in FIG. 2. Specifically, the initial dictionary tree includes the root node, the leaf node and the intermediate node on the path from the root node to the leaf node, the initial string node is the leaf node and the intermediate node, the intermediate node is the shared string prefix of its child nodes, and each initial string node is pre-configured with the string usage frequency, for example, the attribute value of each initial string node includes the corresponding string usage frequency. In an implementation, the compression code length corresponding to the initial string node is randomly allocated, i.e., each initial string node is pre-configured with the corresponding compression code, which can be randomly allocated. For example, the compression code length corresponding to the initial string node can be preset to 10 in another implementation, the compression code length corresponding to the initial string node is estimated based on the string usage frequency of the initial string node. For example, the initial dictionary tree can be traversed, and then the compression code length of the initial string node is estimated according to the string usage frequency of the initial string node. Although the estimation based on the string usage frequency is time-consuming, it is more accurate, and the random allocation is fast but less accurate. Therefore, the actual requirements can be selected, for example, if high efficiency is required, the random allocation can be selected, and if high compression rate is required, the estimation based on the string usage frequency can be selected. In an implementation, the determination of whether to retain the initial string node in the initial dictionary tree according to the string usage frequency, the string length and the compression code length of the string corresponding to the initial string node can include: calculating the cost and benefit of the current string node occupying the storage space according to the string usage frequency, the string length and the compression code length of the string corresponding to the current string node, and determining whether to retain the current string node in the initial dictionary tree based on the cost and benefit of the current string node; and in response to retaining the current string node in the initial dictionary tree, updating the string usage frequency of the parent node of the current string node.To determine whether to keep a string node, its cost and benefit need to be calculated. If the cost is greater than the benefit, the string node needs to be pruned (deleted) from the initial trie. Exemplarily, the cost of an initial string node can be calculated as: cost = string length + compression code length, and its benefit can be calculated as: benefit = (string length - compression code length) * string frequency. Further, since a parent node is a prefix of its children, when a string node is kept, the string corresponding to the string node will be encoded into a corresponding compression code in the string compression process, and thus the string frequency of the parent node is actually reduced. For example, assuming the string represented by a parent node is "tea", and the string represented by a child node is "teach", if the child node "teach" is kept and assigned a short compression code, the short compression code will be used every time "teach" appears, instead of "tea" + "ch". oIn the case where the "teach" node is not reserved, each use of "teach" actually increases the frequency of use of "tea". However, once the "teach" node is reserved, the frequency of use of "tea" no longer includes the frequency of use of "teach". Therefore, when a string node is reserved, the frequency of use of the string of the string node needs to be subtracted from the frequency of use of the string of the parent node of the string node, so as to accurately calculate the actual frequency of use of each string, so as to improve the accuracy of the configuration of the compression code and improve the compression rate. In an embodiment, according to the frequency of use of the string corresponding to the current string node, the string length and the compression code length, the cost value and the benefit value of the current string node occupying the storage space are calculated, and whether the current string node is reserved in the initial dictionary tree is determined based on the cost value and the benefit value of the current string node, including: according to the frequency of use of the string corresponding to the current string node, the string length and the compression code length, the cost value and the initial benefit value of the current string node are calculated; in the case where the cost value is less than the initial benefit value, the target benefit value of the current string node is determined according to the initial benefit value and the lost benefit value of the parent node of the current string node; wherein the lost benefit value is calculated based on the string length of the parent node and the frequency of use of the string corresponding to the current string node; in response to the target benefit value being greater than a preset threshold, the current string node is reserved in the initial dictionary tree. Exemplarily, first consider the first layer filtering (Filterl), calculate the cost value (cost) and the initial benefit value (benefitl) of the current string node, cost = the string length of the current string node + the compression code length of the current string node, benefit 1= (the string length of the current string node - the compression code length of the current string node) * the frequency of use of the string of the current string node, if the cost value (cost) is less than the initial benefit value (benefitl), then enter the second layer filtering (Filter2). In the second layer filtering, the lost benefit value (benefit lost) caused by reserving the current string node to the parent node needs to be considered, which is because the parent node is the prefix of its child node, therefore, if the current string node is reserved, then in the string compression process, the string corresponding to the string node will be encoded into the corresponding compression code, therefore, the frequency of use of the string of the parent node is actually reduced. Exemplarily, the lost benefit value (benefit lost) of the parent node can be calculated as follows: benefit lost = the string length of the parent node * the frequency of use of the string of the current string node.Further, a net benefit, i.e., a target benefit value (benefit2) is calculated: benefit2 = benefitl - benefit lost Further, if the target benefit value (benefit2) is greater than a preset threshold value, the current string node is reserved. The preset threshold value represents a minimum net benefit required for reserving the node. This rule ensures that a node is reserved only when the space saving brought by the reserved node (even when the benefit loss of the parent node is considered) is large enough. This method balances the compression efficiency and the necessity of reserving a string, thereby optimizing the compression strategy of the entire trie. In the embodiments of the present disclosure, the target trie is used for string compression, that is, the strings appearing in the target trie are encoded into corresponding compression codes. Therefore, whether to reserve an initial string node in the target trie, i.e., whether to compress the string corresponding to the string node when the string appears, is considered. Since the parent node is the prefix of its child nodes, the value and the benefit of the node need to be considered as a whole. Further, after the target trie is generated, for each candidate string node of the target trie, a corresponding compression code is configured for the candidate string node based on the frequency of use of the string corresponding to the candidate string node. Specifically, the length of the compression code corresponding to the candidate string node is negatively correlated with the frequency of use of the string corresponding to the candidate string node. Furthermore, in the string compression scenario, if the string corresponding to the candidate string node is queried in the target trie, the string is encoded into the compression code corresponding to the candidate string node, so as to reduce the memory and disk space occupancy. FIG. 5 shows a flowchart of a string encoding method according to an embodiment of the present disclosure. The method can be applied to a database system, for example, executed by a database server. As shown in FIG. 5, the method can include steps S501 and S502. Step S501: From a plurality of candidate string nodes of a target trie, a specified string node corresponding to a to-be-encoded string is determined; wherein the candidate string nodes are pre-configured with a string use frequency and a compression code determined based on the string use frequency. Step S502: The to-be-encoded string is encoded according to the compression code corresponding to the specified string node.Corresponding to the application scenario and the string encoding method provided by the embodiments of the present disclosure, the embodiments of the present disclosure further provide a string encoding apparatus. The apparatus can be applied to a database system, for example, deployed on a database server. The apparatus can include: a specified string node determining component configured to determine a specified string node corresponding to a to-be-encoded string from a plurality of candidate string nodes of a target dictionary tree; wherein the candidate string nodes are pre-configured with a string usage frequency and a compression code determined based on the string usage frequency; and an encoding component configured to encode the to-be-encoded string according to the compression code corresponding to the specified string node. In an embodiment, the apparatus further includes a compression code configuring component configured to: obtain the string usage frequency corresponding to each candidate string node; and configure the compression code corresponding to each candidate string node according to the string usage frequency corresponding to each candidate string node; wherein the length of the compression code corresponding to the candidate string node is negatively correlated with the string usage frequency corresponding to the candidate string node. In an embodiment, the apparatus further includes a target dictionary tree generating component configured to, for a plurality of initial string nodes of an initial dictionary tree, in the order from a leaf node to a root node, determine whether to retain the initial string node in the initial dictionary tree according to the string usage frequency, the string length, and the compression code length of the initial string node, to generate the target dictionary tree. In an embodiment, the length of the compression code corresponding to the initial string node is randomly allocated or estimated based on the string usage frequency of the initial string node. In an embodiment, the target dictionary tree generating component is further configured to: calculate the cost value and the benefit value of the storage space occupied by the current string node according to the string usage frequency, the string length, and the compression code length of the current string node, and determine whether to retain the current string node in the initial dictionary tree based on the cost value and the benefit value of the current string node; and in response to retaining the current string node in the initial dictionary tree, update the string usage frequency of the parent node of the current string node.In an embodiment, the target dictionary tree generating component is further configured to: calculate a generation value and an initial income value of the current string node according to the string use frequency corresponding to the current string node, the string length, and the compression code length; in a case where the generation value is less than the initial income value, determine a target income value of the current string node according to the initial income value and a loss income value of a parent node of the current string node, wherein the loss income value is calculated based on the string length of the parent node and the string use frequency corresponding to the current string node; and in response to the target income value being greater than a preset threshold, retain the current string node in the initial dictionary tree. In an embodiment, the target dictionary tree includes a root node, a leaf node, and an intermediate node on a path from the root node to the leaf node, the candidate string node is the leaf node and the intermediate node, and the intermediate node is a shared string prefix of its child nodes. Corresponding to the application scenario and the dictionary tree configuration method provided by the embodiments of the present disclosure, the embodiments of the present disclosure further provide a dictionary tree configuration apparatus, which can be applied to a database system, for example, deployed on a database server. The apparatus can include: a string use frequency obtaining component configured to obtain a string use frequency corresponding to a candidate string node of a target dictionary tree; and a compression code configuring component configured to configure a compression code corresponding to the candidate string node for the candidate string node according to the string use frequency corresponding to the candidate string node, so as to encode a string represented by the candidate string node into the compression code corresponding to the candidate string node. In an embodiment, the compression code length corresponding to the candidate string node is negatively correlated with the string use frequency corresponding to the candidate string node. The functions of the components in the apparatuses of the embodiments of the present disclosure can be referred to the corresponding descriptions in the above methods, and have corresponding beneficial effects, which are not described here again. FIG. 6 is a block diagram of an electronic device for implementing the embodiments of the present disclosure. As shown in FIG. 6, the electronic device includes a memory 601 and a processor 602, and the memory 601 stores a computer program capable of running on the processor 602. The processor 602 implements the method in the above embodiments when executing the computer program. The number of the memory 601 and the processor 602 can be one or more. The electronic device further includes a communication interface 603 configured to communicate with external devices and perform data transmission. If the memory 601, the processor 602, and the communication interface 603 are independently implemented, the memory 601, the processor 602, and the communication interface 603 can be connected with each other through a bus and complete communication among them.The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in FIG. 6, but it does not mean that there is only one bus or only one type of bus. Alternatively, in a specific implementation, if the memory 601, the processor 602, and the communication interface 603 are integrated on a chip, the memory 601, the processor 602, and the communication interface 603 can complete communication with each other through an internal interface. The embodiment of the present disclosure provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method provided in the embodiment of the present disclosure. The embodiment of the present disclosure provides a computer program product, which includes a computer program, and the computer program is executed by a processor to implement the method provided in the embodiment of the present disclosure. The embodiment of the present disclosure further provides a chip, which includes a processor configured to call and run instructions stored in a memory, so that a communication device installed with the chip executes the method provided in the embodiment of the present disclosure. The embodiment of the present disclosure further provides a chip, which includes an input interface, an output interface, a processor, and a memory, and the input interface, the output interface, the processor, and the memory are connected through an internal connection path. The processor is used to execute the code in the memory, and when the code is executed, the processor is used to execute the method provided in the embodiment. It should be understood that the above processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), FPGAs or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc. It should be noted that the processor can be a processor supporting an advanced RISC machine (ARM) architecture. Further, alternatively, the above memory can include a read-only memory and a random access memory.The memory can be a volatile memory or a nonvolatile memory, or can include both volatile and nonvolatile memory. The nonvolatile memory can include Read-Only Memory (ROM), Programmable ROM (PROM), Erasable PROM (EPROM), Electrically EPROM (EEPROM), or flash memory. The volatile memory can include Random Access Memory (RAM), which functions as the external cache. Many forms of RAM are available, including, by way of example and not limitation, Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Sync link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM). In the above embodiments, all or some can be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or some can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed by a computer, the computer program instructions cause the processes or functions according to the present disclosure to be performed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable apparatus. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. In the description of the specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present disclosure.Moreover, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Furthermore, the described embodiments or examples and features of the described embodiments or examples can be combined and / or combined in any suitable manner without departing from the scope of the present disclosure. Furthermore, the terms "first", "second" are used only for descriptive purposes and cannot be construed as indicating or implying relative importance or an indicated number of technical features. Therefore, the features defined as "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "a plurality of" is two or more, unless otherwise specifically limited. Any process or method described in the flowchart or otherwise described herein can be understood as a module, segment, or portion of code containing executable instructions for implementing specific logical functions or steps. Moreover, the scope of the preferred embodiments of the present disclosure includes additional implementations in which the functions can be performed in an order different from that shown or discussed, including functions performed in substantially simultaneous fashion or in reverse order, according to the functions involved. The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as a list of executable instructions for implementing the logic function, which can be specifically embodied in any computer-readable medium for use by an instruction execution system, device, or apparatus, such as a computer-based system, a system including a processor, or other system that can fetch instructions from the instruction execution system, device, or apparatus and execute the instructions. It should be understood that parts of the present disclosure can be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above-described embodiment methods can be instructed by a program to complete the relevant hardware, which can be stored in a computer-readable storage medium. The program, when executed, includes one or a combination of the steps of the method embodiments. Furthermore, the functional units in the various embodiments of the present disclosure can be integrated in one processing module, or each unit can be physically present separately, or two or more units can be integrated in one module. The above-mentioned integrated module can be realized in the form of hardware or in the form of a software function module. The above-mentioned integrated module, if realized in the form of a software function module and sold or used as an independent product, can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a magnetic disk or an optical disk, etc.The above merely illustrates exemplary embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto, any skilled person in the art can easily think of various changes or replacements within the technical scope of the present disclosure, which should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims. The technical scheme of the present embodiment adopts an enhanced statistical value dictionary tree (target dictionary tree), each string node corresponds to an attribute value, the attribute value represents the string use frequency of the corresponding string node, further, each string node is further configured with a compression code set based on the string use frequency thereof, in a string compression scene, if the string corresponding to the candidate string node is queried in the target dictionary tree, the string is encoded as the compression code corresponding to the candidate string node, so as to reduce the memory and disk space occupation. Since the target dictionary tree naturally has the ability to identify the shared prefix of the string and the string use frequency, based thereon, the string use frequency corresponding to each candidate string node can be automatically acquired, and the corresponding compression code is configured, so that the memory occupation and time consumption of the string encoding process can be reduced.

Claims

Claims 1. A string encoding method, comprising: From multiple candidate string nodes in the target trie, a specified string node corresponding to the string to be encoded is determined; wherein, the candidate string node is pre-configured with string usage frequency and compression code determined based on its string usage frequency; the string to be encoded is encoded according to the compression code corresponding to the specified string node.

2. The method according to claim 1, wherein, The method further includes: obtaining the string usage frequency corresponding to each candidate string node; configuring corresponding compression code for each candidate string node according to the string usage frequency corresponding to each candidate string node; wherein, the length of the compression code corresponding to the candidate string node is negatively correlated with the string usage frequency corresponding to the candidate string node.

3. The method according to claim 2, wherein, Based on the string usage frequency corresponding to each candidate string node, a corresponding compression code is configured for each candidate string node, including: setting multiple preset frequency ranges and multiple sets of compression codes, wherein the multiple preset frequency ranges correspond one-to-one with the multiple sets of compression codes; determining the target frequency range in which the string usage frequency corresponding to different candidate string nodes falls from the multiple preset frequency ranges; determining the target compression code group corresponding to the target frequency range from the multiple sets of compression codes; and selecting the target compression code from the target compression code group to obtain the compression code corresponding to the candidate string node.

4. The method according to claim 1, wherein, The method further includes: for multiple initial string nodes of the initial trie, determining whether to retain the initial string node in the initial trie according to the string usage frequency, string length and compressed code length corresponding to the initial string node in the order from leaf node to root node, so as to generate the target trie.

5. The method according to claim 4, wherein, The length of the compressed code corresponding to the initial string node is randomly assigned or estimated based on the frequency of string usage of the initial string node.

6. The method according to claim 4, wherein, The process involves determining whether to retain the initial string node in the initial trie based on the string usage frequency, string length, and compressed code length corresponding to the initial string node. This includes: calculating the cost and benefit value of the storage space occupied by the current string node based on the string usage frequency, string length, and compressed code length corresponding to the current string node; and determining whether to retain the current string node in the initial trie based on the cost and benefit value of the current string node. In response to retaining the current string node in the initial trie, the string usage frequency of the parent node of the current string node is updated.

7. The method according to claim 6, wherein, Based on the frequency of string usage corresponding to the current string node, The process involves calculating the cost and benefit of the storage space occupied by the current string node based on its string length and compressed code length. Then, based on these values, it determines whether to retain the current string node in the initial trie. This includes: calculating the cost and initial benefit of the current string node based on its string usage frequency, string length, and compressed code length; if the cost is less than the initial benefit, determining the target benefit of the current string node based on the initial benefit and the loss benefit of its parent node; wherein the loss benefit is calculated based on the string length of the parent node and the string usage frequency of the current string node; and retaining the current string node in the initial trie if the target benefit is greater than a preset threshold.

8. The method according to claim 7, wherein, Based on the string usage frequency, string length, and compressed code length corresponding to the current string node, calculate the cost value and initial benefit value of the current string node, including: obtaining the cost value of the current string node based on the sum of the string length and the compressed code length corresponding to the current string node; obtaining a first difference value based on the difference between the string length and the compressed code length corresponding to the current string node; and obtaining the initial benefit value of the current string node based on the product of the first difference and the string usage frequency corresponding to the current string node.

9. The method according to any one of claims 1 to 7, wherein, The target trie includes a root node, leaf nodes, and intermediate nodes located on the path from the root node to the leaf node. The candidate string nodes are the leaf nodes and the intermediate nodes, and the intermediate nodes are the shared string prefixes of their child nodes.

10. A method for configuring a trie, including: Obtain the string usage frequency corresponding to the candidate string nodes of the target trie; Based on the frequency of string usage corresponding to the candidate string node, a corresponding compression code is configured for the candidate string node, so that the string represented by the candidate string node is encoded as its corresponding compression code.

11. The method according to claim 10, wherein, The length of the compressed code corresponding to the candidate string node is negatively correlated with the frequency of use of the string corresponding to the candidate string node.

12. A database system, comprising: A database client is configured to send a string encoding request or a trie configuration request to a database server; the database server is configured to implement the method of any one of claims 1 to 9 in response to the encoding request; or is configured to implement the method of claim 10 or 11 in response to the configuration request.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor, when executing the computer program, implements the method of any one of claims 1 to 11.

14. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method of any one of claims 1 to 11.

15. A computer program product comprising a computer program, said computer program implementing a root function when executed by a processor.

15. The method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Method and system for creating an in-memory physical dictionary for data compression

    CN101222232A

  • Reducing latch count to save hardware area for dynamic huffman table generation

    CN113366765A

  • Binary data lossless compression method and device and storage medium

    CN117579081A

  • Data compression method and apparatus implemented with limited length character tables

    US6400286B1