Interval data merging method and device
By using ordered sets for sorting and recursive merging in interval data merging, the problem of low data storage and computing efficiency in the prior art is solved, and fast merging and efficient query are achieved.
Patent Information
- Application Number
- CN202310834231.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-07
- Publication Date
- 2025-01-07
AI Technical Summary
The prior art requires querying the full amount of data when merging interval data, resulting in large consumption of data storage resources, low query efficiency and long calculation time.
By generating the key names and weight values of interval data, adding them to the ordered set, recursively merging using index positions, reducing data storage and calculation times, and improving query efficiency.
Save data storage resources, reduce computing time, improve data query and computing efficiency, and realize fast interval data merging.
Smart Images

Figure CN119271665A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for merging interval data. Background Art
[0002] Interval merging is a common and effective method for processing overlapping intervals. It is usually used in scenarios where time interval merging is required, such as clock-in time calculation, business hours calculation, and video viewing progress calculation. For this scenario, the general solution is to save the interval data generated by the user into the database. When calculating the total length of time, all previously saved data will be queried, and then traversed to determine whether interval merging can be performed one by one, so as to merge the data in the intervals that can be merged.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] It is necessary to save all the user's time interval data, which consumes a large amount of data storage resources; when calculating the total length of time, it is necessary to query the entire data, which has low query efficiency, a large number of calculations, and a long calculation time. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for merging interval data, which can reduce the pressure of data storage and save data storage resources. Since the interval data is sorted based on the ordered set, when calculating the total length of time, there is no need to query the full amount of data, and it can be quickly determined whether the interval data can be merged, thereby reducing the number of calculations and calculation time, and improving data query efficiency and data calculation efficiency.
[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for merging interval data is provided, comprising: generating a key name and a key value corresponding to the interval data according to input parameters, and calculating a weight value of the interval data according to the key value; adding the interval data to an ordered set according to the key name and the weight value, and obtaining the index position of the interval data in the ordered set; recursively merging the interval data with the interval data before the index position in the ordered set to obtain merged interval data; recursively merging the merged interval data with the interval data after the index position in the ordered set to obtain a merged result of the interval data in the ordered set.
[0007] Optionally, the interval data is recursively merged with the interval data located before the index position in the ordered set to obtain merged interval data, including: according to the index position of the interval data, obtaining the interval data corresponding to the previous index position of the index position of the interval data from the ordered set as the first interval data to be merged; when the interval data and the first interval data to be merged can be merged, merging the interval data and the first interval data to be merged to obtain a first merged result, adding the first merged result to the ordered set, and deleting the interval data and the first interval data to be merged from the ordered set; using the first merged result as the interval data, using the index position of the first merged result in the ordered set as the index position of the interval data, and repeating the above operations until the interval data and the first interval data to be merged cannot be merged; using the interval data when the interval data and the first interval data to be merged cannot be merged as the merged interval data.
[0008] Optionally, the merged interval data is recursively merged with the interval data located after the index position in the ordered set to obtain a merge result of the interval data in the ordered set, including: according to the index position of the merged interval data, obtaining from the ordered set the interval data corresponding to the index position after the index position of the merged interval data as the second interval data to be merged; when the merged interval data and the second interval data to be merged can be merged, merging the merged interval data and the second interval data to be merged to obtain a second merged result, adding the second merged result to the ordered set, and deleting the merged interval data and the second interval data to be merged from the ordered set; using the second merged result as the merged interval data, using the index position of the second merged result in the ordered set as the index position of the merged interval data, and repeating the above operations until the merged interval data and the second interval data to be merged cannot be merged; using the ordered set obtained when the merged interval data and the second interval data to be merged cannot be merged as the merged result of the interval data in the ordered set.
[0009] Optionally, two interval data are merged by the following algorithm: creating a merge result array for storing the merge result of the two interval data to be merged; respectively obtaining the left endpoint value and the right endpoint value of the two interval data; taking the interval data with the smaller left endpoint value of the two interval data as the first interval data, and the interval data with the larger left endpoint value as the second interval data; adding the first interval data to the merge result array; when the left endpoint value of the second interval data is greater than the right endpoint value of the first interval data, adding the second interval data to the end of the merge result array to obtain the merge result of the two interval data; when the left endpoint value of the second interval data is not greater than the right endpoint value of the first interval data, if the right endpoint value of the second interval data is greater than the right endpoint value of the first interval data, modifying the right endpoint value of the first interval data in the merge result array to the right endpoint value of the second interval data to obtain the merge result of the two interval data; otherwise, not modifying the right endpoint value of the first interval data in the merge result array, and directly obtaining the merge result of the two interval data.
[0010] Optionally, after obtaining the merging result of the two interval data, the method further includes: when the merging result array includes the two interval data, or the length of the merging result array is 2, determining that the two interval data cannot be merged.
[0011] Optionally, the input parameters include the resource identifier, user information, start time and end time corresponding to the interval data; generating the key name and key value corresponding to the interval data according to the input parameters, including: generating the key name corresponding to the interval data according to the resource identifier and user information corresponding to the interval data; generating the key value corresponding to the interval data according to the start time and end time corresponding to the interval data.
[0012] Optionally, calculating the weight value of the interval data according to the key value includes: calculating the weight value of the interval data according to left and right endpoint values of the time interval corresponding to the key value.
[0013] Optionally, the interval data is added to an ordered set according to the key name and the weight value, including: obtaining a corresponding target ordered set according to the key name; adding the interval data to the target ordered set according to the weight value, wherein the interval data in the target ordered set is arranged in ascending order of weight value.
[0014] According to another aspect of an embodiment of the present invention, a device for merging interval data is provided, comprising: a data weight calculation module, used to generate a key name and a key value corresponding to the interval data according to an input parameter, and calculate a weight value of the interval data according to the key value; an index position acquisition module, used to add the interval data to an ordered set according to the key name and the weight value, and obtain the index position of the interval data in the ordered set; a first recursive merging module, used to recursively merge the interval data with the interval data in the ordered set that is located before the index position to obtain merged interval data; and a second recursive merging module, used to recursively merge the merged interval data with the interval data in the ordered set that is located after the index position to obtain a merge result of the interval data in the ordered set.
[0015] According to another aspect of an embodiment of the present invention, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the interval data merging method provided by an embodiment of the present invention.
[0016] According to another aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the interval data merging method provided by the embodiments of the present invention is implemented.
[0017] An embodiment of the above invention has the following advantages or beneficial effects: by generating the key name and key value corresponding to the interval data according to the input parameters, and calculating the weight value of the interval data according to the key value; adding the interval data to the ordered set according to the key name and weight value, and obtaining the index position of the interval data in the ordered set; recursively merging the interval data with the interval data before the index position in the ordered set to obtain the merged interval data; recursively merging the merged interval data with the interval data after the index position in the ordered set to obtain the merged result of the interval data in the ordered set. The ordered set stores the non-mergeable interval data, so the pressure of data storage can be reduced and data storage resources can be saved. Since the interval data is sorted based on the ordered set, when calculating the total length of time, there is no need to query the full amount of data, and it can be quickly determined whether the interval data can be merged, thereby reducing the number of calculations and calculation time, and improving data query efficiency and data calculation efficiency.
[0018] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0020] Figure 1 is a schematic diagram of main steps of a method for merging interval data according to an embodiment of the present invention;
[0021] Figure 2 It is a schematic diagram of the interval data merging process according to an embodiment of the present invention;
[0022] Figure 3 is a schematic diagram of main modules of a device for merging interval data according to an embodiment of the present invention;
[0023] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0024] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0026] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution disclosed in the present invention are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0027] In order to solve the technical problems existing in the prior art, to improve the efficiency of interval merging, to reduce the pressure of resource storage, and to avoid querying the full amount of data, the present invention proposes a method for interval merging based on cache. The method utilizes the ordered set (Sorted Set) data structure in the cache database (for example, redis database) to save the data to be sorted, and the data structure realizes an ordered and unique key-value pair set of data. When saving data, the interval data of each user is distinguished according to the different data key names, and the user's interval is sorted by weight score. In the present invention, the score value is equal to the sum of the left and right endpoints of the interval. When saving interval data, the new interval data is first saved in the cache, and then the index position of the new interval data in the ordered set is used as the reference point, and the value of the left index position is found to the left for recursive merging, and then the result of the left merging is found to the right for recursive merging. The original stored interval data and the newly inserted interval data are deleted each time they are merged, and the result after merging is treated as new data for recursive merging. Using this method to sort interval data in the cache reduces the amount of data queried during merging and the number of interval merging calculations, thereby improving computing efficiency.
[0028] Among them, the ordered set (Sorted Set) is a data structure in the redis cache database. This data structure uses a weight (score) to sort the members in the set from small to large according to the score value. The business scenario of the present invention is to realize the merging of time intervals. In one embodiment, the left endpoint of the time interval is, for example, the time when the video playback starts, and the right endpoint is, for example, the time when the video playback ends. The sum of the left and right endpoints is the sum of the time when the video playback starts and the time when the playback ends. The sum of these two time values is used as the score value to sort the videos in the set. For example, if the time interval is [6,8], the score value of the interval is equal to 14.
[0029] Figure 1 FIG. 1 is a schematic diagram of the main steps of the method for merging interval data according to an embodiment of the present invention. Figure 1 As shown, the interval data merging method of the embodiment of the present invention mainly includes the following steps S101 to S104.
[0030] Step S101: Generate a key name and a key value corresponding to the interval data according to the input parameters, and calculate a weight value of the interval data according to the key value.
[0031] According to an embodiment of the present invention, the input parameters include the resource identifier, user information, start time and end time corresponding to the interval data. The resource identifier is, for example, the video identifier id (Identity document) browsed by the user, the user information includes, for example, the user nickname, user identifier, user type and other information, the start time is, for example, the time when the user starts playing the video, and the end time is, for example, the time when the user ends playing the video, etc.
[0032] In one embodiment of the present invention, generating a key name and a key value corresponding to the interval data according to input parameters may specifically include: generating a key name corresponding to the interval data according to the resource identifier and user information corresponding to the interval data; generating a key value corresponding to the interval data according to the start time and end time corresponding to the interval data. The key name key is, for example, a combination of the video id, user nickname, user type, and user identifier; the key value value is, for example, a time interval consisting of the start time and the end time. For example: the start time is 6, the end time is 8, and the value is "6-8", which can also be expressed as the time interval [6, 8].
[0033] According to one of the embodiments of the present invention, the weight value of the interval data is calculated according to the key value, which may specifically include: calculating the weight value of the interval data according to the left and right endpoint values of the time interval corresponding to the key value. In an embodiment of the present invention, for example, an ordered set (Sorted Set) data structure in a cache database (for example, a redis database) is selected to save the interval data that needs to be sorted, and the interval data includes a key name and a key value. When saving the interval data, the interval data is sorted from small to large according to the weight value corresponding to the interval data, wherein the weight value can be calculated by the sum of the left endpoint and the right endpoint of the time interval corresponding to the key value. By sorting the interval data according to the weight value and judging in order whether the interval data can be merged, the number of merges of the interval data can be reduced.
[0034] Step S102: adding the interval data to an ordered set according to the key name and the weight value, and obtaining the index position of the interval data in the ordered set.
[0035] According to one embodiment of the present invention, adding the interval data to an ordered set according to the key name and the weight value includes: obtaining the corresponding target ordered set according to the key name; adding the interval data to the target ordered set according to the weight value, wherein the interval data in the target ordered set is arranged in order from small to large according to the weight value. In an embodiment of the present invention, the ordered storage of interval data is performed based on the ordered set of the cache database. When saving data, the interval data of each user is distinguished by the different keys, and the interval data of the user is sorted by the weight value of the interval data. One implementation method is, for example: first obtain the corresponding target ordered set according to the key name of the interval data, then determine the position of the interval data in the target ordered set according to the weight of the interval data, and then add the interval data to the target ordered set according to the position. When storing interval data in an ordered set in the cache, for example, the zadd command of the redis cache database can be used to implement adding data to the ordered set.
[0036] After adding the interval data to the ordered set, you can use the zrank command of the redis cache database to obtain the index position of the newly inserted interval data in the ordered set. The index position is the position of a certain data in the set, starting from 0. For example, in the set {1,4,2,6}, the index position of 6 is 3.
[0037] Step S103: recursively merge the interval data with the interval data before the index position in the ordered set to obtain merged interval data. After obtaining the index position of the interval data in the ordered set, this step will execute a recursive merge of the interval data with the interval data whose index position is smaller than the index position of the interval data. In one embodiment, for example, the zrange command of the redis cache database can be used to find the value of the previous index position for recursive merging (for example: the index position of the interval data is 2, and looking forward is to find the interval data with an index position of 1 and merge it with it).
[0038] According to one embodiment of the present invention, recursively merging the interval data with the interval data located before the index position in the ordered set to obtain merged interval data may specifically include: according to the index position of the interval data, obtaining from the ordered set the interval data corresponding to the previous index position of the index position of the interval data as the first interval data to be merged; if the interval data and the first interval data to be merged can be merged, merging the interval data and the first interval data to be merged to obtain a first merged result, adding the first merged result to the ordered set, and deleting the interval data and the first interval data to be merged from the ordered set; using the first merged result as the interval data, using the index position of the first merged result in the ordered set as the index position of the interval data, and repeatedly performing the above operations until the interval data and the first interval data to be merged cannot be merged; using the interval data when the interval data and the first interval data to be merged cannot be merged as the merged interval data.
[0039] According to the technical solution of the present invention, specifically, two interval data are merged by the following algorithm: creating a merge result array for storing the merge result of the two interval data to be merged; respectively obtaining the left endpoint value and the right endpoint value of the two interval data; taking the interval data with the smaller left endpoint value of the two interval data as the first interval data, and the interval data with the larger left endpoint value as the second interval data; adding the first interval data to the merge result array; in the case where the left endpoint value of the second interval data is greater than the right endpoint value of the first interval data, adding the second interval data to the end of the merge result array to obtain the merge result of the two interval data; in the case where the left endpoint value of the second interval data is not greater than the right endpoint value of the first interval data, if the right endpoint value of the second interval data is greater than the right endpoint value of the first interval data, then modifying the right endpoint value of the first interval data in the merge result array to the right endpoint value of the second interval data to obtain the merge result of the two interval data; otherwise, not modifying the right endpoint value of the first interval data in the merge result array, and directly obtaining the merge result of the two interval data.
[0040] Furthermore, after obtaining the merging result of the two interval data, the method further includes: determining that the two interval data cannot be merged when the merging result array includes the two interval data or the length of the merging result array is 2. The merging result array is a two-dimensional array.
[0041] For example, there are multiple interval data {[1,3], [4,5], [6,9], [10,12]} in the ordered set. If the newly inserted interval data is [3,7], since the weight value of this interval data is 10, it is between the weight values of [4,5] and [6,9]. Therefore, [3,7] is added to this ordered set, and this ordered set becomes {[1,3], [4,5], [3,7], [6,9], [10,12]}. At this time, the index position of [3,7] is 2. According to the index position of the interval data [3,7], the first interval data to be merged corresponding to its previous index position (i.e.: 1) is [4,5]. After that, it is determined whether the interval data [3,7] and the first interval data to be merged [4,5] can be merged.
[0042] Specifically, first, the left endpoint value 3 of the interval data [3,7] is less than the left endpoint value 4 of the first interval data to be merged [4,5], so the interval data [3,7] is added to the pre-created merge result array result; secondly, the left endpoint value 4 of the first interval data to be merged [4,5] is less than the right endpoint value 7 of the interval data [3,7], but the right endpoint value 5 of the first interval data to be merged [4,5] is also less than the right endpoint value 7 of the interval data [3,7], so there is no need to modify the right endpoint value of the interval data [3,7] stored in the merge result array result, and the interval data [3,7] in the merge result array result is directly used as the merge result. At this time, there is only one interval data [3,7] in the merge result array result, so the merge is successful, and the result after the merge is the first merge result [3,7].
[0043] After merging the interval data [3,7] and the first interval data to be merged [4,5], the original interval data [3,7] and the first interval data to be merged [4,5] are deleted from the ordered set (for example, this can be achieved by using the zrem command of the redis cache database), and the first merged result [3,7] obtained by merging is added to the ordered set. At this time, the ordered set is updated to: {[1,3], [3,7], [6,9], [10,12]}. Then, the first merged result [3,7] is used as the interval data again, and its index position (now changed to 1) is used as the index position of the interval data. The first interval data to be merged corresponding to the previous index position (i.e., 0) is obtained from the ordered set as [1,3], and the previous steps are repeated to merge, and the first merged result is [1,7]. At this time, the ordered set becomes {[1,7], [6,9], [10,12]}. Since the first merge result [1,7] does not have the first interval data to be merged corresponding to the previous index position, the interval data and the first interval data to be merged meet the condition that they cannot be merged, and no further recursive merging will be performed. At this time, the first merge result [1,7] is used as the merged interval data for backward recursive merging.
[0044] Step S104: recursively merge the merged interval data with the interval data after the index position in the ordered set to obtain a merged result of the interval data in the ordered set. The method used in merging interval data is the same as the interval data merging algorithm introduced in the above embodiment, which will not be repeated here.
[0045] According to one embodiment of the present invention, when recursively merging the merged interval data with the interval data located after the index position in the ordered set to obtain the merge result of the interval data in the ordered set, it can specifically include: according to the index position of the merged interval data, obtaining from the ordered set the interval data corresponding to the index position after the index position of the merged interval data as the second interval data to be merged; when the merged interval data and the second interval data to be merged can be merged, merging the merged interval data and the second interval data to be merged to obtain a second merged result, adding the second merged result to the ordered set, and deleting the merged interval data and the second interval data to be merged from the ordered set; using the second merged result as the merged interval data, using the index position of the second merged result in the ordered set as the index position of the merged interval data, and repeatedly performing the above operations until the merged interval data and the second interval data to be merged cannot be merged; using the ordered set obtained when the merged interval data and the second interval data to be merged cannot be merged as the merge result of the interval data in the ordered set.
[0046] In combination with the embodiment described above, there are multiple interval data {[1,3], [4,5], [6,9], [10,12]} in the ordered set. After the new interval data [3,7] is inserted, the forward recursive merge is first performed to obtain the merged interval data [1,7]. Subsequently, the backward recursive merge will be performed based on the merged interval data [1,7]. At this time, the start time in the input parameter can be modified to 1 and the end time to 7 to determine that the recursive merge needs to start from the merged interval data [1,7].
[0047] Specifically, first, the index position of the merged interval data [1,7] in the ordered set is 0. According to the index position of the interval data [1,7], the second interval data to be merged corresponding to the next index position (i.e., 1) can be obtained as [6,9]. After that, it is determined whether the merged interval data [1,7] and the second interval data to be merged [6,9] can be merged. The determination process is omitted here. After determination, the merged interval data [1,7] and the second interval data to be merged [6,9] can be merged, and the result after the merger is the second merged result [1,9].
[0048] After merging the merged interval data [1,7] and the second interval data to be merged [6,9], the original merged interval data [1,7] and the second interval data to be merged [6,9] are deleted from the ordered set (for example, this can be achieved by the zrem command of the redis cache database), and the second merged result [1,9] obtained by merging is added to the ordered set. At this time, the ordered set is updated to: {[1,9], [10,12]}. Then, the second merged result [1,9] is used as the merged interval data again, and its index position (still 0 at this time) is used as the index position of the merged interval data. The second interval data to be merged corresponding to the next index position (i.e.: 1) is obtained from the ordered set as [10,12], and it is determined whether the merge can be performed. Here, since the left endpoint value 10 of the second interval data to be merged [10,12] is greater than the right endpoint value of the merged interval data [1,9], the merged result stored in the merged result array result should be [[1,9], [10,12]]. At this time, the length of the merged result array is 2, or in other words, the merged result array includes these two interval data, so it is determined that the two interval data cannot be merged, and the merge ends. Finally, the merged result of the interval data in the ordered set is {[1,9], [10,12]}.
[0049] According to the technical solution of the embodiment of the present invention, the interval data stored in the ordered set is non-mergeable, so the pressure of data storage can be reduced and data storage resources can be saved. Since the interval data is sorted based on the ordered set, when calculating the total length of time, there is no need to query the full amount of data, and it can be quickly determined whether the interval data can be merged, thereby reducing the number of calculations and calculation time, and improving data query efficiency and data calculation efficiency.
[0050] Figure 2 FIG. 1 is a schematic diagram of the interval data merging process according to an embodiment of the present invention. Figure 2As shown, in one embodiment of the present invention, firstly, the key name and key value corresponding to the interval data are generated according to the input parameter splicing, and then it is determined whether there is a corresponding ordered set in the cache according to the key name. If not, the interval data is directly added to the newly created ordered set without merging the interval data; if so, the weight value of the interval data is calculated according to the key value, and the interval data is added to the ordered set corresponding to the key name according to the weight value, and the index position of the interval data in the ordered set is obtained. Afterwards, according to the index position of the interval data, the interval data before the index position of the interval data is taken out from the ordered set and recursively merged, and it is determined whether the merge is successful. If the merge is successful, the original two interval data are deleted, and according to the weight value of the first merged result obtained after the merge, the first merged result is added to the ordered set and used as the interval data, and then the interval data before the index position of the interval data is taken out from the ordered set again and recursively merged; if the merge is not successful, the interval data after the index position of the interval data is directly taken out from the ordered set and recursively merged, and it is determined whether the merge is successful. If the merge is successful, the two original interval data are deleted, and according to the weight value of the second merged result obtained after the merge, the second merged result is added to the ordered set and used as the interval data. Then, the interval data located after the index position of the interval data is taken out from the ordered set again and recursively merged until the merge fails and the merge ends.
[0051] Figure 3 Schematic diagram of the main modules of the device for merging interval data according to an embodiment of the present invention. Figure 3 As shown, the interval data merging device 300 according to the embodiment of the present invention mainly includes a data weight calculation module 301 , an index position acquisition module 302 , a first recursive merging module 303 and a second recursive merging module 304 .
[0052] The data weight calculation module 301 is used to generate a key name and a key value corresponding to the interval data according to the input parameters, and calculate the weight value of the interval data according to the key value;
[0053] An index position acquisition module 302, configured to add the interval data to an ordered set according to the key name and the weight value, and to acquire the index position of the interval data in the ordered set;
[0054] A first recursive merging module 303, configured to recursively merge the interval data with the interval data located before the index position in the ordered set to obtain merged interval data;
[0055] The second recursive merging module 304 is used to recursively merge the merged interval data with the interval data located after the index position in the ordered set to obtain a merging result of the interval data in the ordered set.
[0056] According to one embodiment of the present invention, the first recursive merging module 303 can also be used to: according to the index position of the interval data, obtain the interval data corresponding to the previous index position of the index position of the interval data from the ordered set as the first interval data to be merged; when the interval data and the first interval data to be merged can be merged, merge the interval data and the first interval data to be merged to obtain a first merged result, add the first merged result to the ordered set, and delete the interval data and the first interval data to be merged from the ordered set; use the first merged result as the interval data, use the index position of the first merged result in the ordered set as the index position of the interval data, and repeat the above operations until the interval data and the first interval data to be merged cannot be merged; use the interval data when the interval data and the first interval data to be merged cannot be merged as the merged interval data.
[0057] According to another embodiment of the present invention, the second recursive merging module 304 can also be used to: according to the index position of the merged interval data, obtain the interval data corresponding to the index position after the index position of the merged interval data from the ordered set as the second interval data to be merged; when the merged interval data and the second interval data to be merged can be merged, merge the merged interval data and the second interval data to be merged to obtain a second merge result, add the second merge result to the ordered set, and delete the merged interval data and the second interval data to be merged from the ordered set; use the second merge result as the merged interval data, use the index position of the second merge result in the ordered set as the index position of the merged interval data, and repeat the above operations until the merged interval data and the second interval data to be merged cannot be merged; use the ordered set obtained when the merged interval data and the second interval data to be merged cannot be merged as the merge result of the interval data in the ordered set.
[0058] According to another embodiment of the present invention, the interval data merging device 300 merges two interval data through the following algorithm: creating a merge result array for storing the merge result of the two interval data to be merged; respectively obtaining the left endpoint value and the right endpoint value of the two interval data; taking the interval data with the smaller left endpoint value of the two interval data as the first interval data, and the interval data with the larger left endpoint value as the second interval data; adding the first interval data to the merge result array; in the case where the left endpoint value of the second interval data is greater than the right endpoint value of the first interval data, adding the second interval data to the end of the merge result array to obtain the merge result of the two interval data; in the case where the left endpoint value of the second interval data is not greater than the right endpoint value of the first interval data, if the right endpoint value of the second interval data is greater than the right endpoint value of the first interval data, then modifying the right endpoint value of the first interval data in the merge result array to the right endpoint value of the second interval data to obtain the merge result of the two interval data; otherwise, not modifying the right endpoint value of the first interval data in the merge result array, and directly obtaining the merge result of the two interval data.
[0059] According to another embodiment of the present invention, after obtaining the merging result of the two interval data, the interval data merging device 300 is further used to: when the two interval data are included in the merging result array, or the length of the merging result array is 2, determine that the two interval data cannot be merged.
[0060] According to another embodiment of the present invention, the input parameters include the resource identifier, user information, start time and end time corresponding to the interval data; the data weight calculation module 301 can also be used to: generate a key name corresponding to the interval data according to the resource identifier and user information corresponding to the interval data; generate a key value corresponding to the interval data according to the start time and end time corresponding to the interval data.
[0061] According to another embodiment of the present invention, the data weight calculation module 301 may also be used to calculate the weight value of the interval data according to the left and right endpoint values of the time interval corresponding to the key value.
[0062] According to another embodiment of the present invention, the index position acquisition module 302 can also be used to: obtain the corresponding target ordered set according to the key name; add the interval data to the target ordered set according to the weight value, wherein the interval data in the target ordered set is arranged in ascending order of weight value.
[0063] According to the technical solution of the embodiment of the present invention, by generating the key name and key value corresponding to the interval data according to the input parameters, and calculating the weight value of the interval data according to the key value; adding the interval data to the ordered set according to the key name and weight value, and obtaining the index position of the interval data in the ordered set; recursively merging the interval data with the interval data before the index position in the ordered set to obtain the merged interval data; recursively merging the merged interval data with the interval data after the index position in the ordered set to obtain the merged result of the interval data in the ordered set, the ordered set stores the non-mergeable interval data, so the pressure of data storage can be reduced and data storage resources can be saved. Since the interval data is sorted based on the ordered set, when calculating the total length of time, there is no need to query the full amount of data, and it can be quickly determined whether the interval data can be merged, thereby reducing the number of calculations and calculation time, and improving data query efficiency and data calculation efficiency.
[0064] Figure 4 An exemplary system architecture 400 is shown to which the interval data merging method or interval data merging device according to the embodiment of the present invention can be applied.
[0065] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0066] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, social platform software, etc. (only as examples).
[0067] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0068] Server 405 may be a server that provides various services, such as a background management server (for example only) that provides support for shopping websites browsed by users using terminal devices 401, 402, and 403. The background management server may generate key names and key values corresponding to interval data according to input parameters for the received interval data merging request and other data, and calculate the weight value of the interval data according to the key value; add the interval data to an ordered set according to the key name and the weight value, and obtain the index position of the interval data in the ordered set; recursively merge the interval data with the interval data before the index position in the ordered set to obtain merged interval data; recursively merge the merged interval data with the interval data after the index position in the ordered set to obtain the merged result of the interval data in the ordered set, and feed back the processing result (for example, the merged result - for example only) to the terminal device.
[0069] It should be noted that the interval data merging method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the interval data merging device is generally disposed in the server 405 .
[0070] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0071] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 5 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0072] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0073] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0074] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0075] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0076] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0077] The units or modules involved in the embodiments of the present invention may be implemented by software or hardware. The units or modules described may also be provided in a processor, for example, may be described as: a processor including a data weight calculation module, an index position acquisition module, a first recursive merging module, and a second recursive merging module. The names of these units or modules do not, in certain cases, constitute limitations on the units or modules themselves. For example, the second recursive merging module may also be described as "a module for recursively merging the merged interval data with the interval data in the ordered set located after the index position to obtain a merged result of the interval data in the ordered set".
[0078] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: generating a key name and a key value corresponding to the interval data according to the input parameters, and calculating the weight value of the interval data according to the key value; adding the interval data to an ordered set according to the key name and the weight value, and obtaining the index position of the interval data in the ordered set; recursively merging the interval data with the interval data before the index position in the ordered set to obtain the merged interval data; recursively merging the merged interval data with the interval data after the index position in the ordered set to obtain the merged result of the interval data in the ordered set.
[0079] According to the technical solution of the embodiment of the present invention, by generating the key name and key value corresponding to the interval data according to the input parameters, and calculating the weight value of the interval data according to the key value; adding the interval data to the ordered set according to the key name and weight value, and obtaining the index position of the interval data in the ordered set; recursively merging the interval data with the interval data before the index position in the ordered set to obtain the merged interval data; recursively merging the merged interval data with the interval data after the index position in the ordered set to obtain the merged result of the interval data in the ordered set, the ordered set stores the non-mergeable interval data, so the pressure of data storage can be reduced and data storage resources can be saved. Since the interval data is sorted based on the ordered set, when calculating the total length of time, there is no need to query the full amount of data, and it can be quickly determined whether the interval data can be merged, thereby reducing the number of calculations and calculation time, and improving data query efficiency and data calculation efficiency.
[0080] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for merging interval data, characterized in that: include: Generate a key name and a key value corresponding to the interval data according to the input parameters, and calculate a weight value of the interval data according to the key value; Adding the interval data to an ordered set according to the key name and the weight value, and obtaining the index position of the interval data in the ordered set; Recursively merging the interval data with the interval data located before the index position in the ordered set to obtain merged interval data; The merged interval data is recursively merged with the interval data located after the index position in the ordered set to obtain a merge result of the interval data in the ordered set.
2. The method according to claim 1, characterized in that Recursively merging the interval data with the interval data located before the index position in the ordered set to obtain merged interval data, including: According to the index position of the interval data, obtaining, from the ordered set, the interval data corresponding to the previous index position of the index position of the interval data as the first interval data to be merged; If the interval data and the first interval data to be merged can be merged, merge the interval data and the first interval data to be merged to obtain a first merge result, add the first merge result to the ordered set, and delete the interval data and the first interval data to be merged from the ordered set; Using the first merge result as the interval data, using the index position of the first merge result in the ordered set as the index position of the interval data, and repeatedly performing the above operation until the interval data and the first interval data to be merged cannot be merged; The interval data when the interval data and the first interval data to be merged cannot be merged is used as the merged interval data.
3. The method according to claim 1, characterized in that Recursively merging the merged interval data with the interval data in the ordered set located after the index position to obtain a merge result of the interval data in the ordered set, including: According to the index position of the merged interval data, obtaining, from the ordered set, interval data corresponding to an index position subsequent to the index position of the merged interval data as second interval data to be merged; If the merged interval data and the second interval data to be merged can be merged, merge the merged interval data and the second interval data to be merged to obtain a second merge result, add the second merge result to the ordered set, and delete the merged interval data and the second interval data to be merged from the ordered set; Using the second merge result as the merged interval data, using the index position of the second merge result in the ordered set as the index position of the merged interval data, and repeatedly performing the above operation until the merged interval data and the second interval data to be merged cannot be merged; The ordered set obtained when the merged interval data and the second interval data to be merged cannot be merged is used as the merging result of the interval data in the ordered set.
4. The method according to any one of claims 1 to 3, characterized in that: The two interval data are merged using the following algorithm: Create a merge result array to store the merge result of the two interval data to be merged; Respectively obtain the left endpoint value and the right endpoint value of the two interval data; The interval data with the smaller left endpoint value among the two interval data is used as the first interval data, and the interval data with the larger left endpoint value is used as the second interval data; Adding the first interval data to the merge result array; When the left endpoint value of the second interval data is greater than the right endpoint value of the first interval data, the second interval data is added to the end of the merge result array to obtain a merge result of the two interval data; In the case where the left endpoint value of the second interval data is not greater than the right endpoint value of the first interval data, if the right endpoint value of the second interval data is greater than the right endpoint value of the first interval data, the right endpoint value of the first interval data in the merged result array is modified to the right endpoint value of the second interval data to obtain the merged result of the two interval data; otherwise, the right endpoint value of the first interval data in the merged result array is not modified, and the merged result of the two interval data is directly obtained.
5. The method according to claim 4, characterized in that After obtaining the merged result of the two interval data, the method further includes: When the merge result array includes the two interval data or the length of the merge result array is 2, it is determined that the two interval data cannot be merged.
6. The method according to claim 1, characterized in that The input parameters include the resource identifier, user information, start time and end time corresponding to the interval data; Generate the key name and key value corresponding to the interval data according to the input parameters, including: Generate a key name corresponding to the interval data according to the resource identifier corresponding to the interval data and the user information; The key value corresponding to the interval data is generated according to the start time and the end time corresponding to the interval data.
7. The method according to claim 1 or 6, characterized in that: Calculating the weight value of the interval data according to the key value includes: The weight value of the interval data is calculated according to the left and right endpoint values of the time interval corresponding to the key value.
8. The method according to claim 1, characterized in that: Adding the interval data to an ordered set according to the key name and the weight value includes: Obtain the corresponding target ordered set according to the key name; The interval data is added to the target ordered set according to the weight value, wherein the interval data in the target ordered set is arranged in ascending order of weight value.
9. A device for merging interval data, characterized in that: include: A data weight calculation module, used to generate a key name and a key value corresponding to the interval data according to the input parameters, and calculate the weight value of the interval data according to the key value; An index position acquisition module, used for adding the interval data to an ordered set according to the key name and the weight value, and acquiring the index position of the interval data in the ordered set; a first recursive merging module, configured to recursively merge the interval data with the interval data located before the index position in the ordered set to obtain merged interval data; The second recursive merging module is used to recursively merge the merged interval data with the interval data located after the index position in the ordered set to obtain a merging result of the interval data in the ordered set.
10. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.