CN117973317B - Character string information processing method, device, electronic equipment and storage medium - Google Patents

Character string information processing method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117973317B
CN117973317B CN202410370793.XA CN202410370793A CN117973317B CN 117973317 B CN117973317 B CN 117973317B CN 202410370793 A CN202410370793 A CN 202410370793A CN 117973317 B CN117973317 B CN 117973317B
Authority
CN
China
Prior art keywords
length
storage space
character string
storage
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410370793.XA
Other languages
Chinese (zh)
Other versions
CN117973317A (en
Inventor
庄铭宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hundsun Technologies Inc
Original Assignee
Hundsun Technologies Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hundsun Technologies Inc filed Critical Hundsun Technologies Inc
Priority to CN202410370793.XA priority Critical patent/CN117973317B/en
Publication of CN117973317A publication Critical patent/CN117973317A/en
Application granted granted Critical
Publication of CN117973317B publication Critical patent/CN117973317B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a character string information processing method, a device, an electronic device and a storage medium, wherein the method comprises the following steps: determining the remaining length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space, determining the length storage space and the length storage information in the preset character storage space according to the remaining length, wherein the length storage information is used for indicating the numerical value stored on each byte in the length storage space, the length storage information is used for representing the remaining length, storing the target character string into the preset character storage space, and storing the length storage information in the length storage space. The application stores the length storage information in the length storage space with variable length, thereby realizing the purpose of storing longer characters on the premise of being compatible with the history code environment. The method has the capability of not reducing the storage function and supporting quick reading of the character string length.

Description

Character string information processing method, device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer data processing technologies, and in particular, to a method and apparatus for processing character string information, an electronic device, and a storage medium.
Background
In the data structure, the length information of the character string is usually required to be stored in a separate storage structure, and a common storage structure is to store the length information of the character string by using a fixed-length array.
Currently, one storage method is to store the string length information after the fixed-length character string is assembled. Such as FaceBook Open-source Library (Folly) strings, which can be used to treat the zero end of a string after the string is filled in an array as the remaining length 0 in a short string mode, so that the conventional string is compatible and the length information is stored.
However, the above conventional method for storing character string length information generally only supports character strings having a storage length of 255 or less, and cannot be compatible with longer character strings.
Disclosure of Invention
The application aims to solve the problem that the prior art cannot be compatible with the storage of character string length information with the length of more than 255.
In order to achieve the above purpose, the technical scheme adopted by the application is as follows:
in a first aspect, the present application provides a method for processing character string information, the method comprising:
Determining the residual length of a preset character storage space according to the first length of a target character string and the second length of the preset character storage space;
Determining a length storage space and length storage information in the preset character storage space according to the residual length, wherein the length storage information is used for indicating numerical values stored on each byte in the length storage space, and the length storage information is used for representing the residual length;
and storing the target character string into the preset character storage space, and storing the length storage information in the length storage space.
Optionally, the determining the length storage space and the length storage information in the preset character storage space according to the remaining length includes:
And determining the length storage space and the length storage information according to the residual length and a preset value.
Optionally, the determining the length storage space and the length storage information according to the remaining length and the preset value includes:
If the remaining length is 0, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 0;
if the remaining length is 1, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 1;
If the remaining length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the value stored in each byte in the plurality of bytes according to the remaining length and the preset value.
Optionally, the plurality of bytes includes: last byte and last byte;
The determining the value stored in each byte of the plurality of bytes according to the remaining length and the preset value includes:
calculating the sum of the residual length and the maximum storage value of the bytes;
Taking the result of rounding the ratio of the sum to the preset value as the value stored in the last byte;
And taking the modulo result of the sum and the preset value as the value stored in the last byte.
Optionally, the determining the remaining length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space includes:
Determining the storage occupation length of the character string according to the first length;
and subtracting the storage occupied length from the second length to obtain the remaining length.
Optionally, the method further comprises:
Responding to the request information for reading the target character string, and determining the length information of the target character string according to the numerical values stored in each byte in the length storage space;
And reading the target character string from the preset character storage space according to the length information of the target character string.
Optionally, the determining the length information of the target character string according to the values stored in the bytes in the length storage space includes:
If the value stored in the last byte is 0, determining that the storage occupied length of the target character string is the second length, and determining the length information of the target character string according to the storage occupied length;
If the value stored in the last byte is greater than or equal to 1, determining the length information of the target character string according to the value stored in each byte in the length storage space and a preset value.
Optionally, the determining the length information of the target string according to the value stored in each byte in the length storage space and the preset value includes:
Calculating the product of the value stored in the last byte and a preset value;
Calculating the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte;
Subtracting the maximum stored value of the byte from the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte to obtain an intermediate result;
And taking the result of subtracting the intermediate result from the second length as the storage occupation length of the target character string, and determining the length information of the target character string according to the storage occupation length.
In a second aspect, the present application provides a character string information processing apparatus, the apparatus comprising:
The first determining module is used for determining the residual length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space;
the second determining module is used for determining a length storage space and length storage information in the preset character storage space according to the residual length, wherein the length storage information is used for indicating numerical values stored on each byte in the length storage space, and the length storage information is used for representing the residual length;
and the storage module is used for storing the target character string into the preset character storage space and storing the length storage information in the length storage space.
Optionally, the second determining module is specifically configured to:
And determining the length storage space and the length storage information according to the residual length and a preset value.
Optionally, the second determining module is specifically configured to:
If the remaining length is 0, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 0;
if the remaining length is 1, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 1;
If the remaining length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the value stored in each byte in the plurality of bytes according to the remaining length and the preset value.
Optionally, the plurality of bytes includes: last byte and last byte;
optionally, the second determining module is specifically configured to:
calculating the sum of the residual length and the maximum storage value of the bytes;
Taking the result of rounding the ratio of the sum to the preset value as the value stored in the last byte;
And taking the modulo result of the sum and the preset value as the value stored in the last byte.
Optionally, the first determining module is specifically configured to:
Determining the storage occupation length of the character string according to the first length;
and subtracting the storage occupied length from the second length to obtain the remaining length.
Optionally, the storage module is further configured to:
Responding to the request information for reading the target character string, and determining the length information of the target character string according to the numerical values stored in each byte in the length storage space;
And reading the target character string from the preset character storage space according to the length information of the target character string.
Optionally, the storage module is specifically configured to:
If the value stored in the last byte is 0, determining that the storage occupied length of the target character string is the second length, and determining the length information of the target character string according to the storage occupied length;
If the value stored in the last byte is greater than or equal to 1, determining the length information of the target character string according to the value stored in each byte in the length storage space and a preset value.
Optionally, the storage module is specifically configured to:
Calculating the product of the value stored in the last byte and a preset value;
Calculating the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte;
Subtracting the maximum stored value of the byte from the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte to obtain an intermediate result;
And taking the result of subtracting the intermediate result from the second length as the storage occupation length of the target character string, and determining the length information of the target character string according to the storage occupation length.
In a third aspect, the present application provides an electronic device, comprising: the system comprises a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device runs, the processor and the memory are communicated through the bus, and the processor executes the machine-readable instructions to execute the steps of the character string information processing method.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the character string information processing method as described above.
The beneficial effects of the application are as follows: the method comprises the steps of firstly determining the residual length of a preset character storage space according to the first length of a target character string and the second length of the preset character storage space, then determining the length storage space and length storage information according to the residual length, storing the target character string into the preset character storage space, and storing the length storage information into the length storage space. The present embodiment determines the length storage space using the remaining length, and since at least one byte is included in the length storage space, the number of bytes can be determined according to the remaining length, and thus the size of the length storage space is variable. Furthermore, when the effective character string length exceeds 255, the length storage information of the character string can be stored in the character string, so that the aim of storing longer characters on the premise of being compatible with the history code environment is fulfilled. The method has the capability of not reducing the storage function and supporting quick reading of the character string length.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of a character string information processing method according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of determining a length storage space and length storage information according to an embodiment of the present application;
FIG. 3 is a flow chart for determining values stored in each of a plurality of bytes according to an embodiment of the present application;
fig. 4 is a schematic flow chart of determining length information of a target character string according to an embodiment of the present application;
Fig. 5 is a schematic structural diagram of a character string information processing apparatus according to an embodiment of the present application;
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the drawings in the present application are for the purpose of illustration and description only and are not intended to limit the scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this disclosure, illustrates operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to or removed from the flow diagrams by those skilled in the art under the direction of the present disclosure.
In addition, the described embodiments are only some, but not all, embodiments of the application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by a person skilled in the art without making any inventive effort, are intended to be within the scope of the present application.
It should be noted that the term "comprising" will be used in embodiments of the application to indicate the presence of the features stated hereafter, but not to exclude the addition of other features.
In the prior art, various character string storage methods with lengths are included, wherein the storage of character string length information in a fixed-length array of characters is followed by a storage method capable of being compatible with a history code environment. In this method, the Folly string of FaceBook can treat the zero end of the string after the string is filled in the array as the residual length 0 in the short string mode, so that the conventional string is compatible and the length information is stored.
However, the length information of the character string is stored in the manner of storing Folly character strings of FaceBook, only one byte is used for storing the length information of the character string, and the stored value range of one byte is 0-255, so that only character strings with the stored length within 255 can be supported, and longer character strings cannot be compatible.
Based on the above, the application provides a character string information processing method, which can be applied to an electronic device with computing capability, and the method determines the length storage space and the length storage information in the preset character storage space through the calculated residual length of the preset character storage space, and then stores the length storage information of the target character string into the preset character storage space. According to the application, the length storage information is stored in the length storage space in the character string, and when the character string and the character string length information are read, the length storage information can be directly read from the length storage space, so that the character string can be read according to the length storage information. The application does not limit the length of the preset character storage space and the length storage space, so when the length of the character string exceeds the maximum value which can be stored in a single byte, namely 255, the length information of the character string can be stored in the character string, thereby realizing the aim of being compatible with longer character strings on the premise of being compatible with the history code environment.
Fig. 1 is a flow chart of a character string information processing method according to an embodiment of the present application. The specific steps of the above-described character string information processing method will be described below with reference to fig. 1.
S101, determining the residual length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space.
The target string may be an effective string input by an upper layer, and the first length is a length of the effective string.
The preset character storage space may be a maximum space occupied by a preset valid character, and the second length is a length of the maximum space occupied by the valid character.
It should be appreciated that the second length is greater than the first length so that the target character string may be stored in the preset character storage space.
Alternatively, the remaining length of the preset character storage space represents the length of the space in the preset character storage space that can also be filled with valid characters.
It is noted that when a string ends, an end identifier is typically added at the end, which occupies one byte. Illustratively, the end identifier may be "0".
As an example, if the content "hello" is stored in the character string char [6], the second length of the preset character storage space is 6, the first length of the target character string is 5, and considering the end identifier that needs to occupy one byte, the remaining length of the preset character storage space is 0. If the content "hel" is stored in the character string char 6, the first length of the target character string is 3, and considering the end identifier of the one-bit character, the remaining length of the preset character storage space is 2.
S102, determining a length storage space and length storage information in a preset character storage space according to the residual length, wherein the length storage information is used for indicating numerical values stored on bytes in the length storage space, and the length storage information is used for representing the residual length.
The length storage space refers to a space for storing length storage information in the above-mentioned preset character storage space, that is, the length storage space is a part of the above-mentioned preset character storage space. Further, the length storage space may be composed of a plurality of bytes. The number of bytes required to store the length storage information can be determined from the remaining length, thereby determining the size of the length storage space. That is, the number of bytes may be changed according to the change of the remaining length, thereby changing the size of the length storage space. It should be appreciated that the length storage space should not be greater than the preset character storage space.
It is noted that the length storage space is positively correlated with the remaining length, and when the remaining length is less than the first preset length threshold, the length storage space is 1 character, and when the remaining length is greater than the first preset length threshold and less than the second preset length threshold, the length storage space is 2 characters. The first preset length threshold may be 1, or may be a maximum value 255 that can be stored in a single byte.
The length storage information is used to indicate the values stored on the bytes in the length storage space.
Illustratively, when the length storage space indicates that the length storage information should be stored in consecutive bytes of the last two bits of the character string, then the length storage information includes the value of the byte stored in the last bit and the value of the byte stored in the next-to-last bit.
It should be noted that the length storage information does not directly store the length, but characterizes the remaining length in the form of a value stored in the length storage space, so that the length information of the target character string is calculated according to the length storage information.
As an alternative embodiment, the electronic device may read the values stored on all bytes and determine the remaining length of the preset character storage space based on the read values. Further, the length information of the target character string may be determined according to the remaining length of the preset character storage space.
S103, storing the target character string into a preset character storage space, and storing length storage information in a length storage space.
After determining the length storage space and the length storage information in the preset character storage space, the target character string input by the upper layer may be stored in the preset character storage space. Specifically, the target character string may be stored sequentially from the first byte in the preset character storage space until the last character of the character string is stored, and then an end identifier is added after the last character.
Meanwhile, the length storage information can be stored in the length storage space, specifically, the numerical value in the corresponding length storage information is stored in each byte in the length storage space, so that the remaining length in the current preset character storage space is represented by the numerical value stored in each byte.
In this embodiment, the remaining length of the preset character storage space is determined according to the first length of the target character string and the second length of the preset character storage space, then the length storage space and the length storage information are determined according to the remaining length, the target character string is stored in the preset character storage space, and the length storage information is stored in the length storage space. The present embodiment determines the length storage space using the remaining length, and since at least one byte is included in the length storage space, the number of bytes can be determined according to the remaining length, and thus the size of the length storage space is variable. Furthermore, when the effective character string length exceeds 255, the length storage information of the character string can be stored in the character string, so that the aim of storing longer characters on the premise of being compatible with the history code environment is fulfilled. The method has the capability of not reducing the storage function and supporting quick reading of the character string length.
As an optional implementation manner, the method for determining the length storage space and the length storage information in the preset character storage space according to the remaining length in the step S102 is as follows:
And determining the length storage space and the length storage information according to the residual length and the preset value.
Alternatively, the preset value may be a category number of values that the bytes can store, that is, 256, so that values of 0-255 may be stored in the bytes, and 255 is the byte maximum stored value. Further, the length storage space and the length storage information may be determined according to the maximum storage value of the remaining length and 256.
As another alternative embodiment, the length storage space may be determined according to the second length of the preset character storage space and 256. Specifically, when the preset character storage space is smaller than the number of kinds of numerical values that one byte can store, the length storage space may be set to one byte. When the preset character storage space is larger than the number of kinds of numerical values that one byte can store and smaller than the number of kinds of numerical values that two bytes can store, the length storage space may be set to 2 bytes. Wherein the category number of the values that the two bytes can store may be 65535 different from the maximum stored value of the single byte, which is 255, and 65280.
As a further alternative embodiment, when the second length of the preset character storage space exceeds 65280, the stored content in the bytes may be split, and the split result may be respectively stored in 3 bytes located at the end of the character string and connected in sequence, and the 3 bytes may be used as the length storage space. Specifically, the lower 7 bits and the upper remaining bits of the last byte, i.e., the last byte stores 1-127 as the remaining storage length of the penultimate byte and 128-255 stores the remaining storage length of the penultimate byte, may be split. By the storage method, the character string compatible length of the method can be expanded to 8322817, and the preset character storage space can store 23 bits and is close to the character length of 8 megabytes. Where 8322817 is the square of the maximum memory space of a single byte, the product of 127, and the difference from the maximum memory value of a single byte, i.e., 256×256×127-255= 8322817.
In this embodiment, the length storage space and the length storage information are determined according to the remaining length and the preset number, so that the unique length state of the character string is determined, and ambiguity in reading the length storage information of the character string is avoided.
In order to clearly explain how to determine the length storage space and the length storage information according to the remaining length and the preset value, fig. 2 is a schematic flow chart of determining the length storage space and the length storage information according to the embodiment of the present application, and three possible cases of the remaining length are sequentially described with reference to fig. 2:
S201, if the remaining length is 0, determining the length storage space as the last byte in the preset character storage space, and the value indicated by the length storage information is 0.
When the residual length is 0, the character is characterized in the current preset character storage space, the target character string and the end identifier can be completely stored in the current preset character storage space, and no space of residual bytes exists, so that other characters cannot be continuously stored. Therefore, the last byte in the preset character storage space can be taken as the length storage space. Wherein the last byte is the last byte in the preset character storage space.
At this time, the value indicated by the length storage information may be the end identifier stored in the last storage unit, that is, 0.
When the value stored in the last byte is read to be 0 when the length storage information is read, it can be stated that the remaining length in the currently preset character storage space is 0.
S202, if the remaining length is 1, determining the length storage space as the last byte in the preset character storage space, and the value indicated by the length storage information is 1.
If the remaining length is 1, the character is represented in the current preset character storage space, the target character string and the end identifier can be completely stored in the current preset character storage space, and one byte space remains, and one character can be stored in the byte space. Therefore, the last byte in the preset character storage space can be taken as the length storage space. And stores the length storage information, i.e., the value 1, in the length storage space.
At this time, in the current preset character storage space, the end identifier, that is, the storage value is 0, is stored in the last byte. The last byte is the byte preceding the last byte.
When the value stored in the last byte is read to be 1 and the value stored in the next last byte is read to be 0 in reading the length storage information, it may be indicated that the remaining length in the current preset character storage space is 1.
And S203, if the residual length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the numerical value stored in each byte in the plurality of bytes according to the residual length and the preset numerical value.
If the remaining length is greater than 1, the target character string and the end identifier are represented in the current preset character storage space, and more than one byte of space is left.
As an alternative embodiment, the length storage space may be determined according to the maximum storage value of the remaining length, i.e. the number of consecutive bytes starting from the last storage space in the preset character storage space.
Optionally, when the remaining length is greater than 1, the length storage space is greater than or equal to 2 bytes. Specifically, the length storage space may be determined according to the maximum storage value of the remaining length, where the maximum storage value of the remaining length may be the second length of the preset character storage space minus the maximum storage value of a single byte.
In this embodiment, the length storage space and the length storage information are determined according to the value of the remaining length, so that on the premise of ensuring the history code environment, the unique length state of the character string is determined by determining the accurate length storage space and the length storage information, and ambiguity in reading the length storage information of the character string is avoided.
As an alternative embodiment, the plurality of bytes includes: last byte and next last byte.
Optionally, the plurality of bytes may also include a third last byte, a fourth last byte, and so on. The number of bytes may be determined according to the remaining length of the preset character storage space.
Further, fig. 3 is a flowchart of determining a value stored in each of the plurality of bytes according to the embodiment of the present application, and the determining of the value stored in each of the plurality of bytes in step S203 according to the remaining length and the preset value in the above step S203 is described in detail with reference to fig. 3:
s301, calculating the sum of the residual length and the maximum storage value of the bytes.
Wherein the byte maximum storage value may be 255. As another alternative, the maximum stored value may be an integer multiple of-1 of a preset value, where the preset value is 256. Illustratively, the maximum stored value may be 511.
S302, taking the result of rounding the ratio of the sum to the preset value as the value stored in the last byte.
S303, taking the modulo result of the sum and the preset value as the value stored in the last byte.
Alternatively, the above steps S301 to S303 are applicable to a case where the remaining length is greater than 0, that is, when the remaining length is equal to 1, the value stored in the byte can be determined by the above steps S301 to S303 as well.
As an example, when the remaining length is 1 and the byte maximum storage value is 255, the sum of the remaining length and the byte maximum storage value is 256, the ratio of the sum to the preset value is rounded to 1, and the modulo result of the sum to the preset value is 0. It is noted that when the remaining length is 1, the value stored in the last byte is 1, and the value 0 stored in the next last byte is also the end identifier.
As yet another example, when the remaining length is equal to 1004 and the byte maximum storage value is 255, the sum of the remaining length and the byte maximum storage value is 1259, the ratio of the sum to the preset value is rounded, the result is 4, and 4 is stored in the last byte. And taking the modulus of the sum and the preset value to obtain a result 235, and storing 235 into the last byte.
In this embodiment, by determining the value stored in each byte in the bytes according to the remaining length and the preset value, the accurate length storage information is determined, so as to avoid ambiguity when the character string length storage information is read.
As an optional implementation manner, in the step S101, the remaining length of the preset character storage space is determined according to the first length of the target character string and the second length of the preset character storage space, which specifically includes the following steps:
first, according to the first length, the memory occupation length of the character string is determined.
Then, the result of subtracting the storage occupied length from the second length is taken as the remaining length.
It should be appreciated that when a string ends, an end identifier is typically added at the end, which requires a one-bit character. The memory footprint length may be the length of the end identifier added on the basis of the first length. The first length +1 is the memory occupied length of the character string.
As an alternative embodiment, the memory footprint may also be 2 bytes or more, which may be set by the user, without limitation.
Optionally, subtracting the storage occupied length from the second length of the preset character storage space to obtain a length which can be used for storing the valid characters in the preset character storage space, wherein the length is the remaining length.
In this embodiment, the method of this embodiment takes into account the history code environment by determining the storage occupation length of the character string according to the first length and subtracting the storage occupation length from the second length as the remaining length.
As an alternative real-time manner, the character string information processing method can be described below by two exemplary tables, respectively.
In a first example, the preset character storage space is 6, denoted char [6], on which the stored content can be represented by the following table 1:
TABLE 1 storage 6 storage contents in preset character storage space
As shown in table 1 above, when the preset character storage space is 6, since the number of characters of the preset character storage space is smaller than the maximum storage space of bytes, the length storage space may be set to 1.
When the target character string is "Hello", the first length is 5, the remaining length is 0, the length storage space is the last byte in the preset character storage space, 0 is stored in the last byte in the preset character storage space, and the target character string is stored in the preset character storage space. When the target character string is "Hell", the first length is 4, the remaining length is 1, the length storage space is the last byte, and the value 1 is stored in the last byte, and the value 0 in the next last byte. When the target character string is "He", then the first length is 2, the remaining length is 3, the length storage space is the last byte, and the value 3 is stored in the last byte.
In a second example, the preset character storage space is 1006, denoted char 1006, and the content stored in the upper portion thereof can be represented by the following table 2:
Table 2char 1006 storage contents in preset character storage space
As shown in table 2 above, when the preset character storage space is 1006, since the number of characters of the preset character storage space is greater than 256, the length storage space 2 may be set, and the last byte may be taken as the length storage space.
Taking 749 characters in the target character string as an example, the remaining length is 256, the maximum storage value of the bytes is 255, and since the remaining length is greater than 1, the sum of the remaining length and the maximum storage value is calculated to be 511, and the last byte storage value is 1, and the next last byte storage value is 255.
Taking whether the target character string has characters or not as an example, the residual length is 1005, the maximum storage value of bytes is 255, and since the residual length is greater than 1, the sum of the residual length and the maximum storage value is 1260, the last byte storage value is 4, and the next last byte storage value is 236.
After describing how the length storage information of the character string is stored in the length storage space, a description will be given next of how the electronic device reads the target character string based on the length storage information stored in the length storage space.
First, in response to request information for reading a target character string, length information of the target character string is determined from values stored on respective bytes in a length storage space.
Then, the target character string is read from the preset character storage space according to the length information of the target character string.
The request information of the target character string may be a reading instruction sent by the user on the electronic device, and the electronic device may generate the request information of the target character string according to the reading instruction.
As an alternative embodiment, according to the value stored on each byte stored in the length space, it is first determined whether the value is greater than 0, and then the length information of the target character string is determined according to the determination result and the value stored on each storage unit.
Optionally, the target character string is read backward from the preset character storage space according to the length information of the target character string and the number of characters indicated by the length information from the forefront byte.
In this embodiment, the request information is responded, the length information of the target character string is determined according to the length storage information, and then the target character string is read from the preset character storage space according to the length information of the target character string, so that the capability of quickly reading the character string is supported, the length information of the character string is conveniently extracted at low migration cost, the performance is improved, and the repeated re-measurement of the length of the character string is avoided.
Specifically, the method for determining the length information of the target character string according to the values stored in each byte in the length storage space specifically comprises the following implementation steps:
If the value stored in the last byte is 0, determining that the storage occupied length of the target character string is a second length, and determining the length information of the target character string according to the storage occupied length.
And if the value stored in the last byte is 0, indicating that the remaining length of the currently preset character storage space is 0, and the storage occupied length of the target character string is a second length.
For example, if the preset character storage space is 100 characters and the value stored in the last byte is 0, the length information of the target character string is 100 characters.
If the value stored in the last byte is greater than or equal to 1, determining the length information of the target character string according to the value stored in each byte in the length storage space and the preset value.
And if the value stored in the last byte is greater than or equal to 1, the remaining length of the current preset character storage space is greater than or equal to 1. At this time, the remaining length may be determined according to the values stored in the bytes in the length storage space, and the length information of the target string may be determined according to the remaining length and the preset value.
In this embodiment, by determining whether the value stored in the last byte is 0, the length information of the target string is determined, so that the length of the target string can be quickly obtained by reading the length storage information in the length storage space, and the slow efficiency caused by repeatedly measuring the length of the string is avoided.
Further, fig. 4 is a schematic flow chart of determining the length information of the target character string according to the embodiment of the present application, and in the following, according to fig. 4, details of how to determine the length information of the target character string in the case where the value stored in the last byte is greater than or equal to 1 in the above steps are described.
S401, calculating the product of the value stored in the last byte and a preset value.
Optionally, the product of the value stored in the last byte and the preset value represents the length of the target string stored in the last byte, and a partial length of the string.
Wherein the preset value is 256.
S402, calculating the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte.
Optionally, the sum of the product of the value stored in the last byte and 256 and the value stored in the next last byte represents the remaining length of the preset character storage space.
S403, subtracting the maximum byte stored value from the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte to obtain an intermediate result.
Alternatively, the intermediate result may represent the sum of the remaining length of the preset character storage space and the maximum stored value.
S404, taking the result of subtracting the intermediate result from the second length as the storage occupation length of the target character string, and determining the length information of the target character string according to the storage occupation length.
Illustratively, the maximum stored value is determined to be 255, the second length is 1339, the last byte has a stored value of 3, and the next last byte has a stored value of 121. Then in step S402, the product of the value stored in the last byte and 256 is 768, the sum of the product of the value stored in the last byte and 256 in step S402 and the value stored in the next last byte is 889, the intermediate result in step S404 is 634, and the occupied length is 705, that is, the length information of the target character string is 705 in step S405.
In this embodiment, the length information of the target string is determined according to the maximum stored value of the byte, the second length, the value stored in the last byte and the value stored in the last byte, so that the length information of the target string can be directly read, the slow efficiency caused by repeated measurement of the string length by using the strlen function is avoided, and the migration cost is reduced.
Based on the same inventive concept, the embodiment of the present application further provides a character string information processing device corresponding to the character string information processing method, and since the principle of solving the problem of the device in the embodiment of the present application is similar to that of the character string information processing method in the embodiment of the present application, implementation of the device may refer to implementation of the method, and repeated parts will not be repeated.
Referring to fig. 5, a schematic diagram of a character string information processing apparatus according to an embodiment of the present application is shown, where the apparatus includes: a first determination module 501, a second determination module 502, and a storage module 503; wherein:
A first determining module 501, configured to determine a remaining length of a preset character storage space according to a first length of a target character string and a second length of the preset character storage space;
A second determining module 502, configured to determine a length storage space in the preset character storage space and length storage information according to the remaining length, where the length storage information is used to indicate a value stored on each byte in the length storage space, and the length storage information is used to characterize the remaining length;
A storage module 503, configured to store the target character string in the preset character storage space, and store the length storage information in the length storage space.
Optionally, the second determining module 502 is specifically configured to:
And determining the length storage space and the length storage information according to the residual length and a preset value.
Optionally, the second determining module 502 is specifically configured to:
If the remaining length is 0, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 0;
if the remaining length is 1, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 1;
If the remaining length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the value stored in each byte in the plurality of bytes according to the remaining length and the preset value.
Optionally, the plurality of bytes includes: last byte and last byte;
optionally, the second determining module 502 is specifically configured to:
calculating the sum of the residual length and the maximum storage value of the bytes;
Taking the result of rounding the ratio of the sum to the preset value as the value stored in the last byte;
And taking the modulo result of the sum and the preset value as the value stored in the last byte.
Optionally, the first determining module 501 is specifically configured to:
Determining the storage occupation length of the character string according to the first length;
and subtracting the storage occupied length from the second length to obtain the remaining length.
Optionally, the storage module 503 is further configured to:
Responding to the request information for reading the target character string, and determining the length information of the target character string according to the numerical values stored in each byte in the length storage space;
And reading the target character string from the preset character storage space according to the length information of the target character string.
Optionally, the storage module 503 is specifically configured to:
If the value stored in the last byte is 0, determining that the storage occupied length of the target character string is the second length, and determining the length information of the target character string according to the storage occupied length;
If the value stored in the last byte is greater than or equal to 1, determining the length information of the target character string according to the value stored in each byte in the length storage space and a preset value.
Optionally, the storage module 503 is specifically configured to:
Calculating the product of the value stored in the last byte and a preset value;
Calculating the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte;
Subtracting the maximum stored value of the byte from the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte to obtain an intermediate result;
And taking the result of subtracting the intermediate result from the second length as the storage occupation length of the target character string, and determining the length information of the target character string according to the storage occupation length.
The process flow of each module in the apparatus and the interaction flow between the modules may be described with reference to the related descriptions in the above method embodiments, which are not described in detail herein.
The embodiment of the application also provides an electronic device, as shown in fig. 6, which is a schematic structural diagram of the electronic device provided by the embodiment of the application, and includes: a processor 601, a memory 602, and a bus. The memory 602 stores machine-readable instructions executable by the processor 601 (for example, execution instructions corresponding to the first determining module 501, the second determining module 502, and the storage module 503 in the apparatus in fig. 5, etc.), when the computer device is running, the processor 601 communicates with the memory 602 through a bus, and the machine-readable instructions are executed by the processor 601 to perform the processing of the above-described character string information processing method.
The embodiment of the application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program which executes the steps of the character string information processing method when being executed by a processor.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system and apparatus may refer to corresponding procedures in the method embodiments, and are not repeated in the present disclosure. In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, and the division of the modules is merely a logical function division, and there may be additional divisions when actually implemented, and for example, multiple modules or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, indirect coupling or communication connection of devices or modules, electrical, mechanical, or other form.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily appreciate variations or alternatives within the scope of the present application.

Claims (9)

1. A character string information processing method, characterized in that the method comprises:
Determining the residual length of a preset character storage space according to the first length of a target character string and the second length of the preset character storage space;
Determining a length storage space and length storage information in the preset character storage space according to the residual length, wherein the length storage information is used for indicating numerical values stored on each byte in the length storage space, and the length storage information is used for representing the residual length;
Storing the target character string into the preset character storage space, and storing the length storage information in the length storage space;
The determining the length storage space and the length storage information in the preset character storage space according to the residual length includes:
If the remaining length is 0, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 0;
if the remaining length is 1, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 1;
If the remaining length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the value stored in each byte in the plurality of bytes according to the remaining length and the preset value.
2. The character string information processing method according to claim 1, wherein the plurality of bytes includes: last byte and last byte;
The determining the value stored in each byte of the plurality of bytes according to the remaining length and the preset value includes:
calculating the sum of the residual length and the maximum storage value of the bytes;
Taking the result of rounding the ratio of the sum to the preset value as the value stored in the last byte;
And taking the modulo result of the sum and the preset value as the value stored in the last byte.
3. The character string information processing method according to claim 1, wherein the determining the remaining length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space includes:
Determining the storage occupation length of the character string according to the first length;
and subtracting the storage occupied length from the second length to obtain the remaining length.
4. The character string information processing method according to claim 1, wherein the method further comprises:
Responding to the request information for reading the target character string, and determining the length information of the target character string according to the numerical values stored in each byte in the length storage space;
And reading the target character string from the preset character storage space according to the length information of the target character string.
5. The character string information processing method according to claim 4, wherein the determining the length information of the target character string based on the values stored on the respective bytes in the length storage space includes:
If the value stored in the last byte is 0, determining that the storage occupied length of the target character string is the second length, and determining the length information of the target character string according to the storage occupied length;
If the value stored in the last byte is greater than or equal to 1, determining the length information of the target character string according to the value stored in each byte in the length storage space and a preset value.
6. The method for processing character string information according to claim 5, wherein the determining the length information of the target character string according to the value stored in each byte in the length storage space and a preset value comprises:
Calculating the product of the value stored in the last byte and a preset value;
Calculating the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte;
Subtracting the maximum stored value of the byte from the sum of the product of the value stored in the last byte and the preset value and the value stored in the next last byte to obtain an intermediate result;
And taking the result of subtracting the intermediate result from the second length as the storage occupation length of the target character string, and determining the length information of the target character string according to the storage occupation length.
7. A character string information processing apparatus, characterized by comprising:
The first determining module is used for determining the residual length of the preset character storage space according to the first length of the target character string and the second length of the preset character storage space;
the second determining module is used for determining a length storage space and length storage information in the preset character storage space according to the residual length, wherein the length storage information is used for indicating numerical values stored on each byte in the length storage space, and the length storage information is used for representing the residual length;
The storage module is used for storing the target character string into the preset character storage space and storing the length storage information in the length storage space;
the second determining module is specifically configured to:
If the remaining length is 0, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 0;
if the remaining length is 1, determining that the length storage space is the last byte in the preset character storage space, and the value indicated by the length storage information is 1;
If the remaining length is greater than 1, determining the length storage space as a plurality of continuous bytes starting from the last byte in the preset character storage space, and determining the value stored in each byte in the plurality of bytes according to the remaining length and the preset value.
8. An electronic device, comprising: a processor, a memory and a bus, the memory storing program instructions executable by the processor, the processor and the memory communicating via the bus when the electronic device is running, the processor executing the program instructions to perform the steps of the method for processing string information according to any one of claims 1 to 6 when executed.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of the character string information processing method according to any one of claims 1 to 6.
CN202410370793.XA 2024-03-29 2024-03-29 Character string information processing method, device, electronic equipment and storage medium Active CN117973317B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410370793.XA CN117973317B (en) 2024-03-29 2024-03-29 Character string information processing method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410370793.XA CN117973317B (en) 2024-03-29 2024-03-29 Character string information processing method, device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117973317A CN117973317A (en) 2024-05-03
CN117973317B true CN117973317B (en) 2024-06-07

Family

ID=90858330

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410370793.XA Active CN117973317B (en) 2024-03-29 2024-03-29 Character string information processing method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117973317B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1365046A (en) * 2000-12-28 2002-08-21 精工爱普生株式会社 String process method, process system, and its object program
CN108196937A (en) * 2017-12-26 2018-06-22 金蝶软件(中国)有限公司 Processing method, device, computer equipment and the storage medium of string
CN112118010A (en) * 2020-08-25 2020-12-22 中电信用服务有限公司 Compression processing method and device for character strings and storage medium
CN113449156A (en) * 2020-03-25 2021-09-28 北京沃东天骏信息技术有限公司 Character string generation method and device, computer readable medium and electronic equipment
CN113626651A (en) * 2021-08-04 2021-11-09 上海金仕达成括信息科技有限公司 Data matching method and device
CN114792007A (en) * 2022-04-28 2022-07-26 中国工商银行股份有限公司 Code detection method, device, equipment, storage medium and computer program product
CN114880523A (en) * 2022-04-27 2022-08-09 深圳市优必选科技股份有限公司 Character string processing method and device, electronic equipment and storage medium
CN115344877A (en) * 2022-08-18 2022-11-15 江西科技学院 Data storage method, system and readable storage medium
CN117008906A (en) * 2023-08-18 2023-11-07 上海微盟企业发展有限公司 Multi-line text overflow control method, device, equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10540512B2 (en) * 2015-09-29 2020-01-21 International Business Machines Corporation Exception preserving parallel data processing of string and unstructured text

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1365046A (en) * 2000-12-28 2002-08-21 精工爱普生株式会社 String process method, process system, and its object program
CN108196937A (en) * 2017-12-26 2018-06-22 金蝶软件(中国)有限公司 Processing method, device, computer equipment and the storage medium of string
CN113449156A (en) * 2020-03-25 2021-09-28 北京沃东天骏信息技术有限公司 Character string generation method and device, computer readable medium and electronic equipment
CN112118010A (en) * 2020-08-25 2020-12-22 中电信用服务有限公司 Compression processing method and device for character strings and storage medium
CN113626651A (en) * 2021-08-04 2021-11-09 上海金仕达成括信息科技有限公司 Data matching method and device
CN114880523A (en) * 2022-04-27 2022-08-09 深圳市优必选科技股份有限公司 Character string processing method and device, electronic equipment and storage medium
CN114792007A (en) * 2022-04-28 2022-07-26 中国工商银行股份有限公司 Code detection method, device, equipment, storage medium and computer program product
CN115344877A (en) * 2022-08-18 2022-11-15 江西科技学院 Data storage method, system and readable storage medium
CN117008906A (en) * 2023-08-18 2023-11-07 上海微盟企业发展有限公司 Multi-line text overflow control method, device, equipment and storage medium

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
ForestDB: A Fast Key-Value Storage System for Variable-Length String Keys;Ahn, Jung-Sang等;《IEEE TRANSACTIONS ON COMPUTERS》;20160301;第65卷;全文 *
列数据库字符串类型操作研究与实现;黄鑫铭;《中国优秀硕士学位论文全文数据库(信息科技辑)》;20140515(第5期);全文 *
探究C语言中的字符串;张智先;鲍正德;唐娅雯;;饮食科学;20190323(第06期);全文 *

Also Published As

Publication number Publication date
CN117973317A (en) 2024-05-03

Similar Documents

Publication Publication Date Title
CN103279544A (en) Method and device for storing and inquiring tree structure data in relational database
CN104579360B (en) A kind of method and apparatus of data processing
EP3567734A1 (en) Method and apparatus for processing rate matching of polar codes
CN110990189A (en) Data storage method and device, electronic equipment and computer readable storage medium
CN114817651B (en) Data storage method, data query method, device and equipment
CN110545106A (en) Method and device for coding time series data
CN117973317B (en) Character string information processing method, device, electronic equipment and storage medium
CN116166583B (en) Data precision conversion method and device, DMA controller and medium
CN104077272A (en) Method and device for compressing dictionary
CN107832341B (en) AGNSS user duplicate removal statistical method
CN115774837A (en) Signal verification method, device, equipment, medium, program product and vehicle
CN114385624A (en) Encoding method, encoding searching method, device, electronic equipment and storage medium
CN113630123A (en) Data compression system and method
CN112395468A (en) Number management method and device, electronic equipment and storage medium
KR100937031B1 (en) Cyclic redundancy check system and method thereof
CN116016724B (en) Message parsing method, device, equipment and medium
CN117375629A (en) Data compression method and device, electronic equipment and storage medium
CN106569778B (en) A kind of method and electronic equipment of data processing
CN115658730B (en) Sparse data query method, apparatus, device and computer readable storage medium
CN113438050B (en) Encoding method, decoding method, encoding device and decoding device
CN111274228B (en) Policy data migration storage method, system, equipment and readable storage medium
CN115617392B (en) Method and device for determining version number
CN112100169B (en) Database interaction data encoding method and device
CN116991545B (en) Virtual machine deployment position determining method and device
CN111488727B (en) Word file parsing method, word file parsing apparatus, and computer-readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant