String processing method and apparatus

By dynamically determining the digital number corresponding to the substring, converting massive string data into smaller values, the problem of excessive numerical values ​​in the existing technology is solved, and the efficiency of string processing and memory utilization is improved.

CN113496111BActive Publication Date: 2025-06-13HUAWEI TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202010261492.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-03
Publication Date
2025-06-13
Estimated Expiration
2040-04-03

AI Technical Summary

Technical Problem

When processing massive string data, the value obtained after converting it to numerical values ​​is too large, resulting in low string processing efficiency and high memory consumption.

Method used

By obtaining the substring groups in multiple target strings, the number of digits corresponding to each substring is dynamically determined according to the number of different substrings in the substring group, so that the converted numerical value is smaller.

Benefits of technology

It reduces memory consumption during string processing, improves data processing efficiency, and performs better in order and search operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113496111B_ABST
    Figure CN113496111B_ABST
Patent Text Reader

Abstract

The present application discloses a string processing method and apparatus, which helps to save memory space and improve the efficiency of string data processing. The string processing method is applied to a computer device, and the method includes: obtaining a plurality of target strings, where each target string in the plurality of target strings includes at least one character. Obtaining a first substring group from the same position of each target string. Among them, the first substring in the first substring group includes some characters in the target string where the first substring is located. The substrings in the first substring group correspond to the same digit positions. Determine the base number of the digit positions corresponding to each substring in the first substring group according to the number of different substrings in the first substring group. Determine the target value corresponding to each target string according to the base number of the digit positions corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group, and process the plurality of target strings based on the target value corresponding to each target string.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and particularly to a method and apparatus for string processing. Background Art

[0002] With the development of information technology, enterprises need to process a vast amount of data every day to support the formulation of enterprise market strategies and strategic adjustments. For example, in the communication industry, operators need to analyze daily communication data to adjust marketing strategies. The data to be processed reaches dozens or even hundreds of terabytes every day. To process such a vast amount of data, the speed of data processing must be improved to keep up with the ever-changing market and meet the needs of enterprises. The industry has proposed learning-based data organization to improve the speed of data processing. A learning-based data organization can obtain the data organization that best matches the character features of the current data set based on the character features of the current data set, thereby obtaining better query or sorting performance. A learning-based data organization includes a data model that can support learning and mathematical optimization. A data model that can support learning and mathematical optimization has better query or sorting performance, but the data participating in training the data model must first be converted into numerical values. However, most of the data generated in real business scenarios is in the form of strings.

[0003] Currently, when a computer device processes a string, it converts the string into a numerical value according to the American Standard Code for Information Interchange (ASCII) code of the characters in the string. The ASCII code includes a total of 256 different characters. Therefore, the computer device uses the decimal ASCII code value of each character and base 256 to convert the string into a numerical value. For example: in the string afcdeedd, the decimal ASCII code value of a is 97, the decimal ASCII code value of f is 102, the decimal ASCII code value of c is 99, the decimal ASCII code value of d is 100, and the decimal ASCII code value of e is 101. The decimal numerical value converted from the string afcdeedd is: 97 * 256 7 + 102 * 256 6 + 99 * 256 5 + 100 * 256 4 + 101 * 256 3 + 101 * 256 2 + 100 * 256 1 + 100. In this way, the numerical value obtained by converting the string is too large. The larger the numerical value obtained by converting the string, the lower the efficiency and the greater the memory space consumed when processing string data (such as sorting or searching, etc.). Summary of the Invention

[0004] Embodiments of the present application provide a string processing method and apparatus, which help improve data processing efficiency and reduce memory consumption when processing string data.

[0005] To achieve the above object, the embodiments of the present application adopt the following technical solutions:

[0006] In a first aspect, a method for converting a string into a numerical value is provided. The method includes: obtaining a plurality of target strings, where each target string in the plurality of target strings includes at least one character. Obtaining a first substring group from the same position of each target string. Among them, the first substring in the first substring group includes some or all of the characters in the target string where the first substring is located. The substrings in the first substring group correspond to the same digit positions. According to the number of different substrings in the first substring group, determine the base number of the digit position corresponding to each substring in the first substring group. According to the base number of the digit position corresponding to each substring in the first substring group and the numerical value corresponding to each substring in the first substring group, determine the target numerical value corresponding to each target string, and process the plurality of target strings based on the target numerical value corresponding to each target string. This technical solution is applicable to the scenario of converting a plurality of target strings into numerical values. In this scenario, for any digit position corresponding to a substring in the target string, based on the number of different substrings in the substring group where the digit position corresponding to the substring is located, determine the base number of the digit position. Based on this, the base numbers of different digit positions in the numerical value converted from the target string can be different. In the prior art, "the base numbers of different digit positions in the numerical value converted from the string are fixed base numbers, such as all 256". In this way, if the number of different substrings in the plurality of target strings is less than the fixed base number, compared with the prior art, when using the technical solution provided by the embodiments of the present application, the determined base number corresponding to the digit position will be less than the fixed base number. The numerical value obtained by the computer device converting the string through the obtained base numbers of each digit position will be less than the numerical value obtained by converting the string through the fixed base number. When the computer device processes strings (such as searching) using the relatively small numerical value obtained by the conversion of the embodiments of the present application, it helps reduce memory consumption and improve data processing efficiency.

[0007] According to the first aspect, in a first implementation manner of the first aspect, the base number of the digit position corresponding to the first substring is greater than or equal to the number of different substrings in the first substring group and less than a first threshold. In this way, the base number of the first digit position being greater than or equal to the number of different substrings in the first substring group can ensure that the numerical values corresponding to each substring are different, thus ensuring the conversion accuracy of the string. And the base number of the digit position corresponding to the first substring being less than the first threshold can make the numerical value obtained after converting the string not too large, so that when the computer device processes strings using the converted numerical value, it helps reduce memory consumption and improve data processing efficiency.

[0008] According to the first aspect and the first implementation manner of the first aspect, in the second implementation manner of the first aspect, determining the target value corresponding to each target string according to the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group includes: obtaining the value corresponding to each substring in the first substring group; wherein, the values corresponding to different substrings are different, and the substring with a larger American Standard Code for Information Interchange (ASCII) code value in the substring has a larger corresponding value. Based on the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group, convert each target string into a target value. In this way, the substring with a larger ASCII code value in the target substring has a larger corresponding value. When converting each target string in the multiple target strings into a value, the relative size of each target string in the multiple target strings relative to other target strings can be maintained, thereby ensuring the correctness of the processing result obtained after processing the multiple target strings.

[0009] According to the first aspect and the first implementation manner of the first aspect, in the third implementation manner of the first aspect, obtaining multiple target strings includes: obtaining multiple strings to be processed. Convert each string to be processed in the multiple strings to be processed into a value to obtain multiple target strings. Wherein, the string to be processed and the target string are in one-to-one correspondence. In this way, after converting the multiple strings to be processed into values, the converted values are used as target strings. When the number of different substrings in the target string is less than the currently fixed base number, when converting each target string in the multiple target strings into a value, the obtained value can be further reduced. When the computer device processes strings using the relatively small converted value, it helps to further reduce memory consumption and improve the efficiency of data processing.

[0010] According to the first aspect and the third implementation manner of the first aspect, in the fourth implementation manner of the first aspect, the number of different substrings included in the multiple target strings is less than or equal to a second threshold. In this way, the value obtained after converting the string can be prevented from being too large. Thus, when the computer device processes strings using the converted value, it helps to reduce memory consumption and improve the efficiency of data processing.

[0011] In a second aspect, a string processing device is provided. The device can be used to execute any method provided in any possible implementation manner of the above first aspect to the first aspect. For example, the device can be a computer device (such as a terminal device, a server, or a cloud server) or a chip, etc.

[0012] According to a second aspect, in a first possible implementation manner of the second aspect, the functions of the device may be divided according to any of the methods provided in the first aspect above. For example, each functional unit may be corresponding to each function, or two or more functions may be integrated into one processing unit.

[0013] According to the second aspect or the first possible implementation manner of the second aspect, in a second possible implementation manner of the second aspect, the device may include a processor, and the processor is configured to execute any of the methods provided in the first aspect above.

[0014] In a third aspect, a computer-readable storage medium is provided, such as a non-transitory computer-readable storage medium. A computer program (or instruction) is stored thereon. When the computer program (or instruction) runs on a computer, the computer is caused to execute any of the methods provided in the first aspect or any of the possible implementation manners of the first aspect.

[0015] In a fourth aspect, a computer program product is provided. When it runs on a computer, any of the methods provided in the first aspect or any of the possible implementation manners of the first aspect is caused to be executed.

[0016] In a fifth aspect, a chip is provided, including: a processor, configured to call and run a computer program stored in a memory, and execute any of the methods provided in the first aspect or any of the possible implementation manners of the first aspect.

[0017] It can be understood that any of the above-provided string processing devices, computer-readable storage media, computer program products, or chips, etc. can be applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods, which will not be elaborated here. Description of the Drawings

[0018] Figure 1 It is a schematic flowchart of processing string data by the technical solution of the embodiment of the present application;

[0019] Figure 2 It is a schematic structural diagram of a computer device to which the technical solution provided by the embodiment of the present application is applicable;

[0020] Figure 3 It is an example of multiple target strings in the embodiment of the present application;

[0021] Figure 4 It is a schematic flowchart of a string processing method provided by the embodiment of the present application;

[0022] Figure 5 It is a schematic diagram of 3 target strings obtained by a computer device;

[0023] Figure 6 Schematic diagram of a computer device for assigning numerical values to different substrings in the first substring group;

[0024] Figure 7 Schematic diagram of the numerical values assigned by a computer device to each substring in each substring group;

[0025] Figure 8 Schematic diagram of a computer device for converting a first target string into a numerical value based on the base number of the digit corresponding to the substring and the numerical value corresponding to the substring;

[0026] Figure 9 Schematic structural diagram of a string processing device provided by an embodiment of the present application. Detailed implementation manners

[0027] To facilitate understanding of the technical solutions of the embodiments of the present application, the application scenarios applicable to the related technologies of the present application are first introduced.

[0028] In application scenarios such as big data batch processing services, big data stream processing services, memory-based fast storage, and memory-based middleware, it is necessary to convert string data into numerical values before performing business processing. As Figure 1 shown in the schematic diagram of the process of string data processing applicable to the technical solutions of the embodiments of the present application, the scenarios for processing the above string data include two basic steps: preprocessing and business processing. The technical solutions provided by the embodiments of the present application can be applied to the preprocessing when processing multiple string data. Among them, the preprocessing includes sorting or creating indexes for the string data. Of course, the solutions provided by the embodiments of the present application can also be applied to other scenarios that require converting strings into numerical values. The present application does not limit this.

[0029] In the technical solutions provided by the embodiments of the present application, first, a computer device obtains substrings from the same positions of each target string among multiple target strings, obtaining one substring group or multiple substring groups, and the substring group includes substrings. Each substring is all or part of the characters in the target string where the substring is located, and at least one substring is part of the characters in the target string where the substring is located. Each substring corresponds to a digit, and the digits corresponding to the substrings in the same substring group are the same. Then, the computer device obtains the base number of each digit according to the number of different substrings in the substring group, and obtains the counting unit of each digit through the base numbers of each digit. The computer device adds the products of the numerical values corresponding to the substrings of each digit in a target string and the corresponding counting units to obtain the numerical value converted from the target string.

[0030] When converting a target string into a numerical value, in order to ensure that the processing results are the same when performing business processing on multiple such target strings, it is necessary to ensure that the relative magnitudes of the numerical values obtained after converting multiple target strings are the same as those obtained by converting the same target strings according to the ASCII code. The ASCII code includes a total of 256 characters, and each character corresponds to an ASCII code value. For a target string, the possible character situations at each character position are 256. Therefore, the computer device converts a target string into a decimal numerical value through the ASCII code value of a single character and the 256 - base system. In the embodiments of the present application, a substring in the target string corresponds to a position, and the number of possible substrings at this position is the number of different substrings at this position. Therefore, the base number of each digit can be obtained according to the number of different substrings in the substring group, so as to ensure that the processing results are the same when performing business processing on multiple strings. The numerical value obtained by converting the string through the solution of the present application is smaller than the numerical value obtained by converting the same string based on the ASCII code.

[0031] The technical solution provided by the embodiments of the present application can be executed by a computer device. Among them, the computer device can specifically be a terminal device or a server. Among them, the terminal device can be a tablet computer, a handheld computer, a mobile phone, a desktop computer, etc. The server can be a single server, a server cluster composed of multiple servers, or a cloud computing service center.

[0032] As Figure 2 shown, it is a schematic structural diagram of a computer device to which the technical solution provided by the embodiments of the present application is applicable. Figure 2 The computer device 10 shown may include at least one processor 101, a communication line 102, a memory 103, and at least one communication interface 104.

[0033] The processor 101 can be a general - purpose central processing unit (CPU), a microprocessor, an application - specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the solution of the present application.

[0034] The communication line 102 may include at least one path, such as a data bus and / or a control bus, for transmitting information between the above - mentioned components (such as at least one processor 101, a communication line 102, a memory 103, and at least one communication interface 104).

[0035] The communication interface 104 uses any transceiver-like device for communicating with other devices or communication networks, such as a wide area network (WAN), local area networks (LAN), etc.

[0036] The memory 103 can be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or it can also be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM), or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but not limited to this. The memory 103 can exist independently and be connected to the processor 101 through the communication line 102. The memory 103 can also be integrated with the processor 101. The memory 103 provided in the embodiments of the present application generally includes non-volatile memory. Among them, the memory 103 is used to store computer instructions for executing the solution of the present application and is controlled by the processor 101 for execution. The processor 101 is used to execute the computer instructions stored in the memory 103, thereby implementing the method provided in the following embodiments of the present application.

[0037] The memory 103 includes memory and a hard disk.

[0038] Optionally, the computer instructions in the embodiments of the present application can also be referred to as application program code or a system, and the embodiments of the present application do not make specific limitations on this.

[0039] In a specific implementation, as an embodiment, the computer device 10 can include multiple processors, and each of these processors can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. Here, the processor can refer to one or more devices, circuits, and / or processing cores for processing data (such as computer program instructions).

[0040] In a specific implementation, as an example, the computer device 10 may further include an output device 105 and / or an input device 106. The output device 105 communicates with the processor 101 and can display information in various ways. For example, the output device 105 may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 106 communicates with the processor 101 and can receive user input in various ways. For example, the input device 106 may be a mouse, a keyboard, a touch screen device, or a sensing device, etc.

[0041] It should be noted that Figure 2 the computer device shown is only an example and does not limit the computer devices applicable to the embodiments of the present application. In actual implementation, the computer device may include more or fewer devices or components than Figure 2 those shown.

[0042] For the convenience of understanding, before introducing the string processing method of the embodiments of the present application, some of the terms and technologies involved are briefly introduced:

[0043] 1), Character

[0044] In the embodiments of the present application, a character includes at least one of uppercase and lowercase letters, numbers 0 to 9, punctuation marks, special control characters (such as: LF (line feed), CR (carriage return), FF (form feed), DEL (delete), BS (backspace), BEL (bell), etc.), special symbol characters (such as: mathematical symbols, unit symbols, etc.), foreign language letters, or graphic symbols.

[0045] 2), String

[0046] A string is a string of characters composed of at least one of numbers, letters, punctuation marks, special control characters, special symbol characters, foreign language letters, or graphic symbols.

[0047] 3), Digit

[0048] A digit refers to the position occupied by each digit in a number. The digits can be characterized by numbering each digit in the order from low to high, from right to left. For example, in decimal, the first digit of a number is 1 representing the "units place", the second digit is 2 representing the "tens place", the third digit is 3 representing the "hundreds place", etc. The digit with a smaller number is lower than the digit with a larger number.

[0049] 4), Number system, counting unit

[0050] The number system is also called the positional counting system, which is a counting method with carry. For any number system: X-number system means that the numerical operation on each digit is carried forward by one every X. For example, the decimal system is carried forward by one every ten, the hexadecimal system is carried forward by one every 256, and the binary system is carried forward by one every 2.

[0051] The counting unit is the unit of numerical measurement. The counting unit of the lowest digit of a value is 1. Except for the lowest digit, the counting unit of a digit is the product of the base numbers of all digits lower than that digit. For example, the counting units in the decimal counting method are, from the lowest digit to the highest digit, ones, tens, hundreds, thousands, ten thousand, one hundred thousand, one million, ten million, one hundred ...

[0052] 5) Others

[0053] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0054] In the embodiments of the present application, "at least one" means one or more, and "plurality" means two or more.

[0055] In the embodiments of the present application, "and / or" is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0056] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0057] Embodiment 1

[0058] like Figure 3 As shown in FIG. 1 , a flow chart of a string processing method provided in an embodiment of the present application is shown. For example, this embodiment can be applied to Figure 2 Computer equipment shown. Figure 3 The method shown may include the following steps:

[0059] S100: The computer device obtains a plurality of target character strings, wherein each of the plurality of target character strings includes at least one character.

[0060] The embodiment of the present application does not limit the multiple target character strings obtained by the computer device.

[0061] In one implementation, the computer device receives multiple target strings sent by other devices. Alternatively, the computer device reads multiple stored target strings. The multiple target strings are unprocessed strings.

[0062] In another implementation, the multiple target strings are values obtained by the computer device by converting multiple strings to be processed into numerical values using the technical solutions provided in the embodiments of the present application or the methods of the prior art. This implementation can be used when the values obtained by converting multiple strings to be processed into numerical values using the technical solutions provided in the embodiments of the present application or the methods of the prior art are greater than or equal to a threshold. For example, when they are greater than or equal to the minimum value of a large number, the multiple numerical values are used as target strings. Through the technical solutions provided in the embodiments of the present application, the multiple target strings are first converted into numerical values and then string processing is performed. In this way, the numerical values obtained by converting the target strings can be further reduced. When the computer device processes the target strings using the relatively small obtained numerical values, it helps to reduce memory consumption and improve the efficiency of data processing.

[0063] Exemplarily, as Figure 4 shown, it is a schematic diagram of 3 target strings obtained by the computer device. Figure 4 The first target string in it is abc, the second target string is bcd, and the third target string is efcg.

[0064] S101: The computer device obtains a first substring group from the same position of each target string. Among them, the first substring in the first substring group includes some characters in the target string where the first substring is located. The substrings in the first substring group correspond to the same digit positions.

[0065] The first substring group is any one of the multiple substring groups obtained by the computer device. The first substring is a substring in the first substring group. The substrings in the first substring group include all or some characters in the target string where the substring is located.

[0066] Exemplarily, when the target strings are ab and efcd, the computer device starts from the 0 position of each target string in the order from left to right and obtains 2 characters, getting the first substring group. The substrings included in the first substring group are: ab and ef. Among them, the substring ab includes all the characters of the target string ab, and the substring ef includes some characters of the target string efcd.

[0067] Specifically, the computer device obtains a preset number of characters from the same position of each target string among multiple target strings in the order from right to left or from left to right. The preset number of characters obtained by the computer device is a substring. The multiple substrings obtained by the computer device from the same position of each target string form a substring group. The position of a character in a target string can be represented by the subscript of the target string. Among them, the subscript is the number. Since the target string is actually an array of characters, subscript indexing is supported. For example: for the target string ABCS, in the order from left to right, where the subscript of A is 0, the subscript of B is 1, the subscript of C is 2, and the subscript of S is 3. In the order from right to left, where the subscript of S is 0, the subscript of C is 1, the subscript of B is 2, and the subscript of A is 3. Finally, the computer device divides each target string among multiple target strings into substrings. Substrings corresponding to different positions in a target string belong to different substring groups. It should be noted that the embodiment of the present application does not limit the preset number. Exemplarily, the computer device obtains 2 characters starting from the 0 position of the target string in the order from left to right to obtain a substring. The computer device obtains 2 characters starting from position 2 to obtain another substring. Or, the computer device obtains 2 characters starting from the 0 position of the target string in the order from left to right to obtain a substring. The computer device obtains 1 character starting from position 2 to obtain another substring. Or, the computer device defines the preset number according to other rules.

[0068] In the embodiment of the present application, after the computer device obtains the substring groups corresponding to all target strings, it can determine the digit corresponding to the substring based on the number of obtained substring groups and the position of the substring in the target string where it is located. There are various methods for the computer device to determine the digit corresponding to the substring.

[0069] In one implementation, the computer device determines the highest digit corresponding to each substring based on the number of obtained substring groups, and determines the digit corresponding to the substring based on the position of the substring in the target string where it is located in each substring group. For example, the target string abc is split into two substrings ab and c, then the highest digit of the target string abc is 2.

[0070] In another implementation, the computer device determines the highest digit corresponding to each substring based on the number of substrings in the target string with the largest number of substrings, and determines the digit corresponding to the substring based on the position of the substring in the target string where it is located in each substring group. For example, the target string abc is split into two substrings ab and c, and the target string abcd is split into three substrings ab, c, and d, then the highest digit of the target string abcd is 3.

[0071] It can be understood that before the computer device obtains a substring, it needs to allocate storage space for the obtained substring first. When the storage space for one character is 1 byte, without knowing the number of different characters included in multiple target strings, the computer device needs to allocate the total number of different characters (e.g., 256) of bytes to store the characters obtained from multiple target strings. By analogy, when the computer device obtains a substring including two characters, it needs 256 * 256 bytes of storage space. However, when most of the substrings are the same, only one copy of the same substring needs to be stored. Since the computer device doesn't know that the substrings are the same before obtaining them, it still reserves 256 * 256 bytes of storage space to store the substrings, resulting in a large amount of wasted storage space. Therefore, when obtaining a preset number of characters as substrings, the fewer the number of characters included in the substring, the less storage space is wasted by using the method of the embodiments of the present application. Therefore, the preset number can be set to a relatively small number. At the same time, when the computer device obtains a substring, it can directly allocate the storage space for each substring according to the preset number, avoiding waste of storage space.

[0072] Based on the example in S100, combined with Figure 5 , the complete process of S101 will be exemplarily described. The computer device starts obtaining 2 characters from the 0 position of the target string in the order from left to right to obtain a substring. The first substring group obtained by the computer device includes the substring: ab obtained from the first target string, the substring: bc obtained from the second target string, and the substring: ef obtained from the third target string. The computer device starts obtaining 1 character from the 2 position of the target string in the order from left to right to obtain a substring. The second substring group obtained by the computer device includes the substring: c obtained from the first target string, the substring: d obtained from the second target string, and the substring: c obtained from the third target string. The computer device starts obtaining 1 character from the 3 position of the target string in the order from left to right to obtain a substring. The third substring group obtained by the computer device includes the substring: empty obtained from the first target string, the substring: empty obtained from the second target string, and the substring: g obtained from the third target string. Figure 5 In this case, the computer device obtains three substring groups from multiple target strings and determines that the highest digit corresponding to the substrings of the multiple target strings is 3. The computer device determines, in the order from left to right, that the substring groups where the substrings corresponding to the digits from high to low in each target string are located are: the first substring group, the second substring group, and the third substring group. The digit corresponding to each substring in the first substring group is 3, the digit corresponding to each substring in the second substring group is 2, and the digit corresponding to each substring in the third substring group is 1.

[0073] S102: The computer device determines the base number of the digit corresponding to each substring in the first substring group according to the number of different substrings in the first substring group.

[0074] The embodiments of the present application do not limit the specific manner in which the computer device determines the base number of the digit corresponding to each substring in the first substring group according to the number of different substrings in the first substring group.

[0075] In one implementation, the base number of the digit corresponding to each substring in the first substring group is the number of different substrings included in the first substring group. Based on the example in S101: The computer device determines that the base number of the digit corresponding to each substring in the first substring group is 3, the computer device determines that the base number of the digit corresponding to each substring in the second substring group is 2. The computer device determines that the base number of the digit corresponding to each substring in the third substring group is 1.

[0076] In another implementation, the base number of the digit corresponding to each substring in the first substring group is greater than the number of different substrings in the first substring group and less than the first threshold. For example, the first threshold is a value less than 256. In this way, the base number of the digit obtained by this method is not fixed. If the number of different substrings is less than the currently used base number, since the formula for converting the target string to a numerical value is the sum of the products of the numerical values corresponding to each substring of the target string and the counting units of the digits corresponding to the substrings. The counting unit of a digit is equal to the product of the base numbers of all digits lower than that digit. Among them, when the numerical value corresponding to the substring remains unchanged, the smaller the base number, the smaller the obtained counting unit of the digit. Therefore, when the base number is equal to the number of different substrings and less than the currently used base number in the prior art, the numerical value obtained by converting the target string will be less than the numerical value obtained by converting the same target string by the prior art method. Thus, it helps to improve the efficiency of string processing.

[0077] S103: The computer device obtains the numerical value corresponding to each substring in the first substring group.

[0078] Specifically, the computer device obtains the numerical value corresponding to each substring in the first substring group according to the following steps.

[0079] Step 1: The computer device obtains a first number of different numerical values. Wherein, the first number is the number of different substrings in the first substring group obtained by the computer device.

[0080] The embodiments of the present application do not limit the method for the computer device to obtain a first number of different numerical values. In one implementation, the computer device uses a sequence to generate a continuous first number of different numerical values. In another implementation, the computer device obtains a discrete first number of different numerical values. In yet another implementation, the computer device obtains the ASCII code values of each substring in the different substrings to obtain a first number of different numerical values.

[0081] Step 2: The computer device assigns the obtained first quantity of values to each substring in the first substring group.

[0082] In one implementation, the computer device randomly assigns different values among the first quantity of values to different substrings.

[0083] In another implementation, the computer device assigns the first quantity of values to different target substrings according to the ascending order of the ASCII code values of the target substrings. The larger the ASCII code value of a target substring, the larger the value assigned to that target substring. In this way, when the computer device converts each string in multiple strings into a value, it can maintain the relative size of each string in the multiple strings with respect to other strings. When the computer device processes strings (such as sorting or searching) using the relatively small converted values, it helps to reduce memory consumption and improve the efficiency of data processing.

[0084] The computer device determines the value corresponding to a substring according to the number of different substrings in the substring group, rather than using the ASCII code value of the substring as the value corresponding to the substring as in the prior art. In most cases, the value corresponding to the substring determined by the computer device based on the number of different substrings will be smaller than the ASCII code value of the substring. The value obtained by converting the target string based on the value corresponding to the substring determined by the computer device based on the number of different substrings will also be further reduced. The number system of the digits corresponding to the substring and the storage of the value corresponding to the substring determined according to the number of different substrings in the substring group only require a very small amount of storage space. It can be understood that the computer device compresses the target string into a compact space. Therefore, the computer device can store the correspondence between the digits corresponding to the substring and the number system, and the correspondence between the substring and the value in the memory all the time when processing the target string data, so as to improve the conversion speed of converting the target string into a value. Thus, when the computer device processes the target string, the processing efficiency is improved.

[0085] Based on the example in S101, such as Figure 6 The following is a schematic diagram showing the computer device assigning values to different substrings in the first substring group: The number of different substrings in the first substring group obtained by the computer device is 3, and the first quantity is 3. The first quantity of values obtained by the computer device are: 0, 1, 2. The computer device assigns them to the substrings ab, bc, ef in the order of the size of the values 0, 1, 2. Among them, 0 is assigned to ab, 1 is assigned to bc, and 2 is assigned to ef. Among them, the ASCII code value of ab is less than the ASCII code value of bc, and the ASCII code value of bc is less than the ASCII code value of ef.

[0086] Such as Figure 7The figure shows a schematic diagram of the numerical values assigned by the computer device to each substring in each substring group. Figure 7 In this example, the first substring group consists of the substrings ab, bc, and ef, the second substring group consists of the substrings c, d, and c, and the third substring group consists of the substring g. The computer device assigns numerical values to each substring in the multiple substring groups, obtaining a numerical value of 0 for the substring ab, a numerical value of 1 for the substring bc, a numerical value of 2 for the substring ef, a numerical value of 0 for the substring c, a numerical value of 1 for the substring d, and a numerical value of 0 for the substring g.

[0087] The embodiments of the present application do not limit the data structure of the correspondence between substrings and numerical values stored in the computer device. Exemplarily, it can be an array, a queue, a table, or the like.

[0088] S104: The computer device determines the target numerical value corresponding to each target string according to the base number of the digit corresponding to each substring in the first substring group and the numerical value corresponding to each substring in the first substring group.

[0089] Specifically, the computer device converts the first target string into a numerical value according to the following steps. The first target string is any one of the multiple target strings.

[0090] Step 1: The computer device obtains the counting unit of the digit corresponding to the substring in the first substring group.

[0091] In one implementation, the computer device obtains the product of the base numbers of the digits corresponding to all substrings in the first target string that are lower than the digit corresponding to the first substring. The first substring is a substring in the first substring group in the first target string.

[0092] In another implementation, the computer device obtains the product of the base numbers of the digits corresponding to all substrings in the first target string that are lower than the digit corresponding to the first substring, and uses the first algorithm to obtain a number larger than this product as the counting unit of the digit corresponding to the substring in the first substring group. The embodiments of the present application do not limit the first algorithm. Exemplarily, the first algorithm can be adding a positive integer to this product or multiplying it by a positive integer, or other similar calculation methods.

[0093] Step 2: The computer device obtains the product of the numerical value of the substring in the first target string and the counting unit of the substring.

[0094] Step 3: The computer device obtains the sum of the multiple products. Each of the multiple products is the product of the numerical value on a digit and the counting unit of that digit. The sum of the multiple products is the numerical value obtained by converting the first target string.

[0095] Based on the examples in S102 and S103, such asFigure 8 Schematic diagram for a computer device to convert a first target string into a numerical value based on the base number of the digits corresponding to a substring and the numerical value corresponding to the substring. Figure 8 In this case, the first target string is abc. After replacing the substring in the first target string with the numerical value corresponding to the substring, the counting unit of the digit where the numerical value 0 of the substring ab is located is the product of the base numbers of all digits lower than this digit, which is 2 * 1 = 2. The counting unit of the digit where the numerical value 0 of the substring c is located is the product of the base numbers of all digits lower than this digit, which is 1 * 1 = 1. The product of the numerical value of the substring ab obtained by the computer device and the counting unit of the digit where this numerical value is located is 0 * 2 = 0, and the product of the numerical value of the substring c and the counting unit of the digit where this numerical value is located is 0 * 1 = 0. The numerical value that the computer device converts the first target string into is: the sum of these multiple products is: 0 + 0 = 0. The numerical value converted from the first string is 0.

[0096] S105: The computer device processes multiple target strings based on the target numerical values corresponding to each target string.

[0097] The embodiments of this application do not limit the specific scenarios for processing multiple target strings.

[0098] In one example, in a big data batch processing service, if the computer device needs to sort multiple target strings obtained, the computer device can sort the multiple target strings based on the target numerical values corresponding to each target string. Since the computer device needs to compare single characters when sorting strings, while it can directly compare the whole numerical values when comparing numerical values. Therefore, the sorting efficiency of the computer device for numerical values is much greater than the sorting efficiency for strings.

[0099] In another example, in a fast storage scenario based on memory, if it is necessary to create indexes for multiple target strings, the computer device can create indexes for the multiple target strings based on the target numerical values corresponding to each target string. In this way, when using this index to search for a target string, logical AND / OR operations can be performed based on the numerical value of the target string. If directly based on the target string, the computer device can only perform limited operations. Therefore, compared with creating indexes based on target strings, the indexes created based on the target data corresponding to the target strings can find the target string more quickly.

[0100] In the embodiments of the present application, the computer device converts multiple target strings into numerical values. For any digit corresponding to a substring in the target string, based on the number of different substrings corresponding to this digit, the base number of this digit is determined. Based on this, the base numbers of different digits in the numerical value converted from the target string can be different. In the prior art, "the base numbers of different digits in the numerical value converted from the target string are fixed base numbers, such as all 256". Thus, if the number of different substrings corresponding to the same digit in the multiple target strings is less than the fixed base number, compared with the prior art, when using the technical solution provided by the embodiments of the present application, the determined base number of the digit corresponding to the substring will be less than the fixed base number. The numerical value obtained by the computer device converting the target string through the base number of the digit corresponding to the obtained substring will be less than the numerical value obtained by converting the target string through the fixed base number. When the computer device performs string processing (such as searching) using the relatively small numerical value obtained by the conversion in the embodiments of the present application, it helps to reduce memory consumption and improve the efficiency of data processing.

[0101] The results of testing the technical solution of the embodiments of the present application in the following scenarios are as follows:

[0102] The following respectively compares the time consumed for converting target strings into numerical values and sorting them using the method of the embodiments of the present application with the time consumed for converting target strings into numerical values and sorting them using the optimal sorting algorithm among multiple sorting algorithms in the prior art for target strings of 1 million magnitude and 3 million magnitude.

[0103] In the comparison test, two types of target strings are used. The first type is phone numbers, and the second type is randomly generated strings.

[0104] Regarding the selection of the comparison algorithm, in this test, 9 commonly used sorting algorithms currently (insertion sort, shellsort, selection sort, heap sort, bubble sort, quicksort, merge sort, radix sort, and tim sort) are respectively used to sort target strings with the same data volume, and it is found that the tim sort algorithm takes the least time. Therefore, the tim sort algorithm is selected as the comparison algorithm.

[0105] The comparison results of the test are shown in Table 1 below:

[0106] Table 1

[0107]

[0108] As can be seen from Table 1, the sorting time of 1 million target strings of string type being phone numbers by the tim sort sorting algorithm is 1132 ms, and the sorting time of 3 million target strings of string type being phone numbers is 3551 ms. While the time taken to convert 1 million target strings of string type being phone numbers to numerical values and then sort them using the method of this application is 535 ms, and the sorting time of 3 million target strings of string type being phone numbers is 1568 ms. When the computer device sorts 3 million target strings of string type being phone numbers using the method of this embodiment of the application, the performance is improved by (3551 - 1568) / 3551 = 55.8% compared with the existing sorting algorithm. In the above table, when the computer device sorts 3 million target strings of random string type using the method of this embodiment of the application, the performance is improved by (9126 - 2297) / 9126 = 74.8% compared with the existing sorting algorithm. The performance comparison of the other two groups of 1 million - order - of - magnitude string sorting is similar and will not be elaborated. Thus, it can be seen that using the string processing method provided by this embodiment of the application improves the data processing efficiency of the computer device when performing string data processing.

[0109] The above mainly introduces the solution provided by the embodiment of this application from the perspective of the method. To implement the above functions, it includes the corresponding hardware structure and / or software module for executing each function. Those skilled in the art should easily realize that, combining the method steps of each example described in the embodiments disclosed in this article, this application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving the hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but this kind of implementation should not be considered to exceed the scope of this application.

[0110] The embodiment of this application can divide the function modules of the device for converting strings to numerical values according to the above method examples. For example, each function module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above - integrated module can be implemented in the form of hardware or in the form of a software function module. It should be noted that the division of modules in the embodiment of this application is illustrative, only a logical function division, and there can be other division methods in actual implementation.

[0111] As Figure 9 shown, it is a schematic structural diagram of a string processing device provided by the embodiment of this application. The string processing device 50 can be used to execute any one of the above - mentioned embodiments (such as Figure 4The functions performed by the computer device in the illustrated embodiments). The string processing device 50 includes: an acquisition unit 501, a determination unit 502, and a service processing unit 503. The acquisition unit 501 is configured to acquire a plurality of target strings. Each target string in the plurality of target strings includes at least one character. A first substring group is acquired from the same position of each target string. Among them, the first substring in the first substring group includes some or all of the characters in the target string where the first substring is located. The substrings in the first substring group correspond to the same digit positions. The determination unit 502 is configured to determine the base number of the digit positions corresponding to each substring in the first substring group according to the number of different substrings in the first substring group. According to the base number of the digit positions corresponding to each substring in the first substring group and the numerical value corresponding to each substring in the first substring group, determine the target numerical value corresponding to each target string. The service processing unit 503 is configured to process the plurality of target strings based on the target numerical value corresponding to each target string. For example, in combination with Figure 4 , the acquisition unit 501 can be used to execute S100 - S101, S103. The determination unit 502 can be used to execute S102, S104. The service processing unit 503 can be used to execute S105.

[0112] Optionally, the base number of the digit position corresponding to the first substring is greater than or equal to the number of different substrings in the first substring group and less than the first threshold.

[0113] Optionally, the acquisition unit 501 is further configured to: acquire the numerical value corresponding to each substring in the first substring group. Among them, the numerical values corresponding to different substrings are different, and the larger the ASCII code value of the substring, the larger the corresponding numerical value. The determination unit 502 is specifically configured to: convert each target string into a target numerical value based on the base number of the digit position corresponding to each substring in the first substring group and the numerical value corresponding to each substring in the first substring group.

[0114] Optionally, the acquisition unit 501 is specifically configured to: acquire a plurality of strings to be processed. The string processing device 50 further includes a conversion unit 504, and the conversion unit 504 is configured to: convert each string to be processed in the plurality of strings to be processed into a numerical value to obtain a plurality of target strings. Among them, the strings to be processed and the target strings are in one-to-one correspondence.

[0115] It should be noted that when the conversion unit 504 converts each string to be processed in the plurality of strings to be processed into a numerical value by using the method provided in this embodiment, it and the determination unit 502 can be one unit.

[0116] Optionally, the number of different substrings included in the plurality of target strings is less than or equal to the second threshold.

[0117] In one example, refer to Figure 2, the receiving function of the above-mentioned obtaining unit 501 can be implemented by Figure 2 the communication interface 104 in. The processing function of the above-mentioned obtaining unit 501, the determining unit 502, the service processing unit 503, and the conversion unit 504 can all be implemented by Figure 2 the processor 101 in calling the computer program stored in the memory 103.

[0118] For the specific description of the above optional manner, refer to the foregoing method embodiments, which will not be elaborated here. In addition, the explanations and beneficial effects of any of the above-provided string processing devices 50 can be referred to the corresponding method embodiments above, and will not be elaborated.

[0119] It should be noted that the actions corresponding to the above-mentioned respective modules are only specific examples, and the actions actually executed by each unit refer to the actions or steps mentioned in the description of the above-mentioned embodiments based on Figure 4 the embodiments described.

[0120] An embodiment of the present application further provides a device (such as a computer device or a chip), including: a memory and a processor; the memory is used to store a computer program, and the processor is used to call the computer program to execute the actions or steps mentioned in any of the above embodiments.

[0121] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program runs on a computer, the computer is caused to execute the actions or steps mentioned in any of the above embodiments.

[0122] An embodiment of the present application further provides a chip. The chip integrates circuits for implementing the functions of the above-mentioned string processing device and one or more interfaces. Optionally, the functions supported by the chip may include based on Figure 4 the processing actions in the embodiments described, which will not be elaborated here. Those of ordinary skill in the art can understand that all or part of the steps for implementing the above embodiments can be completed by a program instructing relevant hardware. The described program can be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a random access memory, etc. The above-mentioned processing unit or processor may be a central processing unit, a general-purpose processor, an application specific integrated circuit (ASIC), a digital signal processor (DSP), a field programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof.

[0123] The embodiments of the present application also provide a computer program product containing instructions. When the instructions run on a computer, the computer is caused to execute any one of the methods in the above embodiments. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from a website, a computer, a server, or a data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by the computer or a data storage device such as a server, a data center, etc. that includes one or more media integrated therein. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state disk (SSD)), etc.

[0124] It should be noted that the devices for storing computer instructions or computer programs provided in the embodiments of the present application, such as but not limited to, the above-mentioned memory, computer-readable storage medium, and communication chip, etc., are all non-transitory.

[0125] In the process of implementing the claimed present application, those skilled in the art can understand and implement other variations of the disclosed embodiments by referring to the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "a" or "one" does not exclude a plurality. A single processor or other unit may implement several functions recited in the claims. Certain measures are recited in mutually different dependent claims, but this does not mean that these measures cannot be combined to produce good results.

[0126] Although the present application has been described in conjunction with specific features and their embodiments, various modifications and combinations can be made without departing from the spirit and scope of the present application. Accordingly, the present specification and the drawings are merely exemplary illustrations of the present application defined by the appended claims, and are considered to have covered any and all modifications, variations, combinations, or equivalents within the scope of the present application.

Claims

1. A string processing method applied to a computer device, characterized in that, the method includes: Obtaining a plurality of target strings, where each target string in the plurality of target strings includes at least one character; Obtaining a first substring group from the same position of each target string; wherein, the first substring in the first substring group includes some or all of the characters in the target string where the first substring is located; the substrings in the first substring group correspond to the same digit; Determining the base number of the digit corresponding to each substring in the first substring group according to the number of different substrings in the first substring group; Determining the target value corresponding to each target string according to the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group, and processing the plurality of target strings based on the target value corresponding to each target string.

2. The method according to claim 1, characterized in that, the base number of the digit corresponding to the first substring is greater than or equal to the number of different substrings in the first substring group and less than a first threshold.

3. The method according to claim 1 or 2, characterized in that, the determining the target value corresponding to each target string according to the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group includes: Obtaining the value corresponding to each substring in the first substring group; wherein, the values corresponding to different substrings are different, and the substring with a larger American Standard Code for Information Interchange (ASCII) code value has a larger corresponding value; Converting each target string into a target value based on the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group.

4. The method according to claim 1 or 2, characterized in that, the obtaining a plurality of target strings includes: Obtaining a plurality of strings to be processed; Converting each string to be processed in the plurality of strings to be processed into a value to obtain a plurality of target strings; wherein, the string to be processed corresponds to the target string one by one.

5. A string processing device, characterized in that, the device includes: An obtaining unit, configured to obtain a plurality of target strings, where each target string in the plurality of target strings includes at least one character; obtain a first substring group from the same position of each target string; wherein, the first substring in the first substring group includes some or all of the characters in the target string where the first substring is located; the substrings in the first substring group correspond to the same digit; A determining unit, configured to determine the base number of the digit corresponding to each substring in the first substring group according to the number of different substrings in the first substring group; determine the target value corresponding to each target string according to the base number of the digit corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group; A service processing unit, configured to process the plurality of target strings based on the target value corresponding to each target string.

6. The apparatus according to claim 5, wherein, the base number of the digits corresponding to the first substring is greater than or equal to the number of different substrings in the first substring group and less than a first threshold value.

7. The apparatus according to claim 5 or 6, wherein, the obtaining unit is further configured to: obtain the value corresponding to each substring in the first substring group; wherein, the values corresponding to different substrings are different, and the larger the ASCII code value of the substring, the larger the value corresponding to the substring; the determining unit is specifically configured to convert each target string into a target value based on the base number of the digits corresponding to each substring in the first substring group and the value corresponding to each substring in the first substring group.

8. The apparatus according to claim 5 or 6, wherein, the obtaining unit is specifically configured to: obtain a plurality of strings to be processed; the apparatus further includes: a conversion unit, configured to: convert each string to be processed in the plurality of strings to be processed into a value, obtaining a plurality of target strings; wherein, the string to be processed and the target string are in one-to-one correspondence.

9. A computer device, wherein, it includes: a memory and a processor, the memory is used for storing a computer program, and the processor is used for executing the computer program to perform the method according to any one of claims 1-4.

10. A computer-readable storage medium, wherein, a computer program is stored on the computer-readable storage medium, and when the computer program runs on a computer, the computer is caused to execute the method according to any one of claims 1-4.

Citation Information

Patent Citations

  • A string processing method and device

    CN106033416A

  • Information push method and device, terminal equipment and storage medium

    CN107749861A

  • Document search method wherein stored documents and search queries comprise segmented text data of spaced, nonconsecutive text elements and words segmented by predetermined symbols

    US5748953A