Disclosure of Invention
The invention aims to provide a method, electronic equipment and medium for determining a continuous visual range of a file, which can accurately and quickly determine the continuous visual range from continuous files with high orders of magnitude.
According to a first aspect of the present invention, there is provided a method for determining a continuous visual range of a file, including:
Step S1, initially setting a continuous visual range set to be empty;
step S2, acquiring a file start visual line number SV in a visual range to be processed and an end visual line number EV in the visual range to be processed;
step S3, acquiring a file line number SF corresponding to the SV and a file line number EF corresponding to the EV;
step S4, initially setting an identification file line number GF=SF, wherein the identification file line number is used for identifying a starting file line of a continuous visual range to be currently determined;
step S5, if EF-sf=ev-SV, then step S6 is executed, otherwise step S7 is executed;
S6, determining { SF, EF } as a continuous visual range, storing the continuous visual range into the continuous visual range set, and ending the flow;
and S7, acquiring all folding lines in the visual range to be processed by adopting a binary search method based on the file start visual line number SV, the file end visual line number EV, the file line number SF, the file line number EF and the identification file line number GF, and storing all continuous visual ranges in the continuous visual range set.
According to a second aspect of the present invention there is provided an electronic device comprising at least one processor and a memory communicatively coupled to the at least one processor, wherein the memory stores instructions for execution by the at least one processor, the instructions being arranged to perform the method of the first aspect of the present invention.
According to a third aspect of the present invention there is provided a computer readable storage medium storing computer executable instructions for performing the method of the first aspect of the present invention.
Compared with the prior art, the invention has obvious advantages and beneficial effects. By means of the technical scheme, the method for determining the continuous visual range of the file, the electronic equipment and the medium can achieve quite technical progress and practicality, and have wide industrial utilization value, and the method has at least the following beneficial effects:
According to the method, the starting visual line number SV, the ending visual line number EV, the file line number SF, the file line number EF and the identification file line number GF of the file are firstly obtained, then all folding lines in the visual range to be processed are obtained based on a binary search method, and all continuous visual ranges are stored in the continuous visual range set, so that the continuous visual range can be accurately and rapidly determined from continuous files with high orders of magnitude, and the operation speed of the visual lines is improved.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to fall within the scope of the invention.
The embodiment of the invention provides a method for determining a continuous visual range of a file, which is shown in fig. 1 and comprises the following steps:
Step S1, initially setting a continuous visual range set to be empty.
The continuous visual range set is used for storing continuous visual ranges which are sequentially determined from top to bottom in the visual range to be processed, file line numbers are sequentially increased from top to bottom in the visual range, and visual line numbers are sequentially increased from top to bottom.
Step S2, acquiring a file start visual line number SV in a visual range to be processed and an end visual line number EV in the visual range to be processed.
It should be noted that the visible line number is continuous, but the file line number is not necessarily continuous because there are folded lines in the visible range.
Step S3, acquiring a file line number SF corresponding to the SV and a file line number EF corresponding to the EV.
As shown in fig. 2, in the to-be-processed visual range, a file line number SF corresponding to a file start visual line number SV in the to-be-processed visual range is 105, and a file line number EF corresponding to an end visual line number EV in the to-be-processed visual range is 200023 lines. There are 4 folds of the visual range to be treated. The file line number of the corresponding folding line at the first folding position is 109, the file line number of the corresponding folding line at the second folding position is 910, the file line number of the corresponding folding line at the third folding position is 3405, and the file line number of the corresponding folding line at the fourth folding position is 98009.
Step S4, an identification file line number gf=sf is initially set, where the identification file line number is used to identify a starting file line of the continuous visual range to be currently determined.
It should be noted that, in the embodiment of the present invention, the continuous visual range is sequentially segmented according to the visual range to be processed from top to bottom, so that the identification file line number GF is dynamically changed, and in the initial case, gf=sf. As illustrated in the example of fig. 2, gf=905 is updated after the first continuous visual range {105,109} is segmented.
Step S5, if EF-sf=ev-SV, step S6 is executed, otherwise step S7 is executed.
If EF-sf=ev-SV indicates that there is no folding line in the visual range to be processed, the process proceeds directly to step S6, and { SF, EF } is determined as the continuous visual range. If there are fold lines, step S7 is entered to determine all consecutive visual fields, one by one.
And S6, determining the { SF, EF } as a continuous visual range, storing the continuous visual range into the continuous visual range set, and ending the flow.
And S7, acquiring all folding lines in the visual range to be processed by adopting a binary search method based on the file start visual line number SV, the file end visual line number EV, the file line number SF, the file line number EF and the identification file line number GF, and storing all continuous visual ranges in the continuous visual range set.
It should be noted that, by adopting binary search and dynamically changing GF, all the folded rows in the visual range to be processed can be accurately and rapidly determined, thereby improving the determination efficiency and accuracy of the continuous visual range in the visual range to be processed.
As an embodiment, in the step S3, the file line number SF corresponding to the SV and the file line number EF corresponding to the EV are obtained based on a preset mapping table of file line numbers and visual line numbers. The mapping relation between the preset file line number and the visual line number can be obtained in advance and stored in the mapping table of the file line number and the visual line number.
As an embodiment, the step S7 includes:
Step S71, setting a first input parameter a1=sv, a second input parameter a2=ev, a third input parameter a3=sf, and a fourth input parameter a4=ef, and calling a preset folding line search function based on { A1, A2, A3, A4}, to find all folding lines from top to bottom in the visual range to be processed, determining all continuous areas except the last continuous area, and after the preset folding line search function is completely ended, updating GF to be the initial file line of the last continuous visual range, wherein the preset folding line search function is a recursive function generated based on a binary search method.
Wherein A1, A2, A3, A4 are inputs to a preset folded row search function. It can be understood that the preset folded line search function is a recursive function generated based on a binary search method, so that the preset folded line search function is continuously called inside the preset folded line search function.
Step S72, determining { GF, EF } as the last A3.
As an embodiment, the preset folded line search function includes:
step S10, inputting { A1, A2, A3, A4} into the preset folding line search function, if A2-A1>1, executing step S20, otherwise, executing step S80.
Step S20, setting the middle visible line number mv= (a1+a2+1)/2.
It should be noted that, setting mv= (a1+a2+1)/2 can ensure that the middle visible line number MV must go down every time, and further improve the efficiency of the folded line search on the basis of ensuring correctness.
Step S30, obtaining a file line number MF corresponding to the MV.
The method specifically comprises the steps of obtaining a file line number MF corresponding to an MV based on a preset file line number and visual line number mapping table. The mapping relation between the preset file line number and the visual line number can be obtained in advance and stored in the mapping table of the file line number and the visual line number.
Step S40, if MF-a3=mv-A1, then step S60 is executed, otherwise, step S50 is executed.
Step S50, a preset folded line search function is called based on { A1, A2, A3, A4}, and after the function call is completed, step S60 is executed.
It should be noted that, step S50 recalls the preset folded line search function inside the preset folded line search function based on the updated { A1, A2, A3, A4 }.
Step S60, if A4-mf=a2-MV, ending the function call, otherwise, executing step S70.
Step S70, setting a1=mv, a2=a2, a3=mf, a4=a4, calling a preset folded line search function based on { A1, A2, A3, A4}, and ending the function call after the processing is ended.
It should be noted that, step S70 recalls the preset folded line search function inside the preset folded line search function based on the updated { A1, A2, A3, A4 }.
And S80, determining a behavior folding line corresponding to the A3, determining the { GF, A3} as a continuous visual range, and storing the continuous visual range into the continuous visual range set.
When A2-A1 is less than or equal to 1, the process proceeds to step S80, which means that the visible line corresponding to A1 is adjacent to or the same as the line corresponding to A2, and the file line number A3 corresponding to A1 may be determined to be the folded line, and GF is the starting file line of the continuous visible range to be determined currently, so { GF, A3} is determined to be the continuous visible range. A4 corresponding to the current A2 is the start file line of the next continuous visual range to be determined, so gf=a4 is updated by step S90.
Step S90, update gf=a4, and end the function call.
It should be noted that, in the embodiment of the present invention, the preset folded line search function implemented through step S10-step S80 is constructed based on the dichotomy and the recursive function, and each folded line of the visual range to be processed is accurately and quickly determined one by one from top to bottom by directly or indirectly calling the preset folded line search function in the function, so as to determine each continuous visual range in the visual range to be processed, and facilitate the subsequent operations of performing lexical highlighting, signal marking, debugging, and the like based on each continuous visual range.
Further, in the above example, steps S10 to S80 are performed serially, that is, consecutive visual ranges are cut out from the visual ranges to be processed one by one in strict order of the visual ranges to be processed from top to bottom. It will be appreciated that, for each set { A1, A2, A3, A4} invoking the preset folding line search function, which is equivalent to determining whether the code line between the visual line A1-visual line A2 is continuous, whether it needs to be further split into two parts for further determination, if splitting is required, and the split two parts can be executed in parallel, but it needs to be ensured that the steps S80 and determining the corresponding action folding line of A3 are executed, the { GF, A3} is determined as a continuous visual range, and the process of storing in the continuous visual range set needs to be executed strictly in a serial manner. The method can further improve the determination efficiency of the continuous visual range on the premise of ensuring the accuracy of determining the continuous visual range of the file by combining parallel and serial execution.
It should be noted that, in order to further ensure the accuracy of determining the continuous visual range of the file, in the step S30, the preset folded line search function further includes a step S00, which is set before the step S10, ending the function call if a4_a3=a2_a1, otherwise, executing the step S10. It should be noted that, the calling condition of the preset folded line search function has filtered the case of a4-a3=a2-a1, and by setting S00, it can further detect whether the case of a4-a3=a2-a1 triggers the preset folded line search function by mistake, thereby further improving the accuracy of determining the continuous visual range of the file.
According to the embodiment of the invention, the file start visual line number SV, the file end visual line number EV, the file line number SF, the file line number EF and the identification file line number GF are firstly obtained, then all the folding lines in the visual range to be processed are obtained based on a binary search method, and all the continuous visual ranges are stored in the continuous visual range set, so that the continuous visual range can be accurately and rapidly determined from continuous files with high orders of magnitude, and the operation speed of the visual lines is improved.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and/or" as used herein includes any and all combinations of one or more of the associated listed items.
It should be noted that some exemplary embodiments are described as a process or a method depicted as a flowchart. Although a flowchart depicts steps as a sequential process, many of the steps may be implemented in parallel, concurrently, or with other steps. Furthermore, the order of the steps may be rearranged. The process may be terminated when its operations are completed, but may have additional steps not included in the figures. The processes may correspond to methods, functions, procedures, subroutines, and the like.
The embodiment of the invention also provides electronic equipment, which comprises at least one processor and a memory in communication connection with the at least one processor, wherein the memory stores instructions executed by the at least one processor, and the instructions are configured to execute the method of the embodiment of the invention.
The embodiment of the invention also provides a computer readable storage medium, which stores computer executable instructions for executing the method according to the embodiment of the invention.
The present invention is not limited to the preferred embodiments, and the present invention is described above in any way, but is not limited to the preferred embodiments, and any person skilled in the art will appreciate that the present invention is not limited to the embodiments described above, while the above disclosure is directed to various equivalent embodiments, which are capable of being modified or varied in several ways, it is apparent to those skilled in the art that many modifications, variations and adaptations of the embodiments described above are possible in light of the above teachings.