Text data compression method, device, computer equipment and storage medium
By converting text data into two-byte units and performing displacement addition operations, combined with secondary compression, the problem of low storage compression ratio of text data is solved, and efficient storage and transmission is achieved.
Patent Information
- Application Number
- CN202111271127.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-29
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-10-29
AI Technical Summary
The existing data storage method is based on text format, resulting in low data compression ratio and low hard disk utilization, and the inability to effectively save and transmit a large amount of power quality monitoring data.
The text data to be compressed is converted into multiple units to be compressed with two bytes in length, and then the displacement and addition operations are performed, and then the compressed data is spliced in sequence, and the compressed data is optionally secondary compression through a specific component, and the Hash value is calculated and saved.
It improves storage space utilization, reduces storage space, reduces network transmission bandwidth usage, and has certain data confidentiality capabilities.
Smart Images

Figure CN114070325B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer equipment, storage medium, and computer program product for compressing text data. Background Art
[0002] As the number of power quality monitoring points increases, the amount of power quality monitoring data increases. The increasingly rich monitoring data has brought great convenience to equipment status monitoring and operation and maintenance, resulting in a blowout of monitoring data.
[0003] The current data storage is based on text format, which is not conducive to the long-term preservation and flow of data. A large amount of monitoring data has to be abandoned or deleted regularly due to insufficient funds to purchase enough hard disks.
[0004] In addition, traditional winrar compression software, due to its universality, cannot achieve a high compression ratio for monitoring data.
[0005] Therefore, how to improve the data compression ratio and increase the utilization rate of the hard disk has become a technical problem that needs to be solved urgently. Summary of the Invention
[0006] Based on this, it is necessary to provide a text data compression method, device, computer equipment, computer-readable storage medium and computer program product that can store compressed data files, improve storage space utilization, have a higher compression ratio, and occupy less storage space in response to the above technical problems.
[0007] A method for compressing text data, the method comprising:
[0008] Get the text data to be compressed;
[0009] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0010] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0011] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0012] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0013] The compressed characters are spliced in sequence to obtain compressed data.
[0014] In one embodiment, the text data is character string data, and converting the text data to be compressed into a plurality of two-byte units to be compressed comprises:
[0015] Convert the string data into array data of multiple bytes;
[0016] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0017] In one embodiment, the method further comprises:
[0018] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0019] In one embodiment, the adding of the third char character unit to the corresponding second char character unit to obtain the compressed character comprises:
[0020] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0021] The added character units are converted into char character units to obtain compressed characters.
[0022] In one embodiment, the method includes:
[0023] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0024] In one embodiment, the method further comprises:
[0025] Calculate and save the hash value of the secondary compression result.
[0026] A text data compression device, comprising:
[0027] A text data acquisition module, used to acquire text data to be compressed;
[0028] A unit-to-be-compressed conversion module, configured to convert the text data to be compressed into a plurality of units to be compressed each having a length of two bytes;
[0029] A char character unit conversion module is used to convert each unit to be compressed into a first char character unit and a second char character unit;
[0030] A left shift module, used for shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0031] An adding module, configured to add the third char character unit to the corresponding second char character unit to obtain a compressed character;
[0032] The splicing module is used to splice the compressed characters in sequence to obtain compressed data.
[0033] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0034] Get the text data to be compressed;
[0035] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0036] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0037] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0038] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0039] The compressed characters are spliced in sequence to obtain compressed data.
[0040] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0041] Convert the string data into array data of multiple bytes;
[0042] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0043] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0044] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0045] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0046] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0047] The added character units are converted into char character units to obtain compressed characters.
[0048] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0049] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0050] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0051] Calculate and save the hash value of the secondary compression result.
[0052] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0053] Get the text data to be compressed;
[0054] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0055] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0056] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0057] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0058] The compressed characters are spliced in sequence to obtain compressed data.
[0059] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0060] Convert the string data into array data of multiple bytes;
[0061] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0062] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0063] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0064] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0065] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0066] The added character units are converted into char character units to obtain compressed characters.
[0067] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0068] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0069] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0070] Calculate and save the hash value of the secondary compression result.
[0071] A computer program product, comprising a computer program, which, when executed by a processor, implements the following steps:
[0072] Get the text data to be compressed;
[0073] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0074] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0075] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0076] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0077] The compressed characters are spliced in sequence to obtain compressed data.
[0078] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0079] Convert the string data into array data of multiple bytes;
[0080] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0081] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0082] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0083] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0084] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0085] The added character units are converted into char character units to obtain compressed characters.
[0086] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0087] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0088] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0089] Calculate and save the hash value of the secondary compression result.
[0090] The above-mentioned text data compression method, device, computer equipment, storage medium and computer program product store compressed data files, improve storage space utilization, have a high compression ratio, occupy less storage space, and can effectively reduce bandwidth occupancy during network transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0091] Figure 1 1 is a flow chart of a method for compressing text data in one embodiment;
[0092] Figure 2 Schematic diagram of a flow chart of a step of obtaining a unit to be compressed in one embodiment;
[0093] Figure 3 A flowchart of the assignment step in one embodiment;
[0094] Figure 4 1 is a flow chart of a char character unit addition step in one embodiment;
[0095] Figure 5 Schematic diagram of the secondary compression process in one embodiment;
[0096] Figure 6 is a structural block diagram of a device for compressing text data in one embodiment;
[0097] Figure 7 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0098] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0099] In one embodiment, Figure 1 As shown, a method for compressing text data is provided. This embodiment uses the method applied to a terminal as an example for illustration. It is understandable that the method can also be applied to a server, or to a system including a terminal and a server, and implemented through interaction between the terminal and the server. This embodiment includes the following steps:
[0100] Step 101, obtaining text data to be compressed;
[0101] In this embodiment, the terminal may first obtain text data to be compressed. Specifically, the text data may be multiple types of data such as power quality monitoring data, and this embodiment does not impose excessive restrictions on this. Furthermore, the text data may be character string data.
[0102] The terminal may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, portable wearable devices, etc. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0103] Step 102, converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0104] In actual application in this embodiment, after obtaining the text data to be compressed, it can be converted into a unit to be compressed with a length of two bytes; first, it can be calculated how many bytes of data the text data includes, that is, the total length is calculated, and it is divided into two groups according to the total length to obtain each group of units to be compressed with a length of two bytes. Of course, the number of units to be compressed can be multiple.
[0105] For example, when the total length of the text data is 26 bytes, it can be divided into 13 units to be compressed with a length of two bytes. If the total length of the text data is 25 bytes, an empty byte is added at the end and assigned a value of 0, and it is divided into 13 units to be compressed with a length of two bytes.
[0106] Step 103, converting each unit to be compressed into a first char character unit and a second char character unit;
[0107] After obtaining multiple two-byte units to be compressed, the two-byte units to be compressed can be converted into a first char character unit and a second char character unit, and the data of each byte of the unit to be compressed can be converted into a char character unit respectively. The char character is a basic data type in computer programming language that can only accommodate a single character.
[0108] Specifically, first, the two bytes of data in each unit to be compressed can be assigned to two separate byte units respectively, and then the two separate byte units can be converted into a first char character unit and a second char character unit.
[0109] Step 104, shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0110] In this embodiment, the first char character unit can be shifted left by a preset number of bits to obtain a third char character unit. The preset number of bits can be 8 bits, and this embodiment does not impose excessive restrictions on this.
[0111] Step 105, adding the third char character unit to the corresponding second char character unit to obtain a compressed character;
[0112] Further applied to this embodiment, the third char character unit can be added to its corresponding second char character unit, and the obtained data can be forcibly converted into a char character unit to obtain the compressed character.
[0113] Repeat steps 103 to 105 to convert all two-byte units to be compressed into char character units, and after performing operations such as shifting and adding, obtain the corresponding compressed characters.
[0114] For example, when the total length of the text data is 26 bytes, it is divided into 13 units to be compressed with a length of two bytes. Each unit to be compressed is converted into a first char character unit and a second char character unit, and then after shifting and adding, the 13 units to be compressed complete the above operations and obtain 13 compressed characters at the same time.
[0115] Step 106: splice the compressed characters in order to obtain compressed data.
[0116] All compressed characters are concatenated in order to obtain compressed data, and the compressed result is written into a data file.
[0117] The above-mentioned text data compression method stores compressed data files, improves storage space utilization, has a high compression ratio, occupies less storage space, and can effectively reduce bandwidth usage during network transmission. Furthermore, if the compression method is kept confidential, it maintains a certain degree of data confidentiality.
[0118] In one embodiment, Figure 2 FIG. 1 is a flow chart of a step of obtaining a unit to be compressed according to this embodiment, including:
[0119] Step 201, converting the string data into array data of multiple bytes;
[0120] In this embodiment, the text data is character string data, and the character string data is converted into array data of multiple bytes, that is, the character string data is converted into a byte array, and the array length may be n.
[0121] Step 202: traverse the array data of the plurality of bytes with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0122] Further applied to this embodiment, the step size is set to two bytes, and the array data of n bytes is traversed to obtain n / 2 units to be compressed with a length of two bytes.
[0123] Specifically applied to this embodiment, Figure 3 FIG. 1 is a flow chart of an assignment step of this embodiment, including:
[0124] Step 301: When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0125] In another case, when the number of bits of the array data is an odd number, that is, n is an odd number, a one-byte byte array can be added and assigned a value of zero, that is, an empty byte is added to the last unit to be compressed and assigned a value of zero, which solves the problem of dividing the two-byte units to be compressed in the odd case and improves the compression efficiency.
[0126] In the specific implementation, Figure 4 FIG. 1 is a flow chart of a char character unit addition step of this embodiment, including:
[0127] Step 401, adding the third char character unit and the second char character unit to obtain an added character unit;
[0128] First, the third char character unit and the second char character unit can be added to obtain the added character unit, that is, the shifted first char character unit and the second char character unit are added to obtain the added character unit.
[0129] Step 402: Convert the added character units into char character units to obtain compressed characters.
[0130] Further applied to this embodiment, the added character units are forcibly converted into char character units to obtain compressed characters.
[0131] In an embodiment of a practical application, Figure 5FIG. 1 is a flow chart of a secondary compression step of this embodiment, including:
[0132] Step 501: Perform secondary compression on the compressed data through a specific component to obtain a secondary compression result.
[0133] The above-mentioned specific components may include SharpZipLib, winzip and other specific components for secondary compression of the compressed data, and other specific components may also be used for secondary compression. This embodiment does not impose too many restrictions on the types of specific components.
[0134] Specifically, SharpZipLib is a C# class library used to decompress files in formats such as Zip, GZip, BZip2, and Tar. It's implemented as a managed assembly and can be easily applied to other projects. Winzip, on the other hand, is a powerful and easy-to-use compression component that supports compressing or decompressing files in ZIP, CAB, TAR, GZIP, MIME, and many more formats.
[0135] Furthermore, when performing a secondary compression operation, a secondary compression result is obtained, and a Hash value of the secondary compression result is calculated and saved.
[0136] In another preferred embodiment, the secondary compression result may be compressed again to obtain a tertiary compression result, thereby further improving the compression ratio, occupying less storage space, and more effectively reducing bandwidth usage and improving transmission efficiency.
[0137] In order to enable those skilled in the art to better understand the core concept of this application, a specific example is given below to illustrate:
[0138] The text data compression method comprises the following steps:
[0139] Step 1: Read the string content of the data file to be compressed;
[0140] Step 2: Convert the string content in step 1 into a byte array with an array length of n.
[0141] Step 3: Traverse the byte array obtained in step 2 with a step size of 2 bytes to obtain n / 2 units to be compressed; if n is an odd number, the second byte of the last unit to be compressed is assigned a value of 0;
[0142] Step 4: Take the first byte and the second byte of the 2-byte unit to be compressed obtained in step 3 and assign them to the first and second byte units to be calculated, respectively. The first and second byte units to be calculated are forcibly converted into the first and second char character units to be calculated, respectively.
[0143] Step 5: Shift the first char character unit to be calculated 8 bits to the left to obtain the first char character unit after calculation;
[0144] Step 6: Add the first char character unit calculated in step 5 to the second char character unit to be calculated obtained in step 4, and then forcefully convert them into char, thereby obtaining a compressed character unit;
[0145] Step 7: Repeat steps 3 to 6 to compress all string contents and concatenate the results to obtain the compressed results and write them into the data file.
[0146] Step 8: Use sharpziplib to compress the data file in step 7 again, and finally generate a twice-compressed data file;
[0147] Step 9: Calculate the hash value of the compressed data file and save the hash value.
[0148] In another preferred embodiment, step 8 may use other tools such as winzip to perform secondary compression. After step 8, the data obtained in step 8 may be compressed again to further improve the compression efficiency.
[0149] The data file compression method used in this embodiment has a high compression ratio, occupies less storage space, and can effectively reduce bandwidth usage during network transmission. In addition, when the compression method is kept confidential, it has a certain data confidentiality capability.
[0150] It should be understood that although Figure 1-5 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figure 1-5 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The order of execution of these steps or stages is not necessarily one by one, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0151] In one embodiment, Figure 6 As shown, a text data compression device is provided, the device comprising:
[0152] The text data acquisition module 601 is used to acquire the text data to be compressed;
[0153] The unit-to-be-compressed conversion module 602 is configured to convert the text data to be compressed into a plurality of units to be compressed each having a length of two bytes;
[0154] The char character unit conversion module 603 is used to convert each unit to be compressed into a first char character unit and a second char character unit;
[0155] A left shift module 604 is configured to shift the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0156] An adding module 605 is used to add the third char character unit to the corresponding second char character unit to obtain a compressed character;
[0157] The splicing module 606 is used to splice the compressed characters in sequence to obtain compressed data.
[0158] In one embodiment, the text data is character string data, and the unit to be compressed conversion module includes:
[0159] An array data conversion submodule, used for converting the string data into array data of multiple bytes;
[0160] The submodule for obtaining the unit to be compressed is used to traverse the array data of the multiple bytes with a step size of two bytes to obtain multiple units to be compressed with a length of two bytes.
[0161] In one embodiment, the apparatus comprises:
[0162] The assignment module is used to assign the second byte of the last unit to be compressed to zero when the number of bits of the array data is an odd number.
[0163] In one embodiment, the adding module includes:
[0164] An adding submodule, configured to add the third char character unit and the second char character unit to obtain an added character unit;
[0165] The conversion submodule is used to convert the added character units into char character units to obtain compressed characters.
[0166] In one embodiment, the apparatus comprises:
[0167] The secondary compression module is used to perform secondary compression on the compressed data through a specific component to obtain a secondary compression result.
[0168] In one embodiment, the apparatus comprises:
[0169] The Hash value calculation module is used to calculate and save the Hash value of the secondary compression result.
[0170] The specific definition of the text data compression device can be found in the definition of the text data compression method above and will not be repeated here. The various modules in the above-mentioned text data compression device can be implemented in whole or in part through software, hardware, or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the corresponding operations of the above-mentioned modules.
[0171] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a method for compressing text data is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse.
[0172] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0173] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0174] Get the text data to be compressed;
[0175] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0176] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0177] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0178] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0179] The compressed characters are spliced in sequence to obtain compressed data.
[0180] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0181] Convert the string data into array data of multiple bytes;
[0182] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0183] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0184] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0185] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0186] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0187] The added character units are converted into char character units to obtain compressed characters.
[0188] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0189] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0190] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0191] Calculate and save the hash value of the secondary compression result.
[0192] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0193] Get the text data to be compressed;
[0194] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0195] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0196] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0197] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0198] The compressed characters are spliced in sequence to obtain compressed data.
[0199] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0200] Convert the string data into array data of multiple bytes;
[0201] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0202] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0203] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0204] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0205] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0206] The added character units are converted into char character units to obtain compressed characters.
[0207] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0208] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0209] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0210] Calculate and save the hash value of the secondary compression result.
[0211] A computer program product, comprising a computer program, which, when executed by a processor, implements the following steps:
[0212] Get the text data to be compressed;
[0213] Converting the text data to be compressed into a plurality of two-byte units to be compressed;
[0214] Convert each unit to be compressed into a first char character unit and a second char character unit;
[0215] Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit;
[0216] Add the third char character unit to the corresponding second char character unit to obtain the compressed character;
[0217] The compressed characters are spliced in sequence to obtain compressed data.
[0218] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0219] Convert the string data into array data of multiple bytes;
[0220] The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
[0221] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0222] When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
[0223] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0224] Adding the third char character unit and the second char character unit to obtain an added character unit;
[0225] The added character units are converted into char character units to obtain compressed characters.
[0226] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0227] The compressed data is subjected to secondary compression by a specific component to obtain a secondary compression result.
[0228] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0229] Calculate and save the hash value of the secondary compression result.
[0230] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0231] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0232] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0233] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.
Claims
1. A method for compressing text data, characterized in that: The method comprises: Acquire text data to be compressed; the text data is power quality monitoring data; Converting the text data to be compressed into a plurality of two-byte units to be compressed, specifically comprising: determining the total length of the text data to be compressed; dividing the text data to be compressed according to the total length to obtain the plurality of two-byte units to be compressed; Convert each unit to be compressed into a first char character unit and a second char character unit; Shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit; Add the third char character unit to the corresponding second char character unit to obtain the compressed character; splicing the compressed characters in order to obtain compressed data; Performing secondary compression on the compressed data by a specific component to obtain a secondary compression result; Calculate and save the hash value of the secondary compression result; The secondary compression result is compressed again to obtain a tertiary compression result.
2. The method according to claim 1, characterized in that The text data is character string data, and converting the text data to be compressed into a plurality of two-byte units to be compressed comprises: Convert the string data into array data of multiple bytes; The array data of the plurality of bytes is traversed with a step length of two bytes to obtain a plurality of to-be-compressed units with a length of two bytes.
3. The method according to claim 2, characterized in that The method further comprises: When the number of bits of the array data is an odd number, the second byte of the last unit to be compressed is assigned a value of zero.
4. The method according to claim 1, wherein The step of adding the third char character unit to the corresponding second char character unit to obtain a compressed character comprises: Adding the third char character unit and the second char character unit to obtain an added character unit; The added character units are converted into char character units to obtain compressed characters.
5. A text data compression device, characterized in that: The device comprises: A text data acquisition module, used to acquire text data to be compressed; the text data is power quality monitoring data; The unit-to-be-compressed conversion module is configured to convert the text data to be compressed into a plurality of units to be compressed each having a length of two bytes, specifically comprising: determining the total length of the text data to be compressed; dividing the text data to be compressed according to the total length to obtain the plurality of units to be compressed each having a length of two bytes; A char character unit conversion module is used to convert each unit to be compressed into a first char character unit and a second char character unit; A left shift module, used for shifting the first char character unit to the left by a preset number of bits to obtain a third char character unit; An adding module, configured to add the third char character unit to the corresponding second char character unit to obtain a compressed character; The splicing module is used to splice the compressed characters in order to obtain compressed data; perform secondary compression on the compressed data through a specific component to obtain a secondary compression result; calculate and save the hash value of the secondary compression result; and compress the secondary compression result again to obtain a tertiary compression result.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
A fast calculation method for binary image median filtering and an implementation method thereof
CN109727206A
Multi-byte compressed string representation
US20170329619A1