CN112947889A - Merging and sorting method and device - Google Patents

Merging and sorting method and device Download PDF

Info

Publication number
CN112947889A
CN112947889A CN202110256265.8A CN202110256265A CN112947889A CN 112947889 A CN112947889 A CN 112947889A CN 202110256265 A CN202110256265 A CN 202110256265A CN 112947889 A CN112947889 A CN 112947889A
Authority
CN
China
Prior art keywords
data
queue
queues
cas
merging
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110256265.8A
Other languages
Chinese (zh)
Inventor
鄢贵海
卢文岩
孔浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yusur Technology Co ltd
Original Assignee
Yusur Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yusur Technology Co ltd filed Critical Yusur Technology Co ltd
Priority to CN202110256265.8A priority Critical patent/CN112947889A/en
Publication of CN112947889A publication Critical patent/CN112947889A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/22Arrangements for sorting or merging computer data on continuous record carriers, e.g. tape, drum, disc
    • G06F7/36Combined merging and sorting

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a merging and sorting method and device, and relates to the technical field of data processing. The method comprises the following steps: merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through a first CAS and a second CAS respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement; when all data in one data queue is dequeued, acquiring the remaining data, a first data queue and a second data queue; and generating a merging and sorting result of the two data queues according to the residual data, the first data queue and the second data queue. The embodiment of the invention is used for improving the merging and sorting parallelism degree, thereby reducing the merging and sorting time delay.

Description

Merging and sorting method and device
Technical Field
The invention relates to the technical field of data processing, in particular to a merging and sorting method and device.
Background
With the rapid development of science and technology, the large data storage scale continuously keeps the growth rate of about 40%, and the explosive growth of data brings huge challenges to data processing.
The merge sort is one of the most basic and most widely applied operations in data processing, and plays a very important role in data processing. The basic principle of the merging and sorting algorithm is as follows: the data in the two ordered sequences are compared by a Compare and Swap unit (CAS), and the smaller or larger data is output to obtain the merging and sorting results of the two ordered sequences. In the prior art, a merging and sorting mode is generally implemented based on a First-In First-Out (FIFO) sequence. That is, the data in the ordered sequence is written into the FIFO sequence in the reverse order of the ordering, the CAS selects one data from the FIFO sequence corresponding to the two ordered sequences each time for comparison, and the data meeting the monotonicity requirement is queued up by the other data. Due to the characteristic that the FIFO sequences can only write data at the tail of the queue and read data at the head of the queue, the data in a pair of FIFO sequences can only be merged and sorted by one CAS, and when the data amount in the FIFO sequences (the data amount of the ordered sequences) is large, the merging and sorting time delay is large.
Disclosure of Invention
In view of this, the present invention provides a merging and sorting method and apparatus, which are used to improve the merging and sorting parallelism and reduce the time delay of merging and sorting.
In order to achieve the above object, the embodiments of the present invention provide the following technical solutions:
in a first aspect, an embodiment of the present invention provides a merging and sorting method, including:
merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through a first comparison switching unit CAS and a second CAS respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement;
when all data in one of the two data queues is dequeued, acquiring remaining data, a first data queue and a second data queue, wherein the remaining data is the remaining data in the other of the two data queues, the first data queue is a data queue formed by data sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data sequentially dequeued by the second CAS;
and generating a merging and sorting result of the two data queues according to the residual data, the first data queue and the second data queue.
As an optional implementation manner of the embodiment of the present invention, the generating a merging and sorting result of the two data queues according to the remaining data, the first data queue, and the second data queue includes:
sequentially writing the residual data into the tail end of the first data queue to generate a third data queue;
performing reverse sequencing on the data in the second data queue to generate a fourth data queue;
and splicing the fourth data queue to the tail end of the third data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, the generating a merging and sorting result of the two data queues according to the remaining data, the first data queue, and the second data queue includes:
writing the residual data into the tail end of the second data queue in reverse order in sequence to generate a third data queue;
performing reverse sequencing on the data in the third data queue to generate a fourth data queue;
and splicing the fourth data queue to the tail end of the first data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, merging and sorting data in the two data queues from a head end of the data queue by the first CAS includes:
when it is determined that first data meets the monotonicity requirement compared with second data, comparing whether third data meets the monotonicity requirement compared with the second data, wherein the third data is data which is positioned behind the first data in a data queue to which the first data belongs and has a first preset value of interval with the first data;
if the third data is determined to meet the monotonicity requirement compared with the second data, sequentially dequeuing the third data and all data before the third data;
if the third data does not meet the monotonicity requirement compared with the second data, selecting data located before the currently compared data from a data queue to which the first data belongs based on a first preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the second data or not, if so, sequentially dequeuing the fourth data and all data before the fourth data, or if not, dequeuing the second data.
As an optional implementation manner of the embodiment of the present invention, the selecting, based on a first preset rule, data located before currently compared data from a data queue to which the first data belongs, and comparing whether the selected data meets a monotonicity requirement compared with the second data includes:
selecting data which is positioned behind the first data and has an interval of [ N/2] with the first data from a data queue to which the first data belongs, and comparing whether the selected data meets monotonicity compared with the second data;
where N is the interval between the current data being compared and the first data, [ ] is a floor function.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting the data in the two data queues by the second CAS from the tail end of the data queue includes:
when determining that sixth data does not meet the monotonicity requirement compared with seventh data, comparing whether eighth data meets the monotonicity requirement compared with the seventh data, wherein the eighth data is data which is positioned in front of the sixth data in a data queue to which the sixth data belongs and has a second preset value interval with the first data;
if the eighth data is determined not to meet the monotonicity requirement compared with the seventh data, sequentially dequeuing the eighth data and all data after the eighth data in a reverse order;
if the eighth data meets the monotonicity requirement compared with the seventh data, selecting data behind the currently compared data from a data queue to which the seventh data belongs based on a second preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the seventh data or not, if so, dequeuing all data before the fourth data and the fourth data in reverse order in sequence, or if so, dequeuing the seventh data and writing the seventh data into the second data queue.
As an optional implementation manner of the embodiment of the present invention, the selecting, based on a second preset rule, data that is located after currently compared data from a data queue to which the seventh data belongs, and comparing whether the selected data meets a monotonicity requirement compared with the seventh data includes:
selecting data which is positioned in front of the sixth data and has an interval of [ M/2] with the first data from a data queue to which the sixth data belongs, and comparing whether the selected data meets monotonicity compared with the seventh data;
where M is the interval between the currently compared data and the seventh data, [ ] is a floor function.
In a second aspect, an embodiment of the present invention provides a merge sorting apparatus, including:
the merging and sequencing unit is used for merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through the first comparison switching unit CAS and the second CAS respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement;
an obtaining unit, configured to obtain, when all data in one of the two data queues is dequeued, remaining data, a first data queue and a second data queue, where the remaining data is data remaining in the other of the two data queues, the first data queue is a data queue formed by data that is sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data that is sequentially dequeued by the second CAS;
and the generating unit is used for generating merging and sequencing results of the two data queues according to the residual data, the first data queue and the second data queue.
As an optional implementation manner of the embodiment of the present invention, the generating unit is specifically configured to write the remaining data into the tail end of the first data queue in sequence, and generate a third data queue; performing reverse sequencing on the data in the second data queue to generate a fourth data queue; and splicing the fourth data queue to the tail end of the third data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, the generating unit is specifically configured to write the remaining data into the tail end of the second data queue in reverse order, and generate a third data queue; performing reverse sequencing on the data in the third data queue to generate a fourth data queue; and splicing the fourth data queue to the tail end of the first data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting unit is specifically configured to, when it is determined that first data meets a monotonicity requirement compared to second data, compare whether third data meets the monotonicity requirement compared to the second data, where the third data is data that is located after the first data in a data queue to which the first data belongs and has a first preset value of an interval with the first data; if the third data is determined to meet the monotonicity requirement compared with the second data, sequentially dequeuing the third data and all data before the third data; if the third data does not meet the monotonicity requirement compared with the second data, selecting data located before the currently compared data from a data queue to which the first data belongs based on a first preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the second data or not, if so, sequentially dequeuing the fourth data and all data before the fourth data, or if not, dequeuing the second data.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting unit is specifically configured to select, from a data queue to which the first data belongs, data that is located after the first data and has an interval of [ N/2] from the first data, and compare whether the selected data satisfies monotonicity compared with the second data;
where N is the interval between the current data being compared and the first data, [ ] is a floor function.
As an optional implementation manner of the embodiment of the present invention, the merge sorting unit is specifically configured to compare, when it is determined that sixth data does not satisfy a monotonicity requirement compared to seventh data, whether eighth data satisfies the monotonicity requirement compared to the seventh data, where the eighth data is data that is located before the sixth data in a data queue to which the sixth data belongs and has a second preset value of interval with the first data; if the eighth data is determined not to meet the monotonicity requirement compared with the seventh data, sequentially dequeuing the eighth data and all data after the eighth data in a reverse order; if the eighth data meets the monotonicity requirement compared with the seventh data, selecting data behind the currently compared data from a data queue to which the seventh data belongs based on a second preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the seventh data or not, if so, dequeuing all data before the fourth data and the fourth data in reverse order in sequence, or if so, dequeuing the seventh data and writing the seventh data into the second data queue.
As an optional implementation manner of the embodiment of the present invention, the merge sorting unit is specifically configured to select, from a data queue to which the sixth data belongs, data that is located before the sixth data and has an interval of [ M/2] with the first data, and compare whether the selected data satisfies monotonicity compared with the seventh data;
where M is the interval between the currently compared data and the seventh data, [ ] is a floor function.
In a third aspect, an embodiment of the present invention provides an electronic device, including: a memory for storing a computer program and a processor; the processor is configured to execute the merge sorting method according to the first aspect or any one of the optional embodiments of the first aspect when the computer program is invoked.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the merging and sorting method according to the first aspect or any one of the optional embodiments of the first aspect.
In a fifth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program/instruction, and when the computer program/instruction is executed by a processor, the merging and sorting method according to the first aspect or any one of the optional embodiments of the first aspect is implemented.
The merging and sorting method provided by the embodiment of the invention merges and sorts the data in the two data queues in parallel from the head end and the tail end of the data queues through the first comparison switching unit CAS and the second CAS respectively, when the data of one data queue in the two data queues are all dequeued, the data queue formed by the remaining data in the other data queue in the two data queues, the data queue formed by the sequentially dequeued data of the first CAS and the data queue formed by the sequentially dequeued data of the second CAS are obtained, and finally, the merging and sorting results of the two data queues are generated according to the remaining data, the first data queue and the second data queue. According to the merging and sorting method provided by the embodiment of the invention, the data in the two data queues can be merged and sorted in parallel from the head end and the tail end of the data queues respectively through the two CAS with opposite monotonicity, so that the parallelism of merging and sorting is improved, and the merging and sorting parallelism can be improved and the time delay of merging and sorting is reduced.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
FIG. 1 is a flowchart illustrating steps of a merge sort method according to an embodiment of the present invention;
FIG. 2 is a block diagram of a merge sort method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a merging and sorting apparatus according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention.
Detailed Description
In order that the above objects, features and advantages of the present invention may be more clearly understood, a solution of the present invention will be further described below. It should be noted that the embodiments of the present invention and features of the embodiments may be combined with each other without conflict.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, but the present invention may be practiced in other ways than those described herein; it is to be understood that the embodiments described in this specification are only some embodiments of the invention, and not all embodiments.
The terms "first" and "second," and the like, in the description and in the claims of the present invention are used for distinguishing between synchronized objects, and are not used to describe a particular order of objects. For example, the first preset value and the second preset value are used for distinguishing different preset values, but are not used for describing the size, the sequence and the specific sequence of the preset values.
In the embodiments of the present invention, words such as "exemplary" or "for example" are used to mean serving as examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "e.g.," an embodiment of the present invention is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present concepts related in a concrete fashion. Further, in the description of the embodiments of the present invention, "a plurality" means two or more unless otherwise specified.
The execution main body of the merging and sorting method provided by the embodiment of the invention can be a merging and sorting device. The merging and sorting device may be a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a Personal Digital Assistant (PDA), an intelligent watch, an intelligent bracelet, or other types of terminal devices.
An embodiment of the present invention provides a merging and sorting method, and as shown in fig. 1, the merging and sorting method includes the following steps S11 to S13:
and S11, merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through the first CAS and the second CAS respectively.
Wherein the first CAS is configured to dequeue data that satisfies the monotonicity requirements and the second CAS is configured to dequeue data that does not satisfy the monotonicity requirements.
Specifically, the data queue in the implementation of the present invention refers to a data queue obtained by merging and sorting a plurality of data, and each ordered sequence includes at least two data. For example: after merging and sorting the data "2" and the data "6", a data queue {2, 6} can be obtained. For another example: after merging and sorting the data queue "{ 2, 5 }" and the data queue "{ 3, 6 }" the data queue "{ 2, 3, 5, 6 }" can be obtained.
In the embodiment of the invention, the first CAS and the second CAS are the CAS with opposite monotonicity, the merging and sorting result output by the first CAS is the first data queue, and the merging and sorting result output by the second CAS is the second data queue.
Dequeuing data in the embodiment of the present invention refers to deleting data from the data queue to which the data belongs. For example: dequeuing data "6" in data queue {2, 3, 5, 6} means deleting data "6" from data queue {2, 3, 5, 6} and after dequeuing data "6", data queue {2, 3, 5, 6} becomes {2, 3, 5 }.
The first CAS reads two data at the head ends of the two data queues for comparison, dequeues the data meeting the monotonicity requirement, and then reads two data at the head ends of the two data queues again for comparison until all the data of one of the two data queues are dequeued.
The second CAS performs merging and sequencing on the data in the two data queues from the tail end of the data queue, that is, the second CAS reads two data at the tail ends of the two data queues for comparison, dequeues the data which does not meet the monotonicity requirement, and then reads two data at the tail ends of the two data queues again for comparison until all the data in one of the two data queues are dequeued.
And S12, when the data of one of the two data queues is completely dequeued, acquiring the remaining data, the first data queue and the second data queue.
The remaining data is data remaining in the other data queue of the two data queues, the first data queue is a data queue formed by data sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data sequentially dequeued by the second CAS.
Specifically, in the process of merging and sorting data in the two data queues in parallel from the head end and the tail end of the data queue through the first CAS and the second CAS, respectively, because the first CAS and the second CAS need to read data from the two data queues respectively for comparison and dequeue one of the data queues, the data in one data queue is always dequeued first, and when the data in one data queue is dequeued completely, the CAS cannot read data from the data queue in which the data is dequeued completely, so that the CAS cannot work continuously, and the data in the other data queue is not dequeued.
For example, referring to fig. 2, the above embodiment is described in fig. 2 by taking two data queues for merging and sorting as a data queue {1, 5, 7, 8, 11} and a data queue {2, 3, 4, 9, 12 }. As shown in fig. 2, the data sequentially dequeued by the first CAS 21 are "1", "2", "3", "4", and thus the first data queue is {1, 2, 3, 4}, and the data sequentially dequeued by the second CAS22 are "12", "11", "9", and thus the second data queue is {12, 11, 9 }. When first CAS 21 outputs data "4" and second CAS22 outputs data "9", the data in data queue {2, 3, 4, 9, 12} is all dequeued, the remaining data in data queue {1, 5, 7, 8, 11} is {5, 7, 8}, and since neither first CAS nor second CAS can read data from data queue {2, 3, 4, 9, 12}, neither first CAS nor second CAS can continue to operate, at which point the remaining data is {5, 7, 8 }.
And S13, generating a merging and sorting result of the two data queues according to the residual data, the first data queue and the second data queue.
As an alternative embodiment of the present invention, the step S13 (generating the merging and sorting result of the two data queues according to the remaining data, the first data queue and the second data queue) includes the following steps a to c.
And a, sequentially writing the residual data into the tail end of the first data queue to generate a third data queue.
Specifically, writing the remaining data into the tail end of the first data queue in sequence means writing the remaining data into the tail end of the first data queue in sequence according to the sequence of the remaining data in the original data queue.
As described in the above example, the remaining data is {5, 7, 8}, the first data queue is {1, 2, 3, 4}, so that the remaining data is sequentially written to the tail end of the first data queue, and the generated third data queue is {1, 2, 3, 4, 5, 7, 8 }.
And b, reversely sequencing the data in the second data queue to generate a fourth data queue.
In the embodiment of the present invention, the reverse data queue of the data queue refers to a data queue obtained by sorting data in the data queue according to opposite monotonicity. For example: for the data queue {12, 11, 9} sorted in descending order, the reverse data queue is the data queue {9, 11, 12} obtained by sorting the data "12", "11", "9" in ascending order.
As described in the above example, the second data queue is {12, 11, 9}, so data in the second data queue is inversely sorted, and the generated fourth data queue is {9, 11, 12 }.
And c, splicing the fourth data queue to the tail end of the third data queue to generate merging and sequencing results of the two data queues.
As described in the above example, the fourth data queue is {9, 11, 12}, the third data queue is {1, 2, 3, 4, 5, 7, 8}, and thus the merged and sorted results of the data queues {1, 5, 7, 8, 11} and the data queues {2, 3, 4, 5, 7, 8, 9, 11, 12} are {1, 2, 3, 4, 5, 7, 8, 9, 11, 12 }.
As an alternative embodiment of the present invention, the step S13 (generating merging and sorting results of the two data queues according to the remaining data, the first data queue, and the second data queue) includes the following steps i to iii.
And step I, writing the residual data into the tail end of the second data queue in reverse order in sequence to generate a third data queue.
Specifically, writing the remaining data into the tail end of the second data queue in reverse order means writing the remaining data into the tail end of the second data queue in sequence according to an order opposite to the order of the remaining data in the original data queue.
As described in the above example, the remaining data is {5, 7, 8}, and the second data queue is {12, 11, 9}, so that the remaining data is written into the tail end of the second data queue in reverse order, a third data queue is generated, and the generated third data queue is {12, 11, 9, 8, 7, 5 }.
And II, reversely sequencing the data in the third data queue to generate a fourth data queue.
As described in the above example, the third data queue is {12, 11, 9, 8, 7, 5}, so that data in the third data queue is reverse-ordered, and the generated fourth data queue is {5, 7, 8, 9, 11, 12 }.
And step III, splicing the fourth data queue to the tail end of the data queue to generate merging and sequencing results of the two data queues.
As described in the above example, the first data queue is {1, 2, 3, 4}, the fourth data queue is {5, 7, 8, 9, 11, 12}, and thus the merged and sorted results of the data queues {1, 5, 7, 8, 11} and the data queues {2, 3, 4, 5, 7, 8, 9, 11, 12} are {1, 2, 3, 4, 5, 7, 8, 9, 11, 12 }.
The merging and sorting method provided by the embodiment of the invention merges and sorts the data in the two data queues in parallel from the head end and the tail end of the data queues through the first comparison switching unit CAS and the second CAS respectively, when the data of one data queue in the two data queues are all dequeued, the data queue formed by the remaining data in the other data queue in the two data queues, the data queue formed by the sequentially dequeued data of the first CAS and the data queue formed by the sequentially dequeued data of the second CAS are obtained, and finally, the merging and sorting results of the two data queues are generated according to the remaining data, the first data queue and the second data queue. According to the merging and sorting method provided by the embodiment of the invention, the data in the two data queues can be merged and sorted in parallel from the head end and the tail end of the data queues respectively through the two CAS with opposite monotonicity, so that the parallelism of merging and sorting is improved, and the merging and sorting parallelism can be improved and the time delay of merging and sorting is reduced.
It should be further noted that, because the merging and sorting method provided by the embodiment of the present invention merges and sorts data in the two data queues in parallel from the head end and the tail end of the data queue through the first CAS and the second CAS, respectively, the embodiment of the present invention may also avoid blocking of an input channel during the merging and sorting process. For example: when merging and sorting the data queues {1, 3, 5, 7, 9} and the data queues {11, 13, 15, 17, 19}, if a conventional merging and sorting manner is adopted, the CAS outputs smaller data each time, and then the data in the data pair columns {1, 3, 5, 7, 9} are all output, and then the data in the data pair columns {11, 13, 15, 17, 19} start to be output, which may cause blocking of the input channel space where the data pair columns {11, 13, 15, 17, 19} are located. In the merging and sorting method provided by the embodiment of the present invention, the first CAS and the second CAS respectively merge and sort the data in the two data queues from the head end and the tail end of the data queue, so that the first CAS outputs the data in the data queue {1, 3, 5, 7, 9}, and the second CAS outputs the data in the data queue {11, 13, 15, 17, 19}, thereby avoiding the input channel blocking.
As an alternative implementation manner of the embodiment of the present invention, on the basis of the merge sorting method shown in fig. 1, the step S11 (merge sorting data in the two data queues from the head end of the data queue by the first CAS) includes the following steps 111 to 113:
and 111, when the first data is determined to meet the monotonicity requirement compared with the second data, comparing whether the third data meets the monotonicity requirement compared with the second data.
The third data is data which is positioned behind the first data in the data queue to which the first data belongs and has a first preset value of interval with the first data.
Specifically, the first data and the second data are data in two data queues respectively, and the first data and the third data belong to the same data queue.
Optionally, the first preset value may be 3, 7, and the like, and the first preset value is not limited in the embodiment of the present invention.
For example, the above embodiment is described below by taking an example of the data queue {18, 20, 22, 24, 26 … … }, another data queue {7, 9, 11, 15, 17 … … }, and the first preset value being 3. When the first data is "7" and the second data is "18", data located after the data "7" and spaced from "7" by 3 in the data queue {7, 9, 11, 15, 17 … … } is "17", and therefore, when the first data is "7" and the second data is "18", the third data is "17". When the first CAS determines that the first data "7" satisfies the monotonicity requirement compared to the second data "18", it compares whether the third data "17" satisfies the monotonicity requirement compared to the second data "18".
In step 111, if it is determined that the third data satisfies the monotonicity requirement compared to the second data, the following step 112 is performed.
And 112, sequentially dequeuing the third data and all data before the third data.
As described in the above example, the first data is "7", the second data is "18", the third data is "17", and the third data "17" satisfies the monotonicity requirement compared to the second data "18", so that the third data "17" and all the data "9", "11", "15", "17" before the third data "17" are dequeued in order.
In step 113, if it is determined that the third data does not satisfy the monotonicity requirement compared to the second data, the following step 113 is executed.
113, selecting data before the currently compared data from a data queue to which the first data belongs based on a first preset rule, and comparing whether the selected data meets a monotonicity requirement compared with the second data, and when the selected fourth data meets the monotonicity requirement compared with the second data, sequentially dequeuing the fourth data and all data before the fourth data, or when the selected fifth data adjacent to the first data does not meet the monotonicity requirement compared with the second data, dequeuing the second data.
Optionally, in step 113, selecting, based on a first preset rule, a data in the data queue to which the first data belongs, the data being located before the currently compared data, and comparing whether the selected data meets a monotonicity requirement compared with the second data includes:
selecting data which is positioned behind the first data and has an interval of [ N/2] with the first data from a data queue to which the first data belongs, and comparing whether the selected data meets monotonicity compared with the second data;
where N is the interval between the current data being compared and the first data, [ ] is a floor function.
For example, the above embodiment is described below by taking an example of the data queue {18, 20, 22, 24, 26 … … }, another data queue {7, 9, 11, 15, 19 … … }, and the first preset value being 3. The first data is "7", the second data is "18", the third data is "19", the third data "19" does not satisfy the monotonicity requirement compared to the second data "18", and thus it is determined whether or not data "11" located after the first data "7" and spaced at [3/2] from the first data "7" satisfies the monotonicity requirement compared to the second data "18", and since data "11" satisfies the monotonicity requirement compared to the second data "18", all data "9", "11" before the fourth data "11" and the fourth data "11" are sequentially dequeued.
For example, the above embodiment is described below by taking an example of the data queue {18, 20, 22, 24, 26 … … }, another data queue {17, 19, 21, 23, 25 … … }, and the first preset value being 3. The first data is "17", the second data is "18", the third data is "26", the third data "26" does not satisfy the monotonicity requirement compared to the second data "18", it is thus determined whether data "21" located after the first data "17" and spaced [3/2] apart from the first data "17" satisfies the monotonicity requirement compared to the second data "18", since the data "21" still does not satisfy the monotonicity requirement as compared with the second data "18", it is determined whether or not the data "19" located after the first data "17" and having an interval [1/2] from the first data "17" satisfies the monotonicity requirement as compared with the second data "18", since data "19" is adjacent to the first data and does not satisfy the monotonicity requirement compared to second data "18", the second data "18" is dequeued.
As an alternative implementation manner of the embodiment of the present invention, on the basis of the merge sorting method shown in fig. 1, the step S11 (merge sorting data in the two data queues from the tail end of the data queue by the second CAS) includes steps 121 to 123, and when it is determined that the sixth data does not satisfy the monotonicity requirement compared to the seventh data, it is compared whether the eighth data satisfies the monotonicity requirement compared to the seventh data.
The eighth data is data which is located before the sixth data in the data queue to which the sixth data belongs and has a second preset value of interval with the first data.
Specifically, the first data and the second data are data in two data queues respectively, and the first data and the third data belong to the same data queue.
Optionally, the second preset value may be 3, 7, and the like, and the second preset value is not limited in the embodiment of the present invention.
For example, the above embodiment is described below by taking an example of the data queue { … …, 92, 96, 98, 99, 100}, another data queue { … …, 77, 79, 81, 83, 85}, and the second preset value being 3. When the sixth data "100" and the seventh data are "85", data in the data queue { … …, 92, 96, 98, 99, 100} which precedes the data "100" and is spaced from "100" by 3 is "92", and therefore, when the sixth data is "100" and the seventh data is "85", the eighth data is "92". When the first CAS determines that the sixth data "100" does not satisfy the monotonicity requirement compared to the seventh data "85", it is compared whether the eighth data "92" satisfies the monotonicity requirement compared to the seventh data "85".
In the above step 121, if it is determined that the eighth data does not satisfy the monotonicity requirement compared to the seventh data, the following step 122 is executed.
And step 122, dequeuing the eighth data and all data after the eighth data in reverse order.
As described in the above example, since the sixth data is "100", the seventh data is "85", the eighth data is "92", and the eighth data "92" does not satisfy the monotonicity requirement as compared with the seventh data "85", all the data "92", "96", "98", "99" following the eighth data "92" and the third data "92" are sequentially dequeued in reverse order, specifically, "99", "98", "96", "92".
In step 122, if the eighth data meets the monotonicity requirement compared to the seventh data, the following step 123 is executed.
And 123, selecting data behind the currently compared data from the data queue to which the seventh data belongs based on a second preset rule, and comparing whether the selected data meets a monotonicity requirement compared with the seventh data, and when the selected ninth data does not meet the monotonicity requirement compared with the seventh data, dequeuing all data before the fourth data and the fourth data in a reverse order in sequence, or when the selected tenth data adjacent to the sixth data meets the monotonicity requirement compared with the seventh data, dequeuing the seventh data and writing the seventh data into the second data queue.
Optionally, in step 123, selecting, based on a second preset rule, data that is located after the currently compared data from the data queue to which the seventh data belongs, and comparing whether the selected data meets a monotonicity requirement compared with the seventh data includes:
selecting data which is positioned in front of the sixth data and has an interval of [ M/2] with the first data from a data queue to which the sixth data belongs, and comparing whether the selected data meets monotonicity compared with the seventh data;
where M is the interval between the currently compared data and the seventh data, [ ] is a floor function.
For example, the above embodiment is described below by taking the example of merging and sorting the data queues { … …, 80, 82, 90, 95, 100} and the data queues { … …, 71, 74, 77, 80, 83}, where the first preset value is 3. The sixth data is "100", the seventh data is "83", the eighth data is "80", the eighth data "80" satisfies the monotonicity requirement compared to the seventh data "83", and therefore, it is determined whether or not the data "90" located before the sixth data "100" and having an interval [3/2] from the sixth data "100" satisfies the monotonicity requirement compared to the seventh data "83", and since the data "90" does not satisfy the monotonicity requirement compared to the second data "83", all the data "90", "95" preceding the ninth data "90" and the fourth data "90" are sequentially dequeued in reverse order.
For example, the above embodiment is described below by taking the example of merging and sorting the data queue { … …, 60, 70, 80, 90, 100} and the data queue { … …, 55, 65, 75, 85, 95}, where the first preset value is 3. The sixth data is "100", the seventh data is "95", the eighth data is "60", the eighth data "60" satisfies the monotonicity requirement as compared with the seventh data "95", it is thus determined whether data "80" located before the sixth data "100" and spaced [3/2] apart from the sixth data "100" satisfies a monotonicity requirement compared to seventh data "95", since the data "80" still satisfies the monotonicity requirement as compared with the seventh data "95", it is determined whether or not the data "90" located before the sixth data "100" and having an interval [1/2] from the sixth data "100" satisfies the monotonicity requirement as compared with the seventh data "95", since data "90" is adjacent to the first data and still satisfies the monotonicity requirement compared to seventh data "95", the seventh data "95" is dequeued.
For some data needing merging and sorting, in the process of continuously merging the data to generate a larger-scale data queue, the data with smaller absolute value difference can be easily merged into the same data queue to form a denser data cluster, namely 'data locality'. For a data cluster, compared with each piece of data, when the preamble data in the data cluster meets or does not meet the monotonicity requirement, the next round of comparison is directly performed by selecting the subsequent data with the preset data interval, the subsequent data is probably the same as the comparison result of the preamble data, and at this time, the data in the data cluster does not need to be compared one by one, so that the data between the preamble data and the subsequent data can be directly dequeued, the comparison times in the merging and sorting process are reduced, and the merging and sorting time delay is further reduced, therefore, the merging and sorting method provided by the embodiment can further reduce the merging and sorting time delay.
Based on the same inventive concept, as an implementation of the foregoing method, an embodiment of the present invention further provides a merging and sorting apparatus, where an embodiment of the merging and sorting apparatus corresponds to the foregoing method embodiment, and for convenience of reading, details in the foregoing method embodiment are not repeated one by one in this apparatus embodiment, but it should be clear that the merging and sorting apparatus in this embodiment can correspondingly implement all the contents in the foregoing method embodiment.
Fig. 3 is a schematic structural diagram of a merge sorting apparatus according to an embodiment of the present invention, and as shown in fig. 3, a merge sorting apparatus 300 for merging and sorting data in two data queues according to the embodiment includes:
a merging and sorting unit 31, configured to merge and sort the data in the two data queues in parallel from the head end and the tail end of the data queue through the first comparison switching unit CAS and the second CAS, respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement;
an obtaining unit 32, configured to obtain, when all data in one of the two data queues is dequeued, remaining data, a first data queue and a second data queue, where the remaining data is data remaining in the other of the two data queues, the first data queue is a data queue formed by data that is sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data that is sequentially dequeued by the second CAS;
a generating unit 33, configured to generate a merging and sorting result of the two data queues according to the remaining data, the first data queue, and the second data queue.
As an optional implementation manner of the embodiment of the present invention, the generating unit 33 is specifically configured to sequentially write the remaining data into the tail end of the first data queue, and generate a third data queue; performing reverse sequencing on the data in the second data queue to generate a fourth data queue; and splicing the fourth data queue to the tail end of the third data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, the generating unit 33 is specifically configured to write the remaining data into the tail end of the second data queue in reverse order, and generate a third data queue; performing reverse sequencing on the data in the third data queue to generate a fourth data queue; and splicing the fourth data queue to the tail end of the data queue to generate a merging and sequencing result of the two data queues.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting unit 31 is specifically configured to, when it is determined that first data meets a monotonicity requirement compared to second data, compare whether third data meets the monotonicity requirement compared to the second data, where the third data is data that is located after the first data in a data queue to which the first data belongs and has a first preset value of an interval with the first data; if the third data is determined to meet the monotonicity requirement compared with the second data, sequentially dequeuing the third data and all data before the third data; if the third data does not meet the monotonicity requirement compared with the second data, selecting data located before the currently compared data from a data queue to which the first data belongs based on a first preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the second data or not, if so, sequentially dequeuing the fourth data and all data before the fourth data, or if not, dequeuing the second data.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting unit 31 is specifically configured to select, from a data queue to which the first data belongs, data that is located after the first data and has an interval of [ N/2] from the first data, and compare whether the selected data satisfies monotonicity compared with the second data;
where N is the interval between the current data being compared and the first data, [ ] is a floor function.
As an optional implementation manner of the embodiment of the present invention, the merging and sorting unit 31 is specifically configured to, when it is determined that sixth data does not satisfy a monotonicity requirement compared to seventh data, compare whether eighth data satisfies the monotonicity requirement compared to the seventh data, where the eighth data is data that is located before the sixth data in a data queue to which the sixth data belongs and has a second preset value of an interval with the first data; if the eighth data is determined not to meet the monotonicity requirement compared with the seventh data, sequentially dequeuing the eighth data and all data after the eighth data in a reverse order; if the eighth data meets the monotonicity requirement compared with the seventh data, selecting data behind the currently compared data from a data queue to which the seventh data belongs based on a second preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the seventh data or not, if so, dequeuing all data before the fourth data and the fourth data in reverse order in sequence, or if so, dequeuing the seventh data and writing the seventh data into the second data queue.
As an optional implementation manner of the embodiment of the present invention, the merge sorting unit 31 is specifically configured to select, from a data queue to which the sixth data belongs, data that is located before the sixth data and has an interval of [ M/2] with the first data, and compare whether the selected data satisfies monotonicity compared with the seventh data;
where M is the interval between the currently compared data and the seventh data, [ ] is a floor function.
The merge sorting apparatus provided in this embodiment may execute the merge sorting method provided in the above method embodiment, and the implementation principle and the technical effect are similar, which are not described herein again.
Based on the same inventive concept, the embodiment of the invention also provides electronic equipment. Fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 4, the electronic device according to the embodiment includes: a memory 41 and a processor 42, the memory 41 being for storing computer programs; the processor 42 is configured to execute the steps of the merge sorting method provided by the above-described method embodiments when the computer program is invoked.
In particular, the memory 41 may be used to store software programs as well as various data. The memory 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. Further, the memory 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
The processor 42 is a control center of the electronic device, connects various parts of the entire electronic device by various interfaces and lines, and performs various functions of the electronic device and processes data by running or executing software programs and/or modules stored in the memory 41 and calling data stored in the memory 41, thereby performing overall monitoring of the electronic device. Processor 42 may include one or more processing units.
In addition, it should be understood that the electronic device provided by the embodiment of the present invention may further include: the device comprises a radio frequency unit, a network module, an audio output unit, a sensor, a signal receiving unit, a display, a user receiving unit, an interface unit, a power supply and the like. It will be appreciated by those skilled in the art that the above-described configuration of the electronic device does not constitute a limitation of the electronic device, and that the electronic device may include more or fewer components, or some components may be combined, or a different arrangement of components. In the embodiment of the present invention, the electronic device includes, but is not limited to, a mobile phone, a tablet computer, a notebook computer, a palm computer, a vehicle-mounted terminal, a wearable device, a pedometer, and the like.
The radio frequency unit may be configured to receive and transmit signals during information transmission and reception or during a call, and specifically, receive downlink data from a base station and then process the received downlink data to the processor 42; in addition, the uplink data is transmitted to the base station. Typically, the radio frequency units include, but are not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, and the like. In addition, the radio frequency unit can also communicate with a network and other devices through a wireless communication system.
The electronic device provides wireless broadband internet access for the user through the network module, such as helping the user send and receive e-mails, browse webpages, access streaming media and the like.
The audio output unit may convert audio data received by the radio frequency unit or the network module or stored in the memory 41 into an audio signal and output as sound. Also, the audio output unit may also provide audio output related to a specific function performed by the electronic device (e.g., a call signal reception sound, a message reception sound, etc.). The audio output unit comprises a loudspeaker, a buzzer, a receiver and the like.
The signal receiving unit is used for receiving audio or video signals. The receiving Unit may include a Graphics Processing Unit (GPU) that processes image data of still pictures or video obtained by an image capturing device (such as a camera) in a video capturing mode or an image capturing mode, and a microphone. The processed image frames may be displayed on a display unit. The image frames processed by the graphic processor may be stored in a memory (or other storage medium) or transmitted via a radio frequency unit or a network module. The microphone may receive sound and be capable of processing such sound into audio data. The processed audio data may be converted into a format output transmittable to a mobile communication base station via the radio frequency unit in case of the phone call mode.
The electronic device also includes at least one sensor, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor that adjusts the brightness of the display panel according to the brightness of ambient light, and a proximity sensor that turns off the display panel and/or the backlight when the electronic device is moved to the ear. As one of the motion sensors, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally, three axes), detect the magnitude and direction of gravity when stationary, and can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), and vibration identification related functions (such as pedometer and tapping); the sensors may also include fingerprint sensors, pressure sensors, iris sensors, molecular sensors, gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., and will not be described herein.
The display unit is used for displaying information input by a user or information provided to the user. The Display unit may include a Display panel, and the Display panel may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like.
The user receiving unit may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic device. Specifically, the user receiving unit includes a touch panel and other input devices. A touch panel, also referred to as a touch screen, may collect touch operations by a user on or near the touch panel (e.g., operations by a user on or near the touch panel using a finger, a stylus, or any other suitable object or attachment). The touch panel may include two parts of a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 42, receives commands from the processor 42, and executes the commands. In addition, the touch panel may be implemented in various types such as a resistive type, a capacitive type, an infrared ray, and a surface acoustic wave. In addition to the touch panel, the user receiving unit may include other input devices. Specifically, the other input devices may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which are not described in detail herein.
Further, the touch panel may be overlaid on the display panel, and when the touch panel detects a touch operation thereon or nearby, the touch panel transmits the touch operation to the processor 42 to determine the type of the touch event, and then the processor 42 provides a corresponding visual output on the display panel according to the type of the touch event. Generally, the touch panel and the display panel are two independent components to implement the input and output functions of the electronic device, but in some embodiments, the touch panel and the display panel may be integrated to implement the input and output functions of the electronic device, and the implementation is not limited herein.
The interface unit is an interface for connecting an external device and the electronic equipment. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device having an identification module, an audio input/output (I/O) port, a video I/O port, an earphone port, and the like. The interface unit may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements in the electronic equipment or may be used to transmit data between the electronic equipment and the external device.
The electronic device may also include a power source (e.g., a battery) for powering the components, and optionally, the power source may be logically connected to the processor 42 via a power management system, such that functions of managing charging, discharging, and power consumption are performed via the power management system.
The embodiment of the invention also provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program realizes the merging and sorting method provided by the method embodiment.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media having computer-usable program code embodied in the medium.
Computer readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media may implement information storage by any method or technology, and the information may be computer-readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include transitory computer readable media (transmyedia) such as modulated data signals and carrier waves.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A merge sort method, comprising:
merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through a first comparison switching unit CAS and a second CAS respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement;
when all data in one of the two data queues is dequeued, acquiring remaining data, a first data queue and a second data queue, wherein the remaining data is the remaining data in the other of the two data queues, the first data queue is a data queue formed by data sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data sequentially dequeued by the second CAS;
and generating a merging and sorting result of the two data queues according to the residual data, the first data queue and the second data queue.
2. The method of claim 1, wherein generating the merged results of the two data queues according to the remaining data, the first data queue, and the second data queue comprises:
sequentially writing the residual data into the tail end of the first data queue to generate a third data queue;
performing reverse sequencing on the data in the second data queue to generate a fourth data queue;
and splicing the fourth data queue to the tail end of the third data queue to generate a merging and sequencing result of the two data queues.
3. The method of claim 1, wherein generating the merged results of the two data queues according to the remaining data, the first data queue, and the second data queue comprises:
writing the residual data into the tail end of the second data queue in reverse order in sequence to generate a third data queue;
performing reverse sequencing on the data in the third data queue to generate a fourth data queue;
and splicing the fourth data queue to the tail end of the first data queue to generate a merging and sequencing result of the two data queues.
4. The method of claim 1, wherein merging and ordering data in the two data queues by the first CAS from a head end of the data queues comprises:
when it is determined that first data meets the monotonicity requirement compared with second data, comparing whether third data meets the monotonicity requirement compared with the second data, wherein the third data is data which is positioned behind the first data in a data queue to which the first data belongs and has a first preset value of interval with the first data;
if the third data is determined to meet the monotonicity requirement compared with the second data, sequentially dequeuing the third data and all data before the third data;
if the third data does not meet the monotonicity requirement compared with the second data, selecting data located before the currently compared data from a data queue to which the first data belongs based on a first preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the second data or not, if so, sequentially dequeuing the fourth data and all data before the fourth data, or if not, dequeuing the second data.
5. The method of claim 1, wherein selecting a data queue to which the first data belongs and which is located before the currently compared data based on a first predetermined rule, and comparing whether the selected data satisfies a monotonicity requirement compared to the second data comprises:
selecting data which is positioned behind the first data and has an interval of [ N/2] with the first data from a data queue to which the first data belongs, and comparing whether the selected data meets monotonicity compared with the second data;
where N is the interval between the current data being compared and the first data, [ ] is a floor function.
6. The method of claim 1, wherein merging and ordering data in the two data queues by the second CAS from the tail end of the data queues comprises:
when determining that sixth data does not meet the monotonicity requirement compared with seventh data, comparing whether eighth data meets the monotonicity requirement compared with the seventh data, wherein the eighth data is data which is positioned in front of the sixth data in a data queue to which the sixth data belongs and has a second preset value interval with the first data;
if the eighth data is determined not to meet the monotonicity requirement compared with the seventh data, sequentially dequeuing the eighth data and all data after the eighth data in a reverse order;
if the eighth data meets the monotonicity requirement compared with the seventh data, selecting data behind the currently compared data from a data queue to which the seventh data belongs based on a second preset rule, and comparing whether the selected data meets the monotonicity requirement compared with the seventh data or not, if so, dequeuing all data before the fourth data and the fourth data in reverse order in sequence, or if so, dequeuing the seventh data and writing the seventh data into the second data queue.
7. The method of claim 6, wherein the selecting a data queue to which the seventh data belongs and which is located after the currently compared data based on the second predetermined rule, and comparing whether the selected data satisfies a monotonicity requirement compared with the seventh data comprises:
selecting data which is positioned in front of the sixth data and has an interval of [ M/2] with the first data from a data queue to which the sixth data belongs, and comparing whether the selected data meets monotonicity compared with the seventh data;
where M is the interval between the currently compared data and the seventh data, [ ] is a floor function.
8. A merge sort apparatus, comprising:
the merging and sequencing unit is used for merging and sequencing the data in the two data queues in parallel from the head end and the tail end of the data queues through the first comparison switching unit CAS and the second CAS respectively; the first CAS is used for dequeuing data meeting the monotonicity requirement, and the second CAS is used for dequeuing data not meeting the monotonicity requirement;
an obtaining unit, configured to obtain, when all data in one of the two data queues is dequeued, remaining data, a first data queue and a second data queue, where the remaining data is data remaining in the other of the two data queues, the first data queue is a data queue formed by data that is sequentially dequeued by the first CAS, and the second data queue is a data queue formed by data that is sequentially dequeued by the second CAS;
and the generating unit is used for generating merging and sequencing results of the two data queues according to the residual data, the first data queue and the second data queue.
9. An electronic device, comprising: a memory for storing a computer program and a processor; the processor is adapted to execute the merge sorting method of any one of claims 1-7 when the computer program is invoked.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the merge sorting method of any one of claims 1 to 7.
CN202110256265.8A 2021-03-09 2021-03-09 Merging and sorting method and device Pending CN112947889A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110256265.8A CN112947889A (en) 2021-03-09 2021-03-09 Merging and sorting method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110256265.8A CN112947889A (en) 2021-03-09 2021-03-09 Merging and sorting method and device

Publications (1)

Publication Number Publication Date
CN112947889A true CN112947889A (en) 2021-06-11

Family

ID=76229092

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110256265.8A Pending CN112947889A (en) 2021-03-09 2021-03-09 Merging and sorting method and device

Country Status (1)

Country Link
CN (1) CN112947889A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605576A (en) * 2013-11-25 2014-02-26 华中科技大学 Multithreading-based MapReduce execution system
CN104360824A (en) * 2014-11-10 2015-02-18 北京奇虎科技有限公司 Data merging method and device
US20150212797A1 (en) * 2014-01-29 2015-07-30 International Business Machines Corporation Radix sort acceleration using custom asic
CN107102839A (en) * 2017-04-13 2017-08-29 青岛蓝云信息技术有限公司 A kind of data processing method for the MapReduce that sorted based on hardware
CN108256083A (en) * 2018-01-22 2018-07-06 成都博睿德科技有限公司 Content recommendation method based on deep learning
US10552397B2 (en) * 2013-05-13 2020-02-04 Microsoft Technology Licensing, Llc Merging of sorted lists using array pair
CN111562898A (en) * 2020-05-11 2020-08-21 上海大学 Multi-stage merging and sorting method based on FPGA

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10552397B2 (en) * 2013-05-13 2020-02-04 Microsoft Technology Licensing, Llc Merging of sorted lists using array pair
CN103605576A (en) * 2013-11-25 2014-02-26 华中科技大学 Multithreading-based MapReduce execution system
US20150212797A1 (en) * 2014-01-29 2015-07-30 International Business Machines Corporation Radix sort acceleration using custom asic
US10685002B2 (en) * 2014-01-29 2020-06-16 International Business Machines Corporation Radix sort acceleration using custom asic
CN104360824A (en) * 2014-11-10 2015-02-18 北京奇虎科技有限公司 Data merging method and device
CN107102839A (en) * 2017-04-13 2017-08-29 青岛蓝云信息技术有限公司 A kind of data processing method for the MapReduce that sorted based on hardware
CN108256083A (en) * 2018-01-22 2018-07-06 成都博睿德科技有限公司 Content recommendation method based on deep learning
CN111562898A (en) * 2020-05-11 2020-08-21 上海大学 Multi-stage merging and sorting method based on FPGA

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
郑亚松 等: "MALK:一种高效处理大规模键值的MapReduce框架", 《计算机研究与发展》 *

Similar Documents

Publication Publication Date Title
US11429248B2 (en) Unread message prompt method and mobile terminal
JP7326577B2 (en) Emission antenna switching method and terminal device
US20210132773A1 (en) Method for displaying notification message and terminal device
CN109343759B (en) Screen-turning display control method and terminal
WO2017152355A1 (en) Display method and terminal device
US11838438B2 (en) Message viewing method and terminal
CN108763316B (en) Audio list management method and mobile terminal
CN107748640B (en) Screen-off display method and mobile terminal
CN107957843B (en) Control method and mobile terminal
CN110365853B (en) Prompting method and electronic equipment
CN108257104B (en) Image processing method and mobile terminal
KR20210057790A (en) Information processing method and terminal
CN108920040B (en) Application icon sorting method and mobile terminal
CN110244884B (en) Desktop icon management method and terminal equipment
CN108984066B (en) Application icon display method and mobile terminal
CN111124345A (en) Audio source processing method and mobile terminal
CN110806826A (en) Information display method and device and electronic equipment
CN108536349B (en) Icon management method and mobile terminal
CN108196781B (en) Interface display method and mobile terminal
CN107800869B (en) Split screen display method, mobile terminal and storage medium
CN112947890B (en) Merging and sorting method and device
CN108491143B (en) Object movement control method and mobile terminal
CN109508300B (en) Disk fragment sorting method and device and computer readable storage medium
CN109144860B (en) Operation method for control object and terminal equipment
CN112947889A (en) Merging and sorting method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210611

RJ01 Rejection of invention patent application after publication