Data compression method, device, apparatus and storage medium

By determining the compression strategy based on the data type and numerical range, and using cutoff bits and storage bits for data compression, the problem of insufficient compression ratio in existing technologies is solved, and more efficient data compression is achieved.

CN114513209BActive Publication Date: 2025-12-16PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210134663.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-14
Publication Date
2025-12-16
Estimated Expiration
2042-02-14

AI Technical Summary

Technical Problem

The existing GZIP compression method has insufficient compression ratio and cannot meet the needs of modern Internet products.

Method used

By obtaining the data type of the data to be compressed, determining its numerical range, selecting the target compression strategy based on the numerical range, and using the cutoff bit and storage bits to compress the data into the target compressed data.

Benefits of technology

It improves the compression rate of data compression, meeting the data transmission needs of modern Internet products.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114513209B_ABST
    Figure CN114513209B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of data compression, and discloses a data compression method, device, equipment and storage medium. The method comprises the following steps: when compressing to-be-compressed data, the data type of the to-be-compressed data is acquired; when the data type is a preset data type, the numerical interval of the to-be-compressed data is determined; the corresponding target compression strategy is determined according to the numerical interval; and the to-be-compressed data is compressed based on the target compression strategy to obtain target compressed data. Through the above method, when the data type of the to-be-compressed data is the preset data type, the numerical interval in which the size of the to-be-compressed data is located is determined, and the corresponding compression strategy is determined based on the data interval in which the to-be-compressed data is located, so that the compression rate during data compression can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data compression, in particular to a data compression method, device, equipment and storage medium. BACKGROUND

[0002] Data compression technology is widely used in Internet application products, and the compression method is different according to different application scenarios. According to the timeliness requirement, it can be divided into instant compression and non-instant compression, according to the compression object, it can be divided into data compression and file compression, according to whether the data can be restored, it can be divided into lossy compression and lossless compression. In this extremely competitive environment of Internet products, who can ensure that the data transmitted in network communication is more timely and stable will undoubtedly have an advantage.

[0003] At present, GZIP compression technology is usually used, and the GZIP compression principle mainly uses LZ77 algorithm and Huffman coding to realize, which is a lossless compression method using redundancy and matching string. The GZIP compression method is widely used, and the compression rate of the compression object is theoretically in the range of 2:1 to 5:1. Such compression rate cannot meet the demand, and how to improve the compression rate becomes a problem to be solved.

[0004] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0005] The main purpose of the present application is to provide a data compression method, device, equipment and storage medium, which aims to solve the technical problem of how to improve the compression rate of the prior art.

[0006] In order to achieve the above purpose, the present application provides a data compression method, which comprises the following steps:

[0007] When the data to be compressed is compressed, the data type of the data to be compressed is obtained;

[0008] When the data type is a preset data type, the numerical interval of the data to be compressed is determined;

[0009] According to the numerical interval, the corresponding target compression strategy is determined;

[0010] The data to be compressed is compressed based on the target compression strategy to obtain target compression data.

[0011] Optionally, the data to be compressed is compressed based on the target compression strategy to obtain target compression data, comprising:

[0012] According to the target compression strategy, the target byte is determined;

[0013] determining a cutoff bit and a storage bit in the target byte;

[0014] compressing the data to be compressed into target compressed data according to the cutoff bit and the storage bit.

[0015] Optionally, the step of compressing the data to be compressed into target compressed data according to the cutoff bit and the storage bit comprises:

[0016] determining a number of bytes according to the target byte;

[0017] storing first preset bit data in the data to be compressed into the storage bit when the number of bytes is a first preset number;

[0018] setting the cutoff bit as a first preset value;

[0019] generating target compressed data according to the first preset bit data in the storage bit and the first preset value in the cutoff bit.

[0020] Optionally, after the step of determining a number of bytes according to the target byte, the method further comprises:

[0021] determining a non-cutoff bit in the target byte when the number of bytes is a second preset number;

[0022] determining a first storage bit and a second storage bit in the storage bit according to the cutoff bit and the non-cutoff bit;

[0023] storing first preset bit data in the data to be compressed into the first storage bit and storing second preset bit data in the data to be compressed into the second storage bit;

[0024] setting the cutoff bit as a first preset value;

[0025] setting the non-cutoff bit as a second preset value;

[0026] generating target compressed data according to the first preset value in the cutoff bit, the second preset value in the non-cutoff bit, the first preset bit data in the first storage bit and the second preset bit data in the second storage bit.

[0027] Optionally, after the step of determining a number of bytes according to the target byte, the method further comprises:

[0028] determining each non-cutoff bit in the target byte when the number of bytes is greater than a second preset number;

[0029] determining each target storage bit in the storage bit according to the cutoff bit and each non-cutoff bit;

[0030] Store each preset bit data in the to-be-compressed data into each target storage bit;

[0031] Set the cutoff bit as a first preset value;

[0032] Set each non-cutoff bit as a second preset value;

[0033] Generate target compressed data according to the first preset value in the cutoff bit, the second preset value in each non-cutoff bit, and each preset bit data in each target storage bit.

[0034] Optionally, after the data type of the to-be-compressed data is obtained, the method further includes:

[0035] When the data type is not a preset data type, determine a data conversion strategy according to the data type;

[0036] Convert the data type of the to-be-compressed data into a preset data type according to the data conversion strategy;

[0037] Determine a value interval of the to-be-compressed data after conversion.

[0038] Optionally, after the to-be-compressed data is compressed based on the target compression strategy to obtain target compressed data, the method further includes:

[0039] Read a current byte of the target compressed data;

[0040] When a highest bit of the current byte is the second preset value, determine a next byte according to a reading order;

[0041] When a highest bit of the next byte is the first preset value, stop reading, and generate decompressed data according to a storage bit of the current byte, a storage bit of the next byte, and the reading order.

[0042] In addition, to achieve the above object, the application further provides a data compression device, which includes:

[0043] A type acquisition module is configured to acquire a data type of to-be-compressed data when the to-be-compressed data is compressed;

[0044] An interval determination module is configured to determine a value interval of the to-be-compressed data when the data type is a preset data type;

[0045] A strategy determination module is configured to determine a corresponding target compression strategy according to the value interval;

[0046] A data compression module is configured to compress the to-be-compressed data based on the target compression strategy to obtain target compressed data.

[0047] Further, to achieve the above object, the present application also provides a data compression device, comprising a memory, a processor and a data compression program stored in the memory and executable on the processor, the data compression program being configured to implement the steps of the data compression method as described above.

[0048] Further, to achieve the above object, the present application also provides a storage medium, the storage medium storing a data compression program, the data compression program being executable on a processor to implement the steps of the data compression method as described above.

[0049] The present application, when compressing the data to be compressed, acquires the data type of the data to be compressed; when the data type is a preset data type, determines the numerical interval of the data to be compressed; determines the corresponding target compression strategy according to the numerical interval; and compresses the data to be compressed based on the target compression strategy to obtain target compressed data. In this way, when the data type of the data to be compressed is a preset data type, the numerical interval in which the size of the data to be compressed is located is determined, and the corresponding compression strategy is determined based on the data interval in which it is located, thereby improving the compression rate during data compression. BRIEF DESCRIPTION OF DRAWINGS

[0050] Figure 1 is a structural schematic diagram of a data compression device of a hardware running environment related to the embodiment scheme of the present application.

[0051] Figure 2 is a flowchart of the first embodiment of the data compression method of the present application.

[0052] Figure 3 is a flowchart of the second embodiment of the data compression method of the present application.

[0053] Figure 4 is a structural block diagram of the first embodiment of the data compression device of the present application.

[0054] The implementation of the object, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0055] It should be understood that the specific embodiments described herein are only used to explain the present application and not to limit the present application.

[0056] Reference Figure 1 , Figure 1 is a structural schematic diagram of a data compression device of a hardware running environment related to the embodiment scheme of the present application.

[0057] As Figure 1As shown in the figure, the data compression device can include a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between the components. The user interface 1003 can include a display, an input unit such as a keyboard, and can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a wireless fidelity (Wi-Fi) interface). The memory 1005 can be a high-speed random access memory (RAM) memory, or a stable non-volatile memory (NVM) such as a disk memory. The memory 1005 can also be a storage device independent of the aforementioned processor 1001.

[0058] Those skilled in the art can understand that Figure 1 The structure shown in the figure does not constitute a limitation on the data compression device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0059] As Figure 1 As shown in the figure, the memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and a data compression program.

[0060] In Figure 1 In the data compression device shown in the figure, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the data compression device of the present application can be arranged in the data compression device, and the data compression device calls the data compression program stored in the memory 1005 through the processor 1001, and executes the data compression method provided by the embodiment of the present application.

[0061] The embodiment of the present application provides a data compression method, which refers to Figure 2 , Figure 2 The flowchart of a first embodiment of the data compression method of the present application.

[0062] In this embodiment, the data compression method includes the following steps:

[0063] Step S10: When compressing the to-be-compressed data, the data type of the to-be-compressed data is acquired.

[0064] It should be noted that the application scenario of the embodiment is that when the data such as the transaction amount, the transaction volume, and the amount of the bank account is compressed, in order to be compatible with a small number of large capacity data, unsigned 64-bit integer data needs to be used for storage and transmission. When the unsigned 64-bit integer data is stored and transmitted, it needs to be compressed, so as to achieve the purpose of smaller storage space occupation and higher transmission rate.

[0065] In a specific implementation, the execution subject of the embodiment can be a terminal device, such as a server of a stock trading platform, a server of a bank, and the like. It can also be a computer or other device with computing function.

[0066] It can be understood that the data such as the transaction amount, the transaction volume, and the amount of the bank account is the data to be compressed. Different data to be compressed can have different data types, including unsigned 64-bit integer, signed 64-bit integer, unsigned 32-bit integer, and the like.

[0067] Further, after the data type of the data to be compressed is obtained, the method further includes:

[0068] When the data type is not the preset data type, a data conversion strategy is determined according to the data type, the data type of the data to be compressed is converted into the preset data type according to the data conversion strategy, and a numerical interval of the data to be compressed after conversion is determined.

[0069] When the data to be compressed is not unsigned 64-bit integer, the data to be compressed needs to be converted. Different data types of the data to be compressed correspond to different conversion strategies. When the data to be compressed is signed number, the data to be compressed needs to be converted into unsigned number. When the signed number is converted into unsigned number, it is needed to detect whether the highest bit of the signed number is 1. If it is not 1 (i.e. 0), the unsigned number is directly equal to the signed number. If the highest bit of the signed number is 1, the signed number is taken as a complement, so as to obtain the unsigned number. After the unsigned number is obtained, if the unsigned number is a floating point number, the floating point number needs to be converted into integer number. If it is an integer number, it does not need to be converted. After the integer number is obtained, it is detected whether the bit number of the integer number is 64 bits. If the bit number of the integer number is less than 64, the unsigned number needs to be right shifted, so as to be supplemented to enough bit number. For example, when unsigned 32-bit integer data is converted into unsigned 64-bit integer, the unsigned 32-bit integer data needs to be right shifted by 32 bits, so as to become 64 bits.

[0070] Step S20: When the data type is the preset data type, a numerical interval of the data to be compressed is determined.

[0071] It should be noted that the preset data type is unsigned 64-bit integer, and when the data type of the to-be-compressed data is unsigned 64-bit integer, the numerical interval in which the to-be-compressed data is located is determined, for example, [0x0000000000000000ULL, 0x0000000000000080ULL), which is greater than or equal to 0 and less than 128 in decimal.

[0072] Step S30: determining a corresponding target compression strategy according to the numerical interval.

[0073] It can be understood that the to-be-compressed data in different numerical intervals has different numbers of bits containing actual effective information, for example, the data equal to 0 and less than 128 in decimal, after being converted into unsigned 64-bit integer, the maximum number of significant bits containing actual effective information is 7 low bits, and the data greater than or equal to 128 and less than 16384 in decimal, after being converted into unsigned 64-bit integer, the maximum number of significant bits containing actual effective information is 14 low bits. Therefore, different numerical intervals of to-be-compressed data need to use different target compression strategies to compress the to-be-compressed data.

[0074] Step S40: compressing the to-be-compressed data based on the target compression strategy to obtain target compressed data.

[0075] Further, in order to better compress the to-be-compressed data, step S40 includes: determining a target byte according to the target compression strategy; determining a cutoff bit and a storage bit in the target byte; and compressing the to-be-compressed data into target compressed data according to the cutoff bit and the storage bit.

[0076] It should be noted that each target compression strategy corresponds to a target byte for storing compressed target compressed data, and the target byte can include one or more consecutive bytes, each byte (byte) including 8 bits (bit), when the target byte is one, the highest bit of the target byte is the cutoff bit, and the rest is the storage bit, and the highest bit refers to the leftmost bit in a byte, when the target byte is a plurality of consecutive bytes, the highest bit of the largest byte in the target byte is the cutoff bit, and the rest is the storage bit, and among the plurality of consecutive bytes, the leftmost byte is the largest byte, and the rightmost byte is the smallest byte.

[0077] Further, the compression of the to-be-compressed data into target compressed data according to the cutoff bit and the storage bit includes: determining a byte quantity according to the target byte; when the byte quantity is a first preset quantity, storing first preset bit data in the to-be-compressed data into the storage bit; setting the cutoff bit to a first preset value; and generating target compressed data according to the first preset bit data in the storage bit and the first preset value in the cutoff bit.

[0078] It can be understood that the number of bytes refers to the number of bytes in the target byte, the first preset number refers to the number 1, when there is only one byte in the target byte, it indicates that the size of the data to be compressed is in the first interval, the first interval refers to 0x0000000000000000ULL to 0x0000000000000080ULL, that is, the data to be compressed is greater than or equal to 0 and less than 128, at this time, the actual effective data in the data to be compressed occupies a maximum of 7 bits, and the 7 bits are the low 7 bits in the data to be compressed. The first preset bit data is the low 7 bits of the 64 bits in the data to be compressed, and the low 7 bits refer to the rightmost 7 bits in the 64 bits. The low 7 bits in the data to be compressed are stored in the storage bit of the target byte. The first preset value refers to 1. The data in the target byte is the target compressed data.

[0079] Further, after determining the number of bytes according to the target byte, it further includes: when the number of bytes is a second preset number, determining a non-stop bit in the target byte; determining a first storage bit and a second storage bit in the storage bit according to the stop bit and the non-stop bit; storing first preset bit data in the data to be compressed into the first storage bit, and storing second preset bit data in the data to be compressed into the second storage bit; setting the stop bit to a first preset value; setting the non-stop bit to a second preset value; generating target compressed data according to the first preset value in the stop bit, the second preset value in the non-stop bit, the first preset bit data in the first storage bit, and the second preset bit data in the second storage bit.

[0080] It should be noted that the second preset number refers to 2, when the number of bytes of the target byte is 2, there is also a non-stop bit in the target byte, and the non-stop bit refers to the highest bit in each of the remaining bytes in the non-maximum byte. When the target byte includes two bytes, the size of the data to be compressed is in the second interval, the second interval is: 0x0000000000000080ULL to 0x0000000000004000ULL, that is, the data to be compressed is greater than or equal to 128 and less than 16384, at this time, the actual effective data in the data to be compressed occupies a maximum of 14 bits, and the low 14 bits in the data to be compressed, the first storage bit refers to the low 7 bits of the minimum byte in the target byte, the second storage bit refers to the low 7 bits of the maximum byte in the target byte, the first preset bit data refers to the low 7 bits in the actual effective data maximum occupation bit, and the second preset bit data refers to the high 7 bits in the actual effective data maximum occupation bit. The second preset value is 0.

[0081] Further, the determining the number of bytes according to the target byte further comprises: when the number of bytes is greater than a second preset number, determining each non-stop bit in the target byte; determining each target storage bit in the storage bits according to the stop bit and each non-stop bit; storing each preset bit data in the to-be-compressed data into each target storage bit; setting the stop bit as a first preset value; setting each non-stop bit as a second preset value; and generating target compressed data according to the first preset value in the stop bit, the second preset value in each non-stop bit, and each preset bit data in each target storage bit.

[0082] In a specific implementation, when the number of bytes of the target byte is greater than 2, there are multiple non-stop bits in the target byte, and the lower 7 bits of each byte in the target byte are target storage bits. The rightmost byte in the target byte is the first byte, and the preset bit data refers to the lower 7 bits of the to-be-compressed data.

[0083] When the number of target bytes is 3, the size of the to-be-compressed data is in the third interval, the third interval is 0x0000000000004000ULL to 0x0000000000200000ULL, that is, the to-be-compressed data is greater than or equal to 16384 and less than 2097152, and at this time, the maximum occupied bits of the actual effective data are 21 bits. Therefore, the compression process is: the first byte stores the lower 7 bits of the to-be-compressed data, and the highest bit of this byte is 0; the to-be-compressed data is right shifted by 7 bits, the lower 7 bits of the moved to-be-compressed data are stored by using the second byte, and the highest bit of this byte is 0; the to-be-compressed data is right shifted by 7 bits again, the lower 7 bits of the moved to-be-compressed data are stored by using the third byte, and the highest bit of this byte is 1.

[0084] When the number of target bytes is 4, the size of the to-be-compressed data is in the fourth interval, the fourth interval is 0x0000000000200000ULL to 0x0000000010000000ULL, that is, the to-be-compressed data is greater than or equal to 2097152 and less than 268435456, and at this time, the maximum occupied bits of the actual effective data are 28 bits. The compression process is: the first byte stores the lower 7 bits of the to-be-compressed data, and the highest bit of this byte is 0; the to-be-compressed data is right shifted by 7 bits, the lower 7 bits of the moved to-be-compressed data are stored by using the second byte, and the highest bit of this byte is 0; the to-be-compressed data is right shifted by 7 bits again, the lower 7 bits of the moved to-be-compressed data are stored by using the third byte, and the highest bit of this byte is 0; the to-be-compressed data is right shifted by 7 bits again, the lower 7 bits of the moved to-be-compressed data are stored by using the fourth byte, and the highest bit of this byte is 1.

[0085] When the target byte number is 5, the size of the data to be compressed is in the fifth interval, the fifth interval is: 0x0000000010000000ULL to 0x0000000800000000ULL, at this time the maximum occupied bits of the actual effective data is 35 bits. The compression process is: the first byte stores the low 7 bits of the data to be compressed, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the second byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the third byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the fourth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the fifth byte, and the highest bit of this byte is 1.

[0086] When the target byte number is 6, the size of the data to be compressed is in the sixth interval, the sixth interval is: 0x0000000800000000ULL to 0x0000040000000000ULL, at this time the maximum occupied bits of the actual effective data is 42 bits. The compression process is: the first byte stores the low 7 bits of the data to be compressed, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the second byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the third byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the fourth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the fifth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed is stored in the sixth byte, and the highest bit of this byte is 1.

[0087] When the target byte number is 7, the size of the data to be compressed is in the seventh interval, the seventh interval is: 0x0000040000000000ULL to 0x0002000000000000ULL, at this time the maximum occupied bit of the actual effective data is 49 bits. The compression process is: the first byte stores the low 7 bits of the data to be compressed, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the second byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the third byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fourth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fifth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the sixth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the seventh byte, and the highest bit of this byte is 1.

[0088] When the target byte number is 8, the size of the data to be compressed is in the eighth interval, the eighth interval is: 0x0002000000000000ULL to 0x0100000000000000ULL, at this time the maximum occupied bit of the actual effective data is 56 bits. The compression process is: the first byte stores the low 7 bits of the data to be compressed, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the second byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the third byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fourth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fifth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the sixth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the seventh byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the eighth byte, and the highest bit of this byte is 1.

[0089] When the target byte number is 9, the size of the data to be compressed is in the ninth interval, the ninth interval is: 0x0100000000000000ULL to 0x8000000000000000ULL, at this time the actual effective data maximum occupies 63 bits, and the compression process is: right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the second byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the third byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the fourth byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the fifth byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the sixth byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the seventh byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the eighth byte, and setting the highest position of this byte to 0; right shifting the data to be compressed by 7 bits, storing the low 7 bits of the moved data to be compressed in the ninth byte, and setting the highest position of this byte to 1.

[0090] When the target byte number is 10, the size of the data to be compressed is in the tenth interval, the tenth interval is: greater than 0x8000000000000000ULL, at this time the actual effective data maximum occupies 70 bits. The compression process is: the first byte stores the low 7 bits of the data to be compressed, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the second byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the third byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fourth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the fifth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the sixth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the seventh byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the eighth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the ninth byte, and the highest bit of this byte is 0; the data to be compressed is right shifted by 7 bits, the low 7 bits of the moved data to be compressed are stored in the tenth byte, and the highest bit of this byte is 1.

[0091] In the embodiment, when compressing the data to be compressed, the data type of the data to be compressed is acquired; when the data type is a preset data type, the value interval of the data to be compressed is determined; the corresponding target compression strategy is determined according to the value interval; and the data to be compressed is compressed based on the target compression strategy to obtain target compressed data. In this way, when the data type of the data to be compressed is the preset data type, the value interval in which the size of the data to be compressed is located is determined, and the corresponding compression strategy is determined based on the data interval, so that the compression rate during data compression can be improved.

[0092] Reference Figure 3 , Figure 3 The figure is a flowchart of a second embodiment of the data compression method.

[0093] Based on the first embodiment, the data compression method further includes the following steps after step S40.

[0094] Step S50: reading the current byte of the target compressed data.

[0095] It should be noted that when the target compressed data is decompressed, the lowest bit of the first byte of the target compressed data is read.

[0096] Step S60: When the highest bit of the current byte is the second preset value, the next byte is determined according to the reading order.

[0097] In a specific implementation, the low 7-bit data of the current byte is written into the memory pointed to by the "result pointer" in the order from low to high when reading, and the "result pointer" refers to a pointer pointing to the memory for storing the decompressed target compressed data. The reading order refers to from low to high, for example, from the first byte to the second byte.

[0098] It can be understood that when the highest bit of the current byte is 0, it indicates that the target compressed data is not decompressed, and needs to be continuously decompressed. At this time, the next byte of the current byte is continuously read.

[0099] Step S70: When the highest bit of the next byte is the first preset value, stop reading, and generate decompressed data according to the storage bit of the current byte, the storage bit of the next byte, and the reading order.

[0100] It should be noted that when the highest bit of the next byte is 1, it indicates that the target compressed data has been read, and if the highest bit of the next byte is still 0, the byte is continuously read according to the reading order until the highest bit of the byte is 1.

[0101] In a specific implementation, the data in the storage bit of each byte in the target compressed data is written into the memory pointed to by the "result pointer" from low to high, thereby obtaining complete decompressed data.

[0102] The embodiment reads the current byte of the target compressed data; when the highest bit of the current byte is the second preset value, the next byte is determined according to the reading order; when the highest bit of the next byte is the first preset value, stop reading, and generate decompressed data according to the storage bit of the current byte, the storage bit of the next byte, and the reading order. In the above manner, the target compressed data can be decompressed, thereby completing the compression and decompression process of the data.

[0103] In addition, the embodiment of the present application also proposes a storage medium, and the storage medium stores a data compression program. When the data compression program is executed by a processor, the steps of the data compression method described above are implemented.

[0104] Since the storage medium adopts all the technical solutions of the above-mentioned embodiments, it at least has all the beneficial effects brought by the technical solutions of the above-mentioned embodiments, which will not be repeated here.

[0105] Refer toFigure 4 , Figure 4 is a structure block diagram of a first embodiment of the data compression device.

[0106] As shown in Figure 4 , the data compression device comprises:

[0107] a type obtaining module 10, configured to obtain a data type of to-be-compressed data when the to-be-compressed data is compressed.

[0108] an interval determining module 20, configured to determine a value interval of the to-be-compressed data when the data type is a preset data type.

[0109] a strategy determining module 30, configured to determine a corresponding target compression strategy according to the value interval.

[0110] a data compression module 40, configured to compress the to-be-compressed data based on the target compression strategy to obtain target compressed data.

[0111] In an embodiment, the data compression module 40 is further configured to determine a target byte according to the target compression strategy; determine a cutoff bit and a storage bit in the target byte; and compress the to-be-compressed data into target compressed data according to the cutoff bit and the storage bit.

[0112] In an embodiment, the data compression module 40 is further configured to determine a byte quantity according to the target byte; store first preset bit data in the to-be-compressed data into the storage bit when the byte quantity is a first preset quantity; set the cutoff bit to a first preset value; and generate target compressed data according to the first preset bit data in the storage bit and the first preset value in the cutoff bit.

[0113] In an embodiment, the data compression module 40 is further configured to determine a non-cutoff bit in the target byte when the byte quantity is a second preset quantity; determine a first storage bit and a second storage bit in the storage bit according to the cutoff bit and the non-cutoff bit; store first preset bit data in the to-be-compressed data into the first storage bit and store second preset bit data in the to-be-compressed data into the second storage bit; set the cutoff bit to a first preset value; set the non-cutoff bit to a second preset value; and generate target compressed data according to the first preset value in the cutoff bit, the second preset value in the non-cutoff bit, the first preset bit data in the first storage bit, and the second preset bit data in the second storage bit.

[0114] In an embodiment, the data compression module 40 is further configured to, when the number of bytes is greater than the second preset number, determine each non-stop bit in the target byte; determine each target storage bit in the storage bit according to the stop bit and each non-stop bit; store each preset bit data in the to-be-compressed data into each target storage bit; set the stop bit as a first preset value; set each non-stop bit as a second preset value; and generate target compression data according to the first preset value in the stop bit, the second preset value in each non-stop bit, and each preset bit data in each target storage bit.

[0115] In an embodiment, the type acquisition module 10 is further configured to, when the data type is not a preset data type, determine a data conversion strategy according to the data type; convert the data type of the to-be-compressed data into a preset data type according to the data conversion strategy; and determine a value interval of the to-be-compressed data after conversion.

[0116] In an embodiment, the data compression module 40 is further configured to read a current byte of the target compression data; when a highest bit of the current byte is the second preset value, determine a next byte according to a reading order; when a highest bit of the next byte is the first preset value, stop reading, and generate decompression data according to a storage bit of the current byte, a storage bit of the next byte, and the reading order.

[0117] It should be understood that the above is only illustrative, and does not constitute any limitation on the technical solutions of the present application. In specific applications, those skilled in the art can set up as needed, and the present application does not limit this.

[0118] In the embodiment, when compressing the to-be-compressed data, the data type of the to-be-compressed data is acquired; when the data type is a preset data type, a value interval of the to-be-compressed data is determined; a corresponding target compression strategy is determined according to the value interval; and the to-be-compressed data is compressed based on the target compression strategy to obtain target compression data. In this way, when the data type of the to-be-compressed data is a preset data type, the size of the to-be-compressed data is determined to be in a value interval, and a corresponding compression strategy is determined based on the data interval in which it is located, so that the compression rate during data compression can be improved.

[0119] It should be noted that the above-described workflow is only illustrative and does not constitute a limitation on the scope of protection of the present application. In actual applications, those skilled in the art can select part or all of them according to actual needs to achieve the purpose of the embodiment scheme, which is not limited here.

[0120] In addition, technical details not described in detail in the present embodiment can be found in the data compression method provided by any embodiment of the present application, which will not be described here.

[0121] Furthermore, it is to be understood that the terms "including", "comprising", or any other variation thereof, are intended to cover the non-exclusive inclusion such that processes, methods, articles, or systems that comprise a list of elements are not required to comprise only those elements but can include other elements not expressly listed or inherent to such processes, methods, articles, or systems. Without further limitation, an element preceded by "comprises a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or system that comprises the recited element.

[0122] The above-mentioned embodiment numbers of the present application are only for description, not representing the advantages or disadvantages of the embodiments.

[0123] From the above description of the embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be realized by means of software and necessary general hardware platforms, of course, they can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, an optical disk), and includes a number of instructions for making a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) execute the methods described in the embodiments of the present application.

[0124] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent flow transformation made by using the content of the present application specification and drawings, or directly or indirectly applied to other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A data compression method characterized by, The data compression method comprises: When compressing the to-be-compressed data, acquiring a data type of the to-be-compressed data; When the data type is a preset data type, determining a numerical interval of the to-be-compressed data; According to the numerical interval, determining a corresponding target compression strategy; Based on the target compression strategy, compressing the to-be-compressed data to obtain target compressed data; The target compressed data is obtained by compressing the to-be-compressed data based on the target compression strategy, comprising: According to the target compression strategy, determining a target byte; Determining a cutoff bit and a storage bit in the target byte; According to the cutoff bit and the storage bit, compressing the to-be-compressed data into target compressed data; According to the target byte, determining a byte quantity; When the byte quantity is a first preset quantity, storing first preset bit data in the to-be-compressed data into the storage bit; Setting the cutoff bit to a first preset value; According to the first preset bit data in the storage bit and the first preset value in the cutoff bit, generating target compressed data. After determining the byte quantity according to the target byte, the method further comprises:

2. The method of claim 1, wherein, When the byte quantity is a second preset quantity, determining a non-cutoff bit in the target byte; According to the cutoff bit and the non-cutoff bit, determining a first storage bit and a second storage bit in the storage bit; Storing first preset bit data in the to-be-compressed data into the first storage bit and storing second preset bit data in the to-be-compressed data into the second storage bit; Setting the cutoff bit to a first preset value; Setting the non-cutoff bit to a second preset value; According to the first preset value in the cutoff bit, the second preset value in the non-cutoff bit, the first preset bit data in the first storage bit, and the second preset bit data in the second storage bit, generating target compressed data. After determining the byte quantity according to the target byte, the method further comprises:

3. The method of claim 1, wherein, When the byte quantity is greater than the second preset quantity, determining each non-cutoff bit in the target byte; According to the cutoff bit and each non-cutoff bit, determining each target storage bit in the storage bit; Storing each preset bit data in the to-be-compressed data into each target storage bit; Setting the cutoff bit to a first preset value; Setting each non-cutoff bit to a second preset value; According to the first preset value in the cutoff bit, the second preset value in each non-cutoff bit, and each preset bit data in each target storage bit, generating target compressed data. After acquiring the data type of the to-be-compressed data, the method further comprises:

4. The method of claim 1, wherein, When the data type is not a preset data type, determining a data conversion strategy according to the data type; According to the data conversion strategy, converting the data type of the to-be-compressed data into a preset data type; Determining a numerical interval of the to-be-compressed data after conversion. After compressing the to-be-compressed data based on the target compression strategy to obtain target compressed data, the method further comprises:

5. The method according to any one of claims 1 to 4, characterized in that, Reading a current byte of the target compressed data; ​ When the highest bit of the current byte is a second preset value, determining a next byte according to a reading sequence; When the highest bit of the next byte is the first preset value, stopping reading and generating decompression data according to the storage bit of the current byte, the storage bit of the next byte and the reading sequence.

6. A data compression device, characterized by, The data compression device comprises: A type acquisition module configured to acquire a data type of the to-be-compressed data when compressing the to-be-compressed data; An interval determination module configured to determine a value interval of the to-be-compressed data when the data type is a preset data type; A strategy determination module configured to determine a corresponding target compression strategy according to the value interval; A data compression module configured to compress the to-be-compressed data based on the target compression strategy to obtain target compression data; The data compression module is further configured to determine a target byte according to the target compression strategy; The data compression module is further configured to determine a cutoff bit and a storage bit in the target byte; The data compression module is further configured to compress the to-be-compressed data into target compression data according to the cutoff bit and the storage bit; The data compression module is further configured to determine a byte quantity according to the target byte; The data compression module is further configured to store first preset bit data in the to-be-compressed data into the storage bit when the byte quantity is a first preset quantity; The data compression module is further configured to set the cutoff bit as a first preset value; The data compression module is further configured to generate target compression data according to the first preset bit data in the storage bit and the first preset value in the cutoff bit.

7. A data compression device, characterized by comprising: The device comprises a memory, a processor and a data compression program stored on the memory and executable on the processor, and the data compression program is configured to implement the data compression method in any one of claims 1 to 5.

8. A storage medium, characterized by The storage medium has a data compression program stored thereon, and the data compression program is executed by a processor to implement the data compression method in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Efficient self-adaption seismic dataflow lossless compression and decompression method

    CN104378118A

  • Time sequence database system

    CN109582708A