Byte array-based integer variable-length ordered coding method and device and storage medium

文档序号:749418 发布日期:2021-04-23 浏览:23次 中文

阅读说明:本技术 基于字节数组的整数变长有序编码方法、装置及存储介质 (Byte array-based integer variable-length ordered coding method and device and storage medium ) 是由 胡俊飞 童兆丰 樊兴华 任政 薛锋 于 2021-02-09 设计创作,主要内容包括:本发明公开了一种基于字节数组的整数变长有序编码方法、装置及存储介质,用于数据库中的整数数据存储。方法包括:接收输入到数据库的整数数据;将接收的整数数据转换为字节数组,在字节数组的第1个字节中,第1位表示整数数据属于非负整数或负整数,第2至4位表示补字节长度,第5至8位表示整数数据的最高4位,字节数组的长度等于补字节长度加1,整数数据的绝对值由补值和差值相加组成,字节数组除第1个字节外,后续的字节与第1个字节的第5至8位一起组成整数的差值,补值根据补字节长度来决定;将转换为字节数组的整数数据存入数据库。本发明实现以变长字节数组存储整数数据,以及直接基于字节数组来比较相同符号下的整数数据大小。(The invention discloses an integer variable-length ordered coding method, device and storage medium based on byte arrays, which are used for storing integer data in a database. The method comprises the following steps: receiving integer data input to a database; converting the received integer data into a byte array, wherein in the 1 st byte of the byte array, the 1 st bit represents that the integer data belongs to a non-negative integer or a negative integer, the 2 nd to 4 th bits represent the length of a complementary byte, the 5 th to 8 th bits represent the highest 4 bits of the integer data, the length of the byte array is equal to the length of the complementary byte plus 1, the absolute value of the integer data is formed by adding a complementary value and a difference value, the byte array except the 1 st byte and the subsequent bytes and the 5 th to 8 th bits of the 1 st byte form the difference value of the integer, and the complementary value is determined according to the length of the complementary byte; and storing the integer data converted into the byte array into a database. The invention realizes the storage of integer data in variable length byte arrays and the comparison of the sizes of the integer data under the same symbol directly based on the byte arrays.)

1. An integer variable-length ordered coding method based on byte arrays, which is used for storing integer data in a database, and is characterized in that the integer variable-length ordered coding method comprises the following steps:

receiving integer data input to a database;

converting the received integer data into a byte array, in a 1 st byte of the byte array, the 1 st bit represents that the integer data belongs to a non-negative integer or a negative integer, the 2 nd to 4 th bits represent a complementary byte length, the 5 th to 8 th bits represent the highest 4 bits of the integer data, the length of the byte array is equal to the complementary byte length plus 1, the absolute value of the integer data is composed of the addition of a complementary value and a difference value, the byte array except the 1 st byte, the following bytes and the 5 th to 8 th bits of the 1 st byte together form the difference value of the integer, the complement value is determined according to the length of the complement byte, wherein, in the order of the byte lengths from small to large, the complement value of each byte length is the maximum value expressed by the last byte length plus 1, wherein the length of the shortest byte array is 1 byte, and the length of the longest byte array is 8 bytes;

and storing the integer data converted into the byte array into the database.

2. A method as claimed in claim 1, characterized by: the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data is converted is.

3. A method as claimed in claim 1, characterized by: the order of the sizes of the integers under the same sign is represented by the order of the byte lengths from small to large, and the sign comprises a non-negative integer and a negative integer.

4. A method as claimed in claim 3, characterized by: sorting the integer data under different signs from small to large separately, sorting the nonnegative integers in sequence, and sorting the negative integers in reverse order to realize the ordered comparison of the integers under the same sign.

5. An integer variable length ordered coding device based on byte arrays, which is used for storing integer data in a database, and is characterized in that the integer variable length ordered coding device comprises:

receiving means for receiving integer data input to a database;

conversion means for converting the received integer data into a byte array, in a 1 st byte of the byte array, a 1 st bit indicates that the integer data belongs to a non-negative integer or a negative integer, 2 nd to 4 th bits indicate a complementary byte length, 5 th to 8 th bits indicate the highest 4 bits of the integer data, a length of the byte array is equal to the complementary byte length plus 1, an absolute value of the integer data is composed of a complement value and a difference value, the byte array, except the 1 st byte, and subsequent bytes, together with the 5 th to 8 th bits of the 1 st byte, constitute the difference value of the integer, the complement value being determined according to the complementary byte length, wherein in order of byte lengths from small to large, a complement value of each byte length is a maximum value expressed by a last byte length plus 1, wherein a length of a shortest byte array is 1 byte, the length of the longest byte array is 8 bytes;

a storage device for storing the integer data converted into a byte array into the database.

6. An apparatus as claimed in claim 5, wherein: the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data is converted is.

7. An apparatus as claimed in claim 5, wherein: the order of the sizes of the integers under the same sign is represented by the order of the byte lengths from small to large, and the sign comprises a non-negative integer and a negative integer.

8. An apparatus as claimed in claim 7, wherein: sorting the integer data under different signs from small to large separately, sorting the nonnegative integers in sequence, and sorting the negative integers in reverse order to realize the ordered comparison of the integers under the same sign.

9. An integer variable-length ordered coding device based on byte arrays, which is used for storing integer data in a database, and is characterized in that:

comprises a processor and a memory;

the memory stores a computer program that is executed by the processor to implement the method of any of claims 1-4.

10. A computer storage medium, in which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 4.

Technical Field

The present application relates to the field of data storage, and in particular, to a byte array based integer variable length ordered coding method, apparatus, and storage medium.

Background

Currently, in a NoSQL database, bottom layers such as HBase, RocksDB, LevelDB and the like are data formats mainly supporting byte arrays, and other data types need to be converted into byte arrays for storage. For integers, it is common to convert to fixed length arrays of bytes by Integer type, such as Integer (Integer) to 4-byte arrays, and Long Integer (Long) to 8-byte arrays.

Conversion to a fixed length byte array may enable the size of integers to be compared by direct comparison of the byte arrays without the need to convert the value byte array to integers in advance. However, many times, because it is uncertain whether an integer exceeds 4 bytes (i.e., the maximum value 4294967295), if direct comparison is needed, a long integer, i.e., 8 bytes, is uniformly used to store the integer, and if most of the integer values are small, the situation of space occupation is wasted.

In some databases or storage engines, the last byte of a byte is distinguished by encoding every 7 bits from lowest to highest in an integer into the last 7 bits of the byte, with the first bit of the byte being set to 1. The encoding mode not only realizes variable-length byte storage, but also realizes the function of identifying the integer encoding boundary according to the byte characteristics, namely, the byte length of a certain integer encoded in the byte array is judged according to the byte most significant bit, and the scene is suitable for the scene of encoding the integer and other values together. But this encoding approach does not allow for direct sorting of integers by byte array.

Therefore, it is desirable to design a scheme for converting integer data into a byte array, so that the byte length occupied by the integer can be known according to the first byte of the byte array, and the size of the integer can be directly sorted according to the byte number.

Disclosure of Invention

The method comprises the steps that analysis is carried out based on multiple requirements of variable length coding, byte array sequence ordering, integer coding boundary and the like, the coding mode is designed, the coding mode supports variable length coding, the minimum length only needs 1 byte, the maximum length needs 8 bytes, the maximum value of coding is 1157442765409226767, the minimum value is-1157442765409226767, the size of more than 60 bits is enough to support most integer scenes; the byte array sequence ordering is supported, and the comparison of the integers coded in the same symbol can be realized according to the ordering comparison of the byte arrays; and an integer coding boundary is supported, and the byte length occupied by the integer can be known according to the first byte of the byte array. The coding mode can realize low storage and query under a certain scene.

In a first aspect, the present application designs a byte array-based integer variable-length ordered coding method for storing integer data in a database, which is characterized in that: receiving integer data input to a database;

converting the received integer data into a byte array, in a 1 st byte of the byte array, the 1 st bit represents that the integer data belongs to a non-negative integer or a negative integer, the 2 nd to 4 th bits represent a complementary byte length, the 5 th to 8 th bits represent the highest 4 bits of the integer data, the length of the byte array is equal to the complementary byte length plus 1, the absolute value of the integer data is composed of the addition of a complementary value and a difference value, the byte array except the 1 st byte, the following bytes and the 5 th to 8 th bits of the 1 st byte together form the difference value of the integer, the complement value is determined according to the length of the complement byte, wherein, in the order of the byte lengths from small to large, the complement value of each byte length is the maximum value expressed by the last byte length plus 1, wherein the length of the shortest byte array is 1 byte, and the length of the longest byte array is 8 bytes; and storing the integer data converted into the byte array into the database.

In an alternative embodiment, it further comprises: the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data is converted is.

In an alternative embodiment, it further comprises: the order of the sizes of the integers under the same sign is represented by the order of the byte lengths from small to large, and the sign comprises a non-negative integer and a negative integer.

In an alternative embodiment, it further comprises: sorting the integer data under different signs from small to large separately, sorting the nonnegative integers in sequence, and sorting the negative integers in reverse order to realize the ordered comparison of the integers under the same sign.

In a second aspect, the present application designs a byte array-based integer variable-length ordered coding apparatus for storing integer data in a database, wherein: receiving means for receiving integer data input to a database; conversion means for converting the received integer data into a byte array, in a 1 st byte of the byte array, a 1 st bit indicates that the integer data belongs to a non-negative integer or a negative integer, 2 nd to 4 th bits indicate a complementary byte length, 5 th to 8 th bits indicate the highest 4 bits of the integer data, a length of the byte array is equal to the complementary byte length plus 1, an absolute value of the integer data is composed of a complement value and a difference value, the byte array, except the 1 st byte, and subsequent bytes, together with the 5 th to 8 th bits of the 1 st byte, constitute the difference value of the integer, the complement value being determined according to the complementary byte length, wherein in order of byte lengths from small to large, a complement value of each byte length is a maximum value expressed by a last byte length plus 1, wherein a length of a shortest byte array is 1 byte, the length of the longest byte array is 8 bytes; a storage device for storing the integer data converted into a byte array into the database.

In an alternative embodiment, it further comprises: the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data is converted is.

In an alternative embodiment, it further comprises: the order of the sizes of the integers under the same sign is represented by the order of the byte lengths from small to large, and the sign comprises a non-negative integer and a negative integer.

In an alternative embodiment, it further comprises: sorting the integer data under different signs from small to large separately, sorting the nonnegative integers in sequence, and sorting the negative integers in reverse order to realize the ordered comparison of the integers under the same sign.

In a third aspect, the present application designs a byte array-based integer variable-length ordered coding apparatus for storing integer data in a database, which is characterized in that: comprises a processor and a memory; the memory stores a computer program that is executed by the processor to implement the method according to the first aspect of the application.

In a fourth aspect, the present application contemplates a computer storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the method according to the first aspect of the present application.

According to the invention, byte array variable length coding is carried out on the integer data input into the database, the byte length of the byte array can be confirmed through the 1 st byte of the byte array, and the size comparison between the integer data corresponding to the byte array can be directly carried out through the byte array.

Drawings

In the drawings, which are not necessarily drawn to scale, like reference numerals may describe similar components in different views. Like reference numerals having letter suffixes or different letter suffixes may represent different instances of similar components. The drawings illustrate various embodiments generally by way of example and not by way of limitation, and together with the description and claims serve to explain the disclosed embodiments. The same reference numbers will be used throughout the drawings to refer to the same or like parts, where appropriate. Such embodiments are illustrative, and are not intended to be exhaustive or exclusive embodiments of the present apparatus or method.

Fig. 1 shows a flow chart of a method for byte array based variable length ordered coding of integers according to the invention.

Fig. 2 is a schematic structural diagram of an apparatus for byte array-based variable-length ordered coding of integers according to the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.

Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present invention. It will be understood by those skilled in the art that the present invention may be practiced without some of these specific details. In some instances, methods, procedures, components, and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present invention.

Referring to fig. 1, a flow chart of a method for byte array based integer variable length ordered coding according to the invention is shown.

S101, receiving integer data input into a database. The database includes NoSQL database, such as HBsae, RocksDB, LevelDB, and other KV databases, in which values are stored in byte arrays.

S102, converting the received integer data into a byte array.

Each byte of the byte array comprises 8 bits, in the 1 st byte of the byte array, the 1 st bit represents that the integer data corresponding to the byte array belongs to a non-negative integer or a negative integer, the 2 nd to 4 th bits represent complementary byte length, and the 5 th to 8 th bits represent the highest 4 bits of the integer data. The byte length of the byte array after conversion of each integer data is equal to the length of a complementary byte in the 1 st byte of the byte array plus 1, the absolute value of the integer data is formed by adding a complementary value and a difference value, the byte array except the 1 st byte, the subsequent bytes and the 5 th to 8 th bits of the 1 st byte form the difference value of the integer, the complementary value is determined according to the length of the complementary byte, wherein the complementary value of each byte length is the maximum value expressed by the length of the last byte plus 1 in the sequence of the byte lengths from small to large, the length of the shortest byte array is 1 byte, and the length of the longest byte array is 8 bytes.

For example, the integer 7 is encoded into a byte array of 1 byte, the 1 st bit of the byte is 1, which indicates that the byte is a non-negative integer, wherein 0 is also set as a non-negative integer when encoded into the byte array, the 1 st bit of the 1 st byte is 0, which indicates that the byte is a negative integer, the 2 nd to 4 th bits of the byte corresponding to the integer 7 are all 0, which indicates that the complementary byte length is 0, and the addition of 1 is the byte array length 1 corresponding to the integer, and the 5 th to 8 th bits are 0,1,1,1, respectively. The integer 20 is encoded into a byte array of 2 bytes, the 1 st bit of the 1 st byte is 1 and is represented as a non-negative integer, the 2 nd to 4 th bits are 0,0,1 respectively and represent that the length of the complementary byte is 1, the length of the complementary byte plus 1 is the corresponding byte length 2, the 5 th to 8 th bits are 0,0,0,0, 2 nd bits are 0,0,0,0,0, 1, 0,0, the 1 st to 8 th bits of the 2 nd byte are 0,0,0,0, 1, 0,0, the last four bits of the 1 st byte and the 2 nd byte form an integer difference 4, the complementary value is the length of the last byte, that is, the maximum value expressed by the length of the 1 byte plus 1 is 15, the maximum value expressed by the length of the 1 byte is 16, the difference 4 plus the complementary value 16 is the absolute value 20 of the integer data expressed by the byte array, and other bytes are analogized in sequence and are not repeated.

For the length of the byte array, the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data conversion is.

In order to realize ordered comparison and query under the same sign, the sign comprises nonnegative integer data and negative integer data, the order of the size of the integers under the same sign is usually expressed by the order of byte length from small to large, the integer data under different signs are separately ordered from small to large, the nonnegative integers are ordered in the order, and the negative integers are ordered in the reverse order, so that the ordered comparison of the integers under the same sign is realized.

S103, storing the integer data converted into the byte array into the database.

The specific coding rule of the byte array-based integer variable-length ordered coding is as follows:

1) in the 1 st byte of the byte array, the 1 st bit represents positive and negative, the 2 nd to 4 th bits represent complementary byte length, and the 5 th to 8 th bits represent the highest 4 bits of the integer value.

2) The length of the byte array is determined according to the length of the complementary byte in the 1 st byte, i.e. the length of the byte array is equal to the length of the complementary byte plus 1.

3) The absolute value of the integer value consists of the addition of the complement and difference values. Except for the 1 st byte, the subsequent bytes of the byte array and the 5 th-8 th bits of the 1 st byte form difference values of integer values; the complement is determined according to the length of the complement byte.

4) In the order of the byte lengths from small to large, the complement value of each byte length is the maximum value which can be expressed by the last byte length and is added with 1; and the maximum value that can be expressed by the current byte length is the complement value plus the maximum value of the integer that can be expressed by the data portion in the current byte array (i.e., the maximum value of the difference).

The encoding algorithm is as follows:

// coding integer Java pseudo code

public static byte[] encodeVarOrderedBytes(long val) {

if (val == Long.MAX_VALUE || val == Long.MIN_VALUE) {

throw new IllegalArgumentException("unsupported number range");

}

byte[] b;

boolean negative = (val < 0);

long value = (val < 0 (-val) : val);

int length = 0;

if (value < (1L << 4)) {

length = 1;

} else if (value < ((1L << 12) + (1L << 4))) {

length = 2;

} else if (value < ((1L << 20) + (1L << 12) + (1L << 4))) {

length = 3;

} else if (value < ((1L << 28) + (1L << 20) + (1L << 12) + (1L << 4))) {

length = 4;

} else if (value < ((1L << 36) + (1L << 28) + (1L << 20) + (1L << 12) + (1L << 4))) {

length = 5;

} else if (value < ((1L << 44) + (1L << 36) + (1L << 28) + (1L << 20) + (1L << 12) + (1L << 4))) {

length = 6;

} else if (value < ((1L << 52) + (1L << 44) + (1L << 36) + (1L << 28) + (1L << 20) + (1L << 12) + (1L << 4))) {

length = 7;

} else if (value < ((1L << 60) + (1L << 52) + (1L << 44) + (1L << 36) + (1L << 28) + (1L << 20) + (1L << 12) + (1L << 4))) {

length = 8;

} else {

throw new IllegalArgumentException("unsupported number range");

}

b = new byte[length];

long v = value;

for (int i = 0; i < length - 1; i++) {

v = v - (1L << (8 * i + 4));

}

b[0] = (byte) (((length - 1) << 4) | v >> ((length - 1) * 8));

for (int i = 1; i < length; i++) {

b[i] = (byte) (v >> ((length - i - 1) * 8));

}

if (!negative) {

b[0] = (byte) (b[0] | 0x80);

}

return b;

}

The decoding algorithm is as follows:

// decoding integer Java pseudo code

public static long decodeVarOrderedBytes(byte[] val) {

boolean negative = (((b[offset] >> 7) & 0x01) == 0);

int addLen = ((b[offset] >> 4) & 0x07);

long v = 0;

switch (addLen) {

case 0: {

v = (long) b[offset] & 0x0f;

break;

}

case 1:

case 2:

case 3:

case 4:

case 5:

case 6:

case 7: {

v = (((long) b[offset] & 0x0f) << (addLen * 8));

for (int i = 0; i < addLen; i++) {

v += ((long) (b[offset + i + 1] & 0xff) << ((addLen - 1 - i) * 8)) + (1L << (4 + 8 * i));

}

break;

default: {

throw new IllegalArgumentException("unsupported number range");

}

}

return negative -v : v;

}

Let v be an integer value, L be the byte array length after encoding, and C be the complement byte array length. As can be seen from the encoding rules: l = C + 1.

For a certain byte array length interval, V represents the value size, CV represents the complement value size, DV represents the difference value size, MAXV and MINV represent the maximum value and the minimum value of integers which can be represented by the interval, MAXCV and MINCV represent the maximum value and the minimum value of the complement value, MAXDV and MINDV represent the maximum value and the minimum value of the difference value, and R is the value range of the interval. The demonstration process is as follows:

one, in the case of non-negative integers, demonstrates uniqueness and order.

1. Expressing uniqueness, namely proving that only one integer value corresponds to only one byte array, the method comprises the following two parts:

a. the integer values represented by any of the different byte arrays are proven to be different and unique as follows:

1) if Lm and Ln are adjacent, i.e., Ln = Lm +1, then MINVn = MAXVm +1, i.e., Rm and Rn are continuously non-coincident, according to the rule.

2) If Lm and Ln are not adjacent, continuous intervals between Lm and Ln, namely L (m +1), L (m +2) and L (m +3) … L (n-1) can be found out, so that a continuous value domain space is formed, and Rm is proved to be not overlapped with Rn.

3) From the above two descriptions, the byte arrays with different lengths represent integer values in different intervals, and the rules show that the first byte of the byte arrays with different lengths is different inevitably.

4) Since any value within the interval V = CV + DV. The CV is the same within the interval, and the DV is different if the value part of the byte array is different, resulting in a difference in V. I.e. any array of bytes can only be represented as a single integer.

b. It is demonstrated that the byte arrays encoded by any of the different integer values are different, as follows:

1) according to the coding rule and algorithm, the length of the coded byte array of any integer value V is determined by the interval of the value, namely, one integer value V cannot be coded into byte arrays with different lengths at the same time.

2) According to V = CV + DV, and the CV values in the interval are the same. I.e., any integer value V, whose DV value is unique, can only be encoded as a portion of the value in a unique byte array.

3) And combining the two, namely any integer only corresponds to a unique byte array.

2. Orderliness, i.e., proving endian size represents an integer value size. Let the byte array Bj be converted from the value j, Bi from the value i, and Bj > Bi in the endian as proved as follows:

1) if the first 4 bits of the first byte of the byte array are different, i.e., (Bj1> > >4) > (Bi1> > >4), the length of the byte array is different according to the encoding rule. Let Bj be the length n and Bi be the length m. Since the length of the byte array is consistent with the ascending order of the interval values, that is, if n > m, the value ranges Rn are all larger than Rm. Thus, it is verified that j > i.

2) If the first 4 bits of the first byte of the byte array are the same, i.e. (Bj1> > >4) = (Bi1> > >4), then the bit values of the value part of the byte array are different, as known from the encoding rule. Let the bit values of both be BVj and BVi, i.e. BVj is greater than BVi, the magnitude order of the values is the same, i.e. j > i.

The second and the above proofs are all carried out on the premise of non-negative numbers, and it needs to be proved that the array intervals of the negative numbers and the non-negative numbers do not intersect, and meanwhile, the intervals of the negative numbers still meet the uniqueness and the orderliness.

1. No crossovers, as demonstrated below:

because the first digits of the first bytes of the negative numbers and the non-negative numbers are different, namely, the intervals of the negative numbers and the non-negative numbers do not intersect.

2. Uniqueness, demonstrated as follows:

1) for any negative number V, its absolute value, V, is represented by a unique one byte array with a first byte leading by 1, according to previous proofs. Then V is represented by a single byte array whose byte array value is the same as that of-V, except that the first byte head is set to 0.

2) For any byte array, if its first byte first is 1, then it represents a unique non-negative integer value V, according to previous proof. If the first byte position is 0, the unique value represented when the first byte position is 1 is set as V, and the unique negative integer value represented by the original byte array is-V.

3. And ordering, namely setting a byte array Bj converted from a value j, Bi converted from a value i, Bj > Bi in the byte order, and i and j are negative integers. The following was demonstrated:

1) since the first byte is the same in first position, when the first byte is set to 1, the values are-i and-j, respectively.

2) If Bj > Bi, -j > -i, i.e., i > j. It follows that when both values are negative integers, the inverse ordering of the byte array is satisfied, i.e. the larger the endianness of the byte array, the smaller the negative integer value.

According to the encoding rule, the smaller the absolute value is, the smaller the byte array length is, and the byte array length boundary of the expressed integer can be judged according to the first byte; according to the above proof results, the encoding method can realize the consistency between the size of the integer value and the encoding byte order under the condition of the same sign (the order is in the case of non-negative integers, and the reverse order is in the case of negative integers), and can realize the ordered range comparison and query under the same sign.

The disadvantage of this coding scheme is that the order is different for integers with different symbols. One solution under the circumstance is that the method can be divided into a non-negative integer comparison part and a negative integer comparison part, ordered comparison is carried out twice, and performance loss caused by inconsistency of a comparison sequence and a storage sequence can be reduced to a certain extent.

FIG. 2 is a schematic diagram of the structure of the byte array-based integer variable-length ordered coding apparatus for storing integer data in a database according to the present invention.

Receiving means 201 for receiving integer data input to the database. The database includes NoSQL database, such as HBsae, RocksDB, LevelDB, and other KV databases, in which values are stored in byte arrays.

A conversion device 202, configured to convert the received integer data into a byte array.

Each byte of the byte array comprises 8 bits, in the 1 st byte of the byte array, the 1 st bit represents that the integer data corresponding to the byte array belongs to a non-negative integer or a negative integer, the 2 nd to 4 th bits represent complementary byte length, and the 5 th to 8 th bits represent the highest 4 bits of the integer data. The byte length of the byte array after conversion of each integer data is equal to the length of a complementary byte in the 1 st byte of the byte array plus 1, the absolute value of the integer data is formed by adding a complementary value and a difference value, the byte array except the 1 st byte, the subsequent bytes and the 5 th to 8 th bits of the 1 st byte form the difference value of the integer, the complementary value is determined according to the length of the complementary byte, wherein the complementary value of each byte length is the maximum value expressed by the length of the last byte plus 1 in the sequence of the byte lengths from small to large, the length of the shortest byte array is 1 byte, and the length of the longest byte array is 8 bytes.

For the length of the byte array, the smaller the absolute value of the integer data is, the shorter the length of the byte array after the integer data conversion is.

In order to realize ordered comparison and query under the same sign, the sign comprises nonnegative integer data and negative integer data, the order of the size of the integers under the same sign is usually expressed by the order of byte length from small to large, the integer data under different signs are separately ordered from small to large, the nonnegative integers are ordered in the order, and the negative integers are ordered in the reverse order, so that the ordered comparison of the integers under the same sign is realized.

A storage device 203 for storing the integer data converted into the byte array into the database.

It should be understood that the structure of the apparatus for byte array based variable length ordered coding of integers of the above example is only one example provided by the embodiments of the present invention, and may have more or less components than those shown, may combine two or more components, or may have different configurations of components. As in a database, comprising a processor and a memory, the memory storing a computer program that the processor executes to implement the method of byte array based integer variable length ordered coding of the present invention.

The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware or in software executed by a processor. The software instructions may be comprised of corresponding software modules that may be stored in a Random Access Memory (RAM), a flash Memory, a Read Only Memory (ROM), an Erasable Programmable ROM (EPROM), an Electrically Erasable Programmable ROM (EEPROM), a register, a hard disk, a removable hard disk, a compact disc Read Only Memory (CD-ROM), or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. Of course, the storage medium may also be integral to the processor.

The embodiments of the present invention have been described above. These examples are for illustrative purposes only and are not intended to limit the scope of the present invention. The scope of the invention is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the invention, and such alternatives and modifications are intended to be within the scope of the disclosure.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于PostgreSQL的地理编码方法和系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!