Integer interval character string processing method and device, electronic equipment and storage medium

By converting integer interval strings into internal data structures and merging them, the problem of inefficient integer interval data processing in the prior art is solved, and more efficient data processing is achieved.

CN119691237APending Publication Date: 2025-03-25SHENZHEN RUIJIAN DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411508912.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-03-25

Smart Images

  • Figure CN119691237A_ABST
    Figure CN119691237A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, in particular to an integer interval character string processing method and device, electronic equipment and a storage medium. When a target character string is received, the character string number and the character string type of the target character string are determined, when it is determined that the character string number is 1 and the character string type is an integer type, integer interval character strings in the target character string are extracted, the integer interval character strings are converted into an internal data structure, and an integer interval list is obtained; and when it is determined that the first overlapping intervals exist in the integer interval list, the first overlapping intervals are merged to obtain the merged interval list, and finally the merged interval list is converted into the character string format from the internal data structure to obtain the merged interval character string, so that the processing efficiency of the integer interval character string is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to an integer interval character string processing method, device, electronic device and storage medium. Background Art

[0002] When processing data involving integer intervals, you often need to perform a series of complex operations, such as merging overlapping or adjacent intervals, removing specific intervals from existing intervals, or adding new intervals to existing intervals.

[0003] The existing method first splits the input interval string into individual intervals or integers and stores them in a data structure (such as a list). Then, these intervals are traversed through nested loops to check whether each pair of intervals overlaps or is adjacent. Assuming that two intervals overlap or are adjacent, they are merged into a new interval and the data structure is updated. This process requires multiple iterations, and as the number of intervals increases, the amount of computation increases sharply, which involves cumbersome logic and multiple iterations, resulting in low efficiency. Summary of the invention

[0004] In order to overcome the shortcomings of the prior art, the present application provides an integer interval string processing method, device, electronic device and storage medium, which can merge multiple integers or integer intervals at a time, remove multiple integers or integer intervals at a time, and add multiple integers or integer intervals in a specific range at a time, thereby improving the processing efficiency of integer interval strings.

[0005] A first aspect of the present application provides a method for processing an integer interval character string, the method comprising: When receiving a target character string, determining the character string quantity and character string type of the target character string; When it is determined that the number of character strings is 1 and the character string type is an integer type, extracting an integer interval character string from the target character string; Convert the integer interval character string into a first internal data structure to obtain an integer interval list; Determine whether there is a first overlapping interval in the integer interval list; When it is determined that the first overlapping intervals exist in the integer interval list, merging the first overlapping intervals to obtain a merged interval list; The merged interval list is converted from the first internal data structure into a string format to obtain a merged interval string.

[0006] In an optional implementation, determining whether the integer interval list has a first overlapping interval includes: Determine a first interval and a second interval in the integer interval list, wherein the first interval is any integer interval in the integer interval list, and the second interval is any integer interval in the integer interval list except the first interval; Determine a first start time and a first end time of the first interval, and a second start time and a second end time of the second interval; Determine whether the first start time is not later than the second end time plus 1, and whether the first end time is not earlier than the second start time minus 1; When the first start time is not later than the second end time plus 1, and the first end time is not earlier than the second start time minus 1, determining that the first overlapping interval exists in the integer interval list; When the first start time is later than the second end time plus 1, and / or the first end time is earlier than the second start time minus 1, it is determined that the first overlapping area does not exist in the integer interval list.

[0007] In an optional implementation, merging the first overlapping intervals to obtain a merged interval list includes: Determine the order of each interval in the integer interval list; Traversing each interval in the integer interval list based on the arrangement order, when it is determined that the target interval overlaps with the last interval in the merged list, merging the target interval with the last interval, wherein the target space is any integer interval in the integer interval list; When it is determined that the target interval does not overlap with the last interval, the target interval is added to the end of the merged list, so as to update the last interval based on the target interval.

[0008] In an optional embodiment, the method further comprises: When the number of the character strings is 2, and the character string types are a merged type and a type to be removed, extracting a first merged interval character string corresponding to the merged type and a to-be-removed interval character string corresponding to the to-be-removed type in the target character string; The interval character string to be removed is removed from the first merged interval character string to obtain a remaining interval character string.

[0009] In an optional implementation, removing the interval string to be removed from the first merged interval string to obtain a remaining interval string includes: Convert the first merged interval character string into a second internal data structure to obtain a first merged interval list, and convert the to-be-removed interval character string into the second internal data structure to obtain a to-be-removed interval list; Determine whether there is a second overlapping interval corresponding to the list of intervals to be removed in the first list of merged intervals; When it is determined that the second overlapping interval corresponding to the to-be-removed interval list exists in the first merged interval list, removing the to-be-removed interval list and the second overlapping interval from the first merged interval list to obtain a remaining interval list; The remaining interval list is converted into a string format to obtain the remaining interval string.

[0010] In an optional embodiment, the method further comprises: When the number of the character strings is 2, and the character string types are the merged type and the type to be added, extracting the second merged interval character string corresponding to the merged type and the interval character string to be added corresponding to the type to be added in the target character string; The interval character string to be added is added to the second merged interval character string to obtain a complete interval character string.

[0011] In an optional implementation, the adding the interval character string to be added to the second merged interval character string to obtain a complete interval character string includes: Convert the second merged interval character string into a third internal data structure to obtain a second merged interval list, and convert the to-be-added interval character string into the third internal data structure to obtain a to-be-added interval list; Adding the to-be-added interval list to the second merged interval list to obtain an initial interval list; Determine whether there is a third overlapping interval corresponding to the list of intervals to be added in the initial interval list; When it is determined that the third overlapping interval corresponding to the interval list to be added exists in the initial interval list, merging the third overlapping intervals to obtain a complete interval list; The complete interval list is converted into a string format to obtain the complete interval string.

[0012] A second aspect of the present application provides an integer interval character string processing device, the device comprising: A determination module, configured to determine the number and type of the target character string when receiving the target character string; an extraction module, configured to extract an integer interval character string from the target character string when it is determined that the number of character strings is 1 and the character string type is an integer type; A first conversion module, used for converting the integer interval character string into a first internal data structure to obtain an integer interval list; A judging module, configured to judge whether the integer interval list has a first overlapping interval; A merging module, configured to merge the first overlapping intervals to obtain a merged interval list when it is determined that the first overlapping intervals exist in the integer interval list; The second conversion module is configured to convert the merged interval list from the first internal data structure into a string format to obtain a merged interval string.

[0013] A third aspect of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the integer interval string processing method when executing the computer program.

[0014] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above-mentioned integer interval string processing method are implemented.

[0015] In summary, the integer interval string processing method, device, electronic device and storage medium provided by the present application ensure that only the integer interval string is processed by judging the number of strings and the string type of the target string when receiving the target string. When it is determined that the number of strings is 1 and the string type is an integer type, the integer interval string in the target string is extracted and converted into an internal data structure (such as an integer interval list), wherein the internal data structure allows more efficient interval comparison and merging, so it is easier to process than the original string, greatly improving the processing efficiency of the integer interval string. Then, the overlapping intervals are judged in the internal data structure. When it is determined that there are overlapping intervals, the overlapping intervals are merged and a merged interval list is generated, wherein the merged interval set is smaller than the original interval set. By merging the intervals, the amount of data that needs to be processed in the subsequent processing steps can be reduced, thereby improving the efficiency of data processing. Finally, the merged interval list is converted back to the string format for subsequent use. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a flowchart of an integer interval character string processing method shown in an embodiment of the present application; Figure 2 It is a flowchart of a method for merging interval character strings shown in an embodiment of the present application; Figure 3 It is a flowchart of a method for removing a specific interval character string from an interval character string shown in an embodiment of the present application; Figure 4 It is a flowchart of a method for adding a characteristic interval character string from an interval character string shown in an embodiment of the present application; Figure 5 It is a functional module diagram of an integer interval string processing device shown in an embodiment of the present application; Figure 6 It is a structural schematic diagram of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION

[0017] The present application is further described below in conjunction with the accompanying drawings and embodiments.

[0018] The following will clearly and completely describe the concept, specific structure and technical effects of the present application in combination with the embodiments and drawings, so as to fully understand the purpose, characteristics and effects of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of them. Based on the embodiments of the present application, other embodiments obtained by technicians in this field without creative work are all within the scope of protection of the present application. In addition, all the connection / connection relationships involved in the patent do not simply refer to the direct connection of components, but refer to the formation of a better connection structure by adding or reducing connection accessories according to the specific implementation situation. The various technical features created in this application can be combined interactively without conflicting with each other.

[0019] Reference Figure 1 As shown, it is a flow chart of an integer interval character string processing method shown in an embodiment of the present application, and the integer interval character string processing method includes the following steps.

[0020] S11, when a target character string is received, determining the character string quantity and character string type of the target character string.

[0021] The target string refers to the input string to be processed, which may contain one or more integers and / or one or more integer intervals. The integer interval is embedded in the string in a specific format (i.e., a specific separator), for example, the intervals are connected with "-", and different integers or integer intervals are separated by ",". It should be noted that the connection and separation methods between the above intervals and integers are only examples and are not limited in this application. For example, the target string is "1-3, 4-9".

[0022] In some embodiments, in tasks such as database query, network address management, event timeline processing, and resource allocation and optimization, data involving integer intervals need to be processed. When the electronic device processes the above tasks, when receiving user input or string data from other sources, the received string data is used as the target string, and then the target string is parsed to determine the number of strings in the target string and the type of each substring included in the target string (whether it is an integer type or a string containing an integer interval). Specifically, when determining the number of strings of the target string, the electronic device can be based on a single reception strategy, that is, designed to receive a complete string at a time, then the number of strings can be directly set to 1, and when two complete strings are received at a time, the number of strings can be directly set to 2, and so on. When determining the string type of the target string, the electronic device can pre-process the target string, such as removing blank characters (such as spaces, tabs, line breaks, etc.) at both ends of the target string to ensure the neatness of the string. Then, the target string is divided into multiple substrings according to specific delimiters (such as commas, separators, semicolons, etc.). After traversing each substring, the electronic device can use a regular expression or convert the substring to an integer type (such as using Python's int() function). If the conversion is successful, it is considered to be an integer type. Secondly, the electronic device can also check whether the substring contains a hyphen (such as "-") to determine the string type of the target string.

[0023] It should be noted that the number of strings of the target string in this application refers to the number of a complete string received at a single time at the current moment, rather than the number of substrings of the substrings contained in the target string. For example, the received string is "1-9, 8, 1-5", the number of substrings is 3, but the number of strings of the target string is 1; and assuming that the received strings are "1-9, 8" and "1-5, 7", the number of substrings is 4, but the number of strings of the target string is 2.

[0024] Exemplarily, the received target string is "1-5, 10, 15-20, abc", the number of strings is determined to be 1, and then the target string is split, using commas as delimiters to obtain ["1-5", "10", "15-20", "abc"], and the substring type is further determined, among which "1-5" contains a hyphen and is parsed as an integer interval type, "10" contains only numbers and is parsed as an integer type, "15-20" contains a hyphen and is parsed as an integer interval type, and "abc" cannot be parsed as an integer or integer interval and is recorded as an invalid type or directly ignored.

[0025] S12: When it is determined that the number of character strings is 1 and the character string type is an integer type, extract an integer interval character string from the target character string.

[0026] When only one target string is received, and it is determined that the substring in the target string is of integer type and / or can be parsed as an integer interval, the electronic device can extract the substring in the target string whose substring type is an integer type as an integer interval string. Specifically, the electronic device can segment the target string according to the same implementation method as in step S11 to determine which substrings in each substring have an integer string type, and then directly extract the substring as an integer interval string, so that the subsequent electronic device can process it based on the processing task. The processing tasks may include: merging integer interval strings, removing integer interval strings, and adding integer interval strings.

[0027] S13, converting the integer interval character string into a first internal data structure to obtain an integer interval list.

[0028] The first internal data structure refers to a data structure for storing integer intervals, which can be a list, an array or other data structure, in which each element represents an integer interval. Figure 2 In some embodiments, the integer interval string is converted into an Interval object, that is, the interval represented by the string is converted into an Interval object list to obtain an integer interval list. The interval is represented in two forms, a point represented by a single number, and a range represented by a start and end number. For example, if the input integer interval string is "1, 2-5, 8", it is converted into three Interval objects, that is, the integer interval list is (1, 1), (2, 5) and (8, 8).

[0029] Specifically, the electronic device can first create an ArrayList named intervals to store the converted Interval objects. Then, it obtains the integer interval string from the input parameter input and uses replaceAll( \\ s, "") method is used to remove all space characters in the integer interval string to ensure that subsequent processing will not cause errors due to spaces, and the split(",") method is used to separate the integer interval string after removing spaces into multiple parts by commas. Each part can be a single integer or an integer interval (composed of two integers connected by "-"). Further, each segmented string is traversed, and the contains("-") method is used to check whether the current part contains the "-" character. If it contains "-", it means that the current part is an interval. The electronic device can use the split("-") method to split the interval string into two substrings, representing the start value and end value of the interval respectively, and convert the two substrings into integer types and assign them to the start and end variables respectively. Finally, a new Interval object is created, start and end are passed in as parameters, and the object is added to the intervals list. If it does not contain "-", it means that the current part is a single integer. The electronic device can convert the current part into an integer type, assign it to the number variable, create a new Interval object, pass number as the start value and end value (that is, create an interval representing a single point), and add the object to the intervals list. When all parts are processed, the intervals list filled with Interval objects is returned to obtain the integer interval list. Assuming that the integer interval string is converted into an internal data structure, the integer interval string is still in string format, and the electronic device cannot compare the integer intervals. Although the integer interval string is not converted into an internal data structure, the electronic device can also process the integer interval string based on the processing task, but this technical solution is similar to the existing method. The integer interval string needs to be split into single intervals or integers, and multi-layer loop traversal is required to determine whether there are adjacent and overlapping integer intervals.

[0030] Through the above optional implementation, the integer interval string is converted into an internal data structure, that is, the Interval class is defined, and the interval is represented by the Interval class, so that each interval has two attributes start and end, which represent the starting point and end point of the interval respectively, so as to facilitate the subsequent comparison of the intervals in the integer interval string.

[0031] S14, determining whether the integer interval list contains a first overlapping interval.

[0032] Refer to Figure 2In some embodiments, the electronic device may check whether the current interval overlaps or is adjacent to another interval. Overlapping or being adjacent means that if any endpoint of two intervals falls inside or on the boundary of another interval, they are considered overlapping or adjacent. For example, for example, "1-3, 4-9" or "1-3, 3-9", "3" in "1-3" and "4" in "4-9" can be determined as adjacent intervals, while "3" in "1-3" and "3" in "3-9" can be determined as overlapping intervals.

[0033] In an optional implementation, determining whether the integer interval list has a first overlapping interval includes: Determine a first interval and a second interval in the integer interval list, wherein the first interval is any integer interval in the integer interval list, and the second interval is any integer interval in the integer interval list except the first interval; Determine a first start time and a first end time of the first interval, and a second start time and a second end time of the second interval; Determine whether the first start time is not later than the second end time plus 1, and whether the first end time is not earlier than the second start time minus 1; When the first start time is not later than the second end time plus 1, and the first end time is not earlier than the second start time minus 1, determining that the first overlapping interval exists in the integer interval list; When the first start time is later than the second end time plus 1, and / or the first end time is earlier than the second start time minus 1, it is determined that the first overlapping area does not exist in the integer interval list.

[0034] In some embodiments, the electronic device first selects an integer interval other than the current interval (first interval) from the integer interval list as another interval object (second interval) for comparison with the current interval. Assuming that the first interval overlaps or is adjacent to the second interval, true is returned, otherwise false is returned. Further, the electronic device continues to select any integer interval other than the first interval and the second interval as another interval object (third interval), and continues to determine whether the first interval overlaps or is adjacent to the third interval. Specifically, the electronic device can set a judgment condition to determine whether the first interval and the second interval overlap or are adjacent, wherein the judgment condition can be set to whether the start time of the first time (that is, the first start time, referred to as this.start) is not later than the end time of the second interval (that is, the second end time, referred to as other.end) plus one day (other.end+1), and whether the end time of the first interval (that is, the first end time, referred to as this.end) is not earlier than the start time of the second interval (that is, the second start time, referred to as other.start) minus one day (other.start -1), that is, this.start<= other.end+1&&this.end>=other.start-1. Among them, +1 and -1 are used to handle the situation where two intervals are exactly connected, ensuring that even if the time point differs by one day (assuming the time unit is day), they are considered adjacent. Assuming that the above two conditions are met at the same time, it means that the first interval overlaps or is adjacent to the second interval, and true is returned. Assuming that any one of the conditions is not met, false is returned, indicating that the first interval does not overlap or is not adjacent to the second interval. Then, according to the same implementation method as above, continue to judge whether the first interval and the third interval overlap or are adjacent, and judge whether the second interval and the third interval overlap or are adjacent. By analogy, it is directly judged whether all intervals in the integer interval list overlap or are adjacent, and the interval in the integer interval list that overlaps or is adjacent is called the first overlapping interval.

[0035] For example, suppose there are two intervals in the integer interval list, namely interval A and interval B. Suppose interval A starts at this.start = 1 and ends at this.end = 5, and interval B starts at other.start = 5 and ends at other.end = 10. The electronic device can call the overlaps method of interval A and pass in interval B as a parameter, which will return true because interval A and interval B are adjacent (that is, there is no gap between interval A and interval B). Suppose interval B starts at other.start = 6, then the electronic device will return false when calling the overlaps method, because interval A and interval B are neither overlapping nor adjacent (that is, there is a gap between interval A and interval B).

[0036] Through the above optional implementation, by traversing the integer interval list and comparing whether the intervals overlap or are adjacent (including the case where they are exactly connected), the electronic device can efficiently determine whether there is a first overlapping interval in the integer interval list, thereby ensuring accurate judgment of the interval relationship, which is of great significance for application scenarios such as interval scheduling and resource allocation, and improves the accuracy and reliability of the system.

[0037] S15: When it is determined that the first overlapping intervals exist in the integer interval list, merge the first overlapping intervals to obtain a merged interval list.

[0038] Refer to Figure 2 , when it is determined that there is a first overlapping interval in the integer interval list, and it is determined that the processing task is to merge the integer interval strings, the electronic device executes step S15. In some embodiments, the electronic device can use the merge method to merge the current interval object (this) with another interval object (other) into a new interval. Specifically, the minimum value of the starting points (start) of the two intervals is selected as the starting point of the new interval, and the maximum value of the ending points (end) of the two intervals is selected as the ending point of the new interval. Exemplarily, assuming that there are intervals "1-3, 4-9" or "1-3, 3-9", the results after merging are all "1-9".

[0039] Specifically, the electronic device can first use the Collections.sort method to sort the input interval list. The sorting is based on the starting position of each interval (start attribute). The electronic device can use a custom comparator to compare the starting positions of the two intervals through Integer.compare(i1.start, i2.start). Then, create a new ArrayList named merged to store the merged intervals. Furthermore, the electronic device can traverse each interval in the sorted integer interval list (that is, each Interval object). For each traversed interval, if the merged list is empty (that is, no interval has been merged), or the current interval does not overlap with the last interval in the merged list, then the current interval is added to the merged list. For example, the electronic device can assume that the Interval class has a method named overlaps to determine whether two intervals overlap. If the current interval (i.e., the target interval) overlaps with the last interval in the merged list, the two intervals are merged and the value of the last interval in the merged list is updated. For example, the electronic device can assume that the Interval class has a method called merge, which is used to merge two overlapping intervals, return the merged new interval, and update the end property of the calling Interval object (i.e., merged.get(merged.size() - 1)) to the larger end value of the two intervals. If the current interval does not overlap with the last interval in the merged list, the current interval is directly added to the end of the merged list, that is, the target interval is the last interval in the merged list. After traversing all intervals, the merged list is returned, which contains all non-overlapping intervals after the merge, that is, the merged interval list can be obtained.

[0040] In some embodiments, when it is determined that there is no first overlapping interval in the integer interval list, and it is determined that the processing task is to merge the integer interval string, the intervals in the integer interval list are still considered as a "large" interval for merging. For example, in the integer interval list, there are intervals "1-3" and "6-8" that are neither overlapping nor adjacent, and the merged "large" interval can be represented as "1-8".

[0041] S16: Convert the merged interval list from the first internal data structure into a string format to obtain a merged interval string.

[0042] Refer to Figure 2, in some embodiments, the electronic device may use the toString method to convert the merged intervals obtained in step S15 into a string format for easy recording. For example, assume that the start point and the end point of the interval are the same (i.e., the interval length is 0), then only the start point is displayed. Assume again that the start point and the end point of the interval are different, then the start point, a hyphen (-), and the end point are displayed.

[0043] Specifically, the electronic device can first initialize a string builder, that is, create a StringBuilder object for efficiently constructing the final string result. Then, use a for loop to traverse each Interval object in the merged list. Among them, the loop variable i starts from 0 until merged.size() (excluding merged.size()), that is, traverse the entire merged interval list, and convert each interval into a string and add it to the string builder. Inside the loop body, the electronic device can use the merged.get(i).toString() method to convert the currently traversed Interval object into a string form, and use the sb.append(...) method to add the converted string to the StringBuilder object. After adding the string of an interval, check whether the current interval is the last interval in the list. If not (i.e., i < merged.size() - 1), then append a comma (,) to the StringBuilder object as the separator between intervals. After traversing all intervals, use the sb.toString() method to convert the StringBuilder object into a string and return the string as the result.

[0044] In an alternative embodiment, the method further includes: When the number of strings is 2 and the string types are the merged type and the type to be removed, extract the first merged interval string corresponding to the merged type and the interval string to be removed corresponding to the type to be removed from the target string; Remove the interval string to be removed from the first merged interval string to obtain the remaining interval string.

[0045] In some embodiments, in some practical applications, it may be necessary to exclude some unwanted or invalid parts from a set of intervals to obtain a more accurate or more compliant result. For example, in the timeline management of events or tasks, it may be necessary to remove some invalid or expired intervals to maintain the accuracy and updateability of the timeline. In the data preprocessing stage, it may be necessary to remove those interval data that do not meet the conditions or are irrelevant to ensure the accuracy and efficiency of subsequent analysis or processing, etc. Refer to Figure 3, when the electronic device receives the target string and it is clear that the target string includes the merged interval string (called the first merged interval string) and the interval string to be removed, and the processing task is to remove the integer interval string, the electronic device first converts the first merged interval string and the interval string to be removed into an internal data structure (called the second internal structure) based on the same implementation method as step 13, and obtains the first merged interval list and the interval list to be removed respectively. Then, the electronic device can create a new result list named result for temporarily storing the processed intervals. Traverse each interval in the input merged list (that is, the first merged interval list), and the interval in each loop is called mergedInterval. For each mergedInterval, set a Boolean variable addInterval to true, indicating that the interval will be added to the result list by default. Traverse each interval in the input toRemove list (that is, the interval list to be removed), and the interval in each loop is called removeInterval. Further, the electronic device can use the mergedInterval.overlaps(removeInterval) method to check whether the mergedInterval overlaps with the removeInterval. If there is an overlap (that is, there is a second overlapping interval), set addInterval to false, indicating that the interval will not be added to the result list. If the starting position of mergedInterval is less than the starting position of removeInterval, it means that there is a remaining part on the left side of mergedInterval, and this part (that is, the new interval [mergedInterval.start, removeInterval.start-1]) is added to the result list. If the ending position of mergedInterval is greater than the ending position of removeInterval, it means that there is a remaining part on the right side of mergedInterval, and this part (that is, the new interval [removeInterval.end+1, mergedInterval.end]) is added to the result list. When the overlap between mergedInterval and an interval in the toRemove list is processed, if addInterval is still true (that is, mergedInterval does not overlap with any removeInterval), it is added to the result list.Then, the electronic device can use the Collections.sort method to sort the result list, where the sorting is based on the starting position of each interval, and create a new result list named mergedResult to store the final merged interval, that is, the first merged interval after removing the interval to be removed. Specifically, the electronic device can traverse the sorted result list in the same embodiment as step S15, and for each interval interval, if mergedResult is empty, or interval does not overlap with the last interval in mergedResult, add it to mergedResult. If it overlaps, the interval is merged with the last interval in mergedResult using the merge method, and the value of the last interval in mergedResult is updated to the merged new interval, so the electronic device can remove the interval list to be removed and the intervals overlapping or adjacent to the interval list to be removed (that is, the second overlapping interval) from the first merged interval list. Finally, after traversing the result list, the electronic device returns the mergedResult list, where the mergedResult list contains the first merged interval (called the remaining interval) after removing the interval to be removed and the second overlapping interval. Similarly, according to the same embodiment as step S16, the remaining interval can be converted into a character string format to obtain a remaining interval character string.

[0046] It should be noted that both the first merged interval character string and the to-be-removed interval character string include integers or integer interval character strings.

[0047] Through the above optional implementation, when the target string contains merged intervals and intervals to be removed, the remaining interval string after removing specific intervals can be accurately obtained through the conversion of internal data structures, detection and processing of overlapping intervals, and merging and sorting of final intervals, thereby improving the accuracy and efficiency of data processing.

[0048] In an optional embodiment, the method further comprises: When the number of the character strings is 2, and the character string types are the merged type and the type to be added, extracting the second merged interval character string corresponding to the merged type and the interval character string to be added corresponding to the type to be added in the target character string; The interval character string to be added is added to the second merged interval character string to obtain a complete interval character string.

[0049] In some embodiments, in some practical applications, it may be necessary to add new data ranges or time periods to the existing interval set to obtain more comprehensive information or make more accurate statistics. For example, when dealing with resource allocation issues, it may be necessary to add new resource intervals to meet more requests or requirements. In the timeline management of events or tasks, it may be necessary to add new time intervals to schedule new activities or tasks.

[0050] Refer to Figure 4 , when the electronic device receives the target string again, and it is clear that the target string includes a merged interval string (referred to as the second merged interval string) and an interval string to be added, and the processing task is a field integer interval string, the electronic device first converts the second merged interval string and the interval string to be added into an internal data structure (referred to as the third internal data structure) based on the same implementation method as step 13, and obtains the second merged interval list and the interval list to be added respectively. Then, the electronic device can add all the intervals in the interval list to be added to the second merged interval list to obtain a temporary list containing all intervals, referred to as the initial interval list. Further, the electronic device sorts the initial interval list and merges the intervals according to the same implementation method as step S15, so as to merge the intervals that overlap or are adjacent to the interval to be added (referred to as the third overlapping interval) to obtain a new list object, referred to as a complete interval list. Finally, based on the same implementation method as step S16, each interval in the complete interval list is converted into a string format to obtain a complete interval string.

[0051] It should be noted that both the second merged interval character string and the interval character string to be added include integers or integer interval character strings.

[0052] Through the above optional implementation, when the target string includes merged intervals and intervals to be added, the complete interval string after adding the specific interval can be accurately obtained through the conversion, sorting and merging operations of the internal data structure, thereby improving the accuracy and efficiency of data processing.

[0053] The embodiments of the present application can be applied to database query optimization, network address management, event timeline processing, resource allocation and optimization, etc. An example is given below to describe the practical application of the embodiments of the present application. Assume that a string of "1, 23, 3, 5-7, 9-19, 33-67, 83, 8, 85, 90, 87" is received, and then the integer intervals in the string are merged, that is, "5-7" and "9-19" are merged into "5-19", then the merged merged interval string output is "1, 3, 5-19, 23, 33-67, 83, 85, 87, 90". Assume that "1, 3, 5-19, 23, 33-67, 83, 85, 87, 90" is the merged interval string, and the interval string to be removed is "9, 40-46", then the interval string to be removed in the merged interval string is removed, and the remaining interval string is "1, 3, 5-8, 10-19, 23, 33-39, 47-67, 83, 85, 87, 90". Assume that the merged interval string is "1-5, 9, 26-34, 57", and the interval string to be added is "6, 10-15, 58", then the interval string to be added is added to the merged interval string for processing, and the complete interval string is "1-6, 9-15, 26-34, 57-58".

[0054] Reference Figure 5 , which is a functional module diagram of an integer interval string processing device shown in an embodiment of the present application.

[0055] In some embodiments, the integer interval string processing device 50 may include a plurality of functional modules composed of computer program segments. The computer program of each program segment of the integer interval string processing device 50 may be stored in a memory of an electronic device and executed by at least one processor to perform (see Figure 1 Description) Function for integer range string processing.

[0056] In this embodiment, the integer interval string processing device can be divided into multiple functional modules according to the functions it performs. The functional modules may include: a determination module 501, an extraction module 502, a first conversion module 503, a judgment module 504, a merging module 505, a second conversion module 506, a removal module 507 and an addition module 508. The module referred to in this application refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.

[0057] The determination module 501 is used to determine the number and type of the target character string when receiving the target character string.

[0058] The extraction module 502 is configured to extract an integer interval character string from the target character string when it is determined that the number of character strings is 1 and the character string type is an integer type.

[0059] The first conversion module 503 is used to convert the integer interval character string into a first internal data structure to obtain an integer interval list.

[0060] The determining module 504 is configured to determine whether the integer interval list has a first overlapping interval.

[0061] The merging module 505 is configured to merge the first overlapping intervals to obtain a merged interval list when it is determined that the first overlapping intervals exist in the integer interval list.

[0062] The second conversion module 506 is configured to convert the merged interval list from the first internal data structure into a string format to obtain a merged interval string.

[0063] The judgment module 504 is further specifically used to: determine a first interval and a second interval in the integer interval list, the first interval being any integer interval in the integer interval list, and the second interval being any integer interval in the integer interval list except the first interval; determine a first start time and a first end time of the first interval, and a second start time and a second end time of the second interval; determine whether the first start time is not later than the second end time plus 1, and the first end time is not earlier than the second start time minus 1; when the first start time is not later than the second end time plus 1, and the first end time is not earlier than the second start time minus 1, determine that the integer interval list has the first overlapping interval; when the first start time is later than the second end time plus 1, and / or the first end time is earlier than the second start time minus 1, determine that the integer interval list does not have the first overlapping area.

[0064] The merging module 505 is further specifically used to: determine the arrangement order of each interval in the integer interval list; traverse each interval in the integer interval list based on the arrangement order, and when it is determined that the target interval overlaps with the last interval in the merged list, merge the target interval with the last interval, wherein the target space is any integer interval in the integer interval list; when it is determined that the target interval does not overlap with the last interval, add the target interval to the end of the merged list to update the last interval based on the target interval.

[0065] The removal module 507 is used to: when the number of the strings is 2 and the string types are a merged type and a type to be removed, extract the first merged interval string corresponding to the merged type and the interval string to be removed corresponding to the type to be removed in the target string; remove the interval string to be removed from the first merged interval string to obtain a remaining interval string.

[0066] The removal module 507 is further specifically used to: convert the first merged interval character string into a second internal data structure to obtain a first merged interval list, and convert the interval character string to be removed into the second internal data structure to obtain a list of intervals to be removed; determine whether there is a second overlapping interval corresponding to the list of intervals to be removed in the first merged interval list; when it is determined that the second overlapping interval corresponding to the list of intervals to be removed exists in the first merged interval list, remove the list of intervals to be removed and the second overlapping interval from the first merged interval list to obtain a list of remaining intervals; convert the remaining interval list into a character string format to obtain the remaining interval character string.

[0067] The adding module 508 is used to: when the number of the strings is 2 and the string types are the merged type and the type to be added, extract the second merged interval string corresponding to the merged type and the interval string to be added corresponding to the type to be added in the target string; add the interval string to be added to the second merged interval string to obtain a complete interval string.

[0068] The adding module 508 is further specifically used to: determine whether there is a third overlapping interval corresponding to the interval list to be added in the initial interval list; when it is determined that the third overlapping interval corresponding to the interval list to be added exists in the initial interval list, merge the third overlapping intervals to obtain a complete interval list; convert the complete interval list into a string format to obtain the complete interval string.

[0069] It should be understood that the various variations and specific embodiments of the integer interval string processing method provided in the above embodiments are also applicable to the integer interval string processing device of the present embodiment. Through the above detailed description of the integer interval string processing method, those skilled in the art can clearly know the implementation method of the integer interval string processing device in the present embodiment. For the sake of brevity of the specification, it will not be described in detail here.

[0070] See also Figure 6 FIG. 1 is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. In a preferred embodiment of the present application, the electronic device 6 includes a memory 61 , at least one processor 62 and at least one communication bus 63 .

[0071] Those skilled in the art should understand that Figure 6 The structure of the electronic device 6 shown does not constitute a limitation of the embodiments of the present application, and can be either a bus structure or a star structure. The electronic device 6 can also include more or less other hardware or software than shown in the figure, or a different component arrangement.

[0072] In some embodiments, the electronic device 6 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application-specific integrated circuits, programmable gate arrays, digital processors, and embedded devices. The electronic device 6 may also include user equipment, which includes but is not limited to any electronic product that can interact with a user through a keyboard, mouse, remote control, touchpad, or voice control device, such as a personal computer, tablet computer, smart phone, digital camera, etc.

[0073] In the above embodiments provided in the present application, it should be understood that the disclosed methods, devices, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple components or modules can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or components or modules, which can be electrical, mechanical or other forms.

[0074] The components described as separate components may or may not be physically separated, and the components shown as components may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the components may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0075] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each component can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0076] The integrated module is assumed to be implemented in the form of a software function module and sold or used as an independent product, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0077] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0078] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0079] The above is a specific description of the preferred implementation of the present application, but the invention of the present application is not limited to the described embodiments. Technical personnel familiar with the field can also make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.

Claims

1. A method for processing integer interval character strings, characterized in that: The method comprises: When receiving a target character string, determining the character string quantity and character string type of the target character string; When it is determined that the number of character strings is 1 and the character string type is an integer type, extracting an integer interval character string from the target character string; Convert the integer interval character string into a first internal data structure to obtain an integer interval list; Determine whether there is a first overlapping interval in the integer interval list; When it is determined that the first overlapping intervals exist in the integer interval list, merging the first overlapping intervals to obtain a merged interval list; The merged interval list is converted from the first internal data structure into a string format to obtain a merged interval string.

2. The integer interval character string processing method according to claim 1, characterized in that: The determining whether the integer interval list has a first overlapping interval comprises: Determine a first interval and a second interval in the integer interval list, wherein the first interval is any integer interval in the integer interval list, and the second interval is any integer interval in the integer interval list except the first interval; Determine a first start time and a first end time of the first interval, and a second start time and a second end time of the second interval; Determine whether the first start time is not later than the second end time plus 1, and whether the first end time is not earlier than the second start time minus 1; When the first start time is not later than the second end time plus 1, and the first end time is not earlier than the second start time minus 1, determining that the first overlapping interval exists in the integer interval list; When the first start time is later than the second end time plus 1, and / or the first end time is earlier than the second start time minus 1, it is determined that the first overlapping area does not exist in the integer interval list.

3. The integer interval character string processing method according to claim 1, characterized in that: The merging the first overlapping intervals to obtain a merged interval list includes: Determine the order of each interval in the integer interval list; Traversing each interval in the integer interval list based on the arrangement order, when it is determined that the target interval overlaps with the last interval in the merged list, merging the target interval with the last interval, wherein the target space is any integer interval in the integer interval list; When it is determined that the target interval does not overlap with the last interval, the target interval is added to the end of the merged list, so as to update the last interval based on the target interval.

4. The integer interval character string processing method according to claim 1, characterized in that: The method further comprises: When the number of the character strings is 2, and the character string types are a merged type and a type to be removed, extracting a first merged interval character string corresponding to the merged type and a to-be-removed interval character string corresponding to the to-be-removed type in the target character string; The interval character string to be removed is removed from the first merged interval character string to obtain a remaining interval character string.

5. The integer interval character string processing method according to claim 4, characterized in that: The removing the interval string to be removed from the first merged interval string to obtain the remaining interval string comprises: Convert the first merged interval character string into a second internal data structure to obtain a first merged interval list, and convert the to-be-removed interval character string into the second internal data structure to obtain a to-be-removed interval list; Determine whether there is a second overlapping interval corresponding to the list of intervals to be removed in the first list of merged intervals; When it is determined that the second overlapping interval corresponding to the to-be-removed interval list exists in the first merged interval list, removing the to-be-removed interval list and the second overlapping interval from the first merged interval list to obtain a remaining interval list; The remaining interval list is converted into a string format to obtain the remaining interval string.

6. The integer interval character string processing method according to claim 4, characterized in that: The method further comprises: When the number of the character strings is 2, and the character string types are the merged type and the type to be added, extracting the second merged interval character string corresponding to the merged type and the interval character string to be added corresponding to the type to be added in the target character string; The interval character string to be added is added to the second merged interval character string to obtain a complete interval character string.

7. The integer interval character string processing method according to claim 6, characterized in that: The step of adding the interval character string to be added to the second merged interval character string to obtain a complete interval character string includes: Convert the second merged interval character string into a third internal data structure to obtain a second merged interval list, and convert the to-be-added interval character string into the third internal data structure to obtain a to-be-added interval list; Adding the to-be-added interval list to the second merged interval list to obtain an initial interval list; Determine whether there is a third overlapping interval corresponding to the list of intervals to be added in the initial interval list; When it is determined that the third overlapping interval corresponding to the interval list to be added exists in the initial interval list, merging the third overlapping intervals to obtain a complete interval list; The complete interval list is converted into a string format to obtain the complete interval string.

8. An integer interval character string processing device, characterized in that: The device comprises: A determination module, configured to determine the number and type of the target character string when receiving the target character string; an extraction module, configured to extract an integer interval character string from the target character string when it is determined that the number of character strings is 1 and the character string type is an integer type; A first conversion module, used for converting the integer interval character string into a first internal data structure to obtain an integer interval list; A judging module, configured to judge whether the integer interval list has a first overlapping interval; A merging module, configured to merge the first overlapping intervals to obtain a merged interval list when it is determined that the first overlapping intervals exist in the integer interval list; The second conversion module is configured to convert the merged interval list from the first internal data structure into a string format to obtain a merged interval string.

9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the integer interval character string processing method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the integer interval character string processing method described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Database object processing method, system, equipment and medium

    CN122086998A