CN107463676A - Text data store method and device - Google Patents

Text data store method and device Download PDF

Info

Publication number
CN107463676A
CN107463676A CN201710664232.0A CN201710664232A CN107463676A CN 107463676 A CN107463676 A CN 107463676A CN 201710664232 A CN201710664232 A CN 201710664232A CN 107463676 A CN107463676 A CN 107463676A
Authority
CN
China
Prior art keywords
node
characters
binary tree
data structure
pending
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.)
Granted
Application number
CN201710664232.0A
Other languages
Chinese (zh)
Other versions
CN107463676B (en
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.)
DBAPPSecurity Co Ltd
Original Assignee
DBAPPSecurity 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 DBAPPSecurity Co Ltd filed Critical DBAPPSecurity Co Ltd
Priority to CN201710664232.0A priority Critical patent/CN107463676B/en
Publication of CN107463676A publication Critical patent/CN107463676A/en
Application granted granted Critical
Publication of CN107463676B publication Critical patent/CN107463676B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/31Indexing; Data structures therefor; Storage structures
    • G06F16/316Indexing structures
    • G06F16/322Trees

Abstract

The invention provides a kind of text data store method and device, it is related to the technical field of text-processing, this method includes:Obtain the data to be stored in text data and current time text data;The number of characters of data to be stored is read, and reads position of the data to be stored in text data, position includes:Line number or columns;The node corresponding with position is searched in the binary tree data structure built in advance, and number of characters is defined as to the nodal value of corresponding node, to be stored to number of characters, wherein, binary tree data structure defines the storage order of node according to the inorder traversal order of binary tree in advance.The present invention come the number of characters for storing each row in text data or respectively arranging, alleviates existing less efficient technical problem during target character in localization of text in the prior art using binary tree data structure.

Description

Text data store method and device
Technical field
The present invention relates to the technical field of text-processing, more particularly, to a kind of text data store method and device.
Background technology
The storage of text character, substantially it is the storage to continuation character sequence.Traditional continuation character sequence storage side Formula has array and chained list, in both storage modes, inserts character in text and deletes after character, it is necessary to location revision Word afterwards is shifted, so that the corresponding relation of character and character in the text between residing line number is become Change.
However, for modern text editor, the corresponding relation between text character and its line number is constantly safeguarded, Be advantageous to be quickly positioned target character when text is by reading and editor, there is higher practicality in the scenes such as Code Edit Value.Localization method of the prior art is in above two storage mode, searches target word from the beginning in the text , for larger file, the relatively low technical problem of location efficiency be present in symbol.
The content of the invention
In view of this, it is an object of the invention to provide a kind of text data store method and device, to alleviate existing skill Existing less efficient technical problem during target character in Intraoperative position text.
In a first aspect, the embodiments of the invention provide a kind of storage method of text character number, including:
Obtain the data to be stored in text data described in text data and current time;
The number of characters of the data to be stored is read, and reads position of the data to be stored in the text data Put, the position includes:Line number or columns;
Search the node corresponding with the position in the binary tree data structure built in advance, and by the number of characters It is defined as the nodal value of the corresponding node, to be stored to the number of characters, wherein, the binary tree data structure is pre- First the storage order of node is defined according to the inorder traversal order of binary tree.
With reference in a first aspect, the embodiments of the invention provide the possible embodiment of the first of first aspect, wherein,
The number of characters of the data to be stored is read, including:
Count the number of characters of each position in the text data;
According to the order of the position, the number of characters is ranked up, obtains character Number Sequence;
The number of characters of data to be stored in text data described in current time is read from the character Number Sequence.
With reference in a first aspect, the embodiments of the invention provide the possible embodiment of second of first aspect, wherein, The node corresponding with the position is searched in the binary tree data structure built in advance, including:
According to the storage order, first object node is searched from the binary tree data structure, and by described first Destination node as the corresponding node, wherein, storage of the first object node in the binary tree data structure The sorting position to sort with the position in the text data is identical.
With reference in a first aspect, the embodiments of the invention provide the possible embodiment of the third of first aspect, wherein, institute Stating method also includes:
The operational order that user sends is obtained, the binary tree data structure is performed according to the operational order corresponding Operation,
Wherein, the operational order comprises at least one below:Change operational order, insertion operation instruction, deletion action Instruction.
With reference to the third possible embodiment of first aspect, the embodiments of the invention provide the 4th of first aspect kind Possible embodiment, wherein, corresponding operation is performed to the binary tree data structure according to the operational order, including:
The root node of the binary tree data structure is obtained, and the root node is defined as initial pending node, instead Following steps are performed again, until meet circulation stop condition,
First comparison step, for will be compared in the number of nodes of the pending node at current time and target value Compared with, wherein, the target value is line number of the target line of the pending operation in the text data and 1 difference;
Second comparison step, the number of nodes for the pending node at current time is not less than the target value In the case of, by the number of nodes of the left sibling of the pending node at current time compared with the target value;
First determines step, and the number of nodes for the left sibling of the pending node at current time is more than the target In the case of numerical value, the pending node of subsequent time will be defined as in the left sibling of the pending node at current time;
Second determines step, and the number of nodes for the left sibling of the pending node at current time is less than the target In the case of numerical value, the pending node of subsequent time will be defined as in the right node of the pending node at current time, and pass through More new formula is updated to the target value, wherein, the more new formula is:ki=ki-1- (subsequent time it is pending The number of nodes+1 of left sibling in node), kiFor the target value after renewal, ki-1For the target value before renewal;
Return to step, for will be defined as in the pending node of subsequent time in current time pending node, and return The comparison step is performed, wherein, the subsequent time is the subsequent time at the current time, and the circulation stop condition is It is less than the target value in the number of nodes of the left sibling of the pending node at current time, wherein, after circulation terminates, The pending node at current time is defined as the second destination node, based on second destination node to the b-tree data Structure is operated.
With reference to the 4th kind of possible embodiment of first aspect, the embodiments of the invention provide the 5th of first aspect kind Possible embodiment, wherein, in the case of the operational order is modification operational order,
It is described that the binary tree data structure is operated based on second destination node, including:
The target value carried in the modification operational order and modification number of characters are obtained, wherein, the modification word Symbol number is the number of characters after being modified to the target line;
The nodal value of second destination node is replaced with into the modification number of characters.
With reference to the 4th kind of possible embodiment of first aspect, the embodiments of the invention provide the 6th of first aspect kind Possible embodiment, wherein, in the case where the operational order is insertion operation instruction,
It is described that the binary tree data structure is operated based on second destination node, including:
The target value carried in the insertion operation instruction and insertion number of characters are obtained, wherein, the insertion word Symbol number is the number of characters of the text inserted before the target line,
Nodal value in first positive node to be repaired is defined as to the nodal value of the second positive node to be repaired successively, and inserted described Enter the nodal value that number of characters is defined as second destination node;
Wherein, the described second positive node to be repaired is the next of the first positive node to be repaired described in the binary tree data structure Individual node, first positive node to be repaired are second destination node, and are located in the storage order and described second Node after destination node.
With reference to the 4th kind of possible embodiment of first aspect, the embodiments of the invention provide the 7th of first aspect kind Possible embodiment, wherein, in the case where the operational order includes deletion action instruction,
It is described that the binary tree data structure is operated based on second destination node, including:
Obtain the target value carried in the deletion action instruction;
Nodal value using the nodal value in the 3rd positive node to be repaired as the 4th positive node to be repaired successively, and by the y-bend Last nodal value performed in the node of storage operation in data tree structure empties, or, delete it is described last Perform the node of storage operation;
Wherein, the 3rd positive node to be repaired be the 4th positive node to be repaired after next node, the described 4th Positive node to be repaired is second destination node, and be located in the storage order and second destination node after section Point.
With reference in a first aspect, the embodiments of the invention provide the possible embodiment of the 8th of first aspect kind, wherein, The number of characters is defined as after the nodal value of the corresponding node, methods described also includes:
The 3rd destination node is extracted, wherein, the 3rd destination node is any one in the binary tree data structure Individual node;
The nodal value sum of all nodes of subtree representated by the 3rd destination node is calculated, obtains the 3rd destination node Node and, wherein, the 3rd destination node be the subtree root node;
Corresponding storage is carried out by the node and with the 3rd destination node, obtains storage information, wherein, the storage The character that information is used for the text data is positioned.
Second aspect, the embodiment of the present invention also provide a kind of storage device of text data, including:
Acquisition module, for obtaining the data to be stored in text data described in text data and current time;
Read module, for reading the number of characters of the data to be stored, and the data to be stored is read described Position in text data, the position include:Line number or columns;
Determining module, for searching the node corresponding with the position in the binary tree data structure built in advance, And the number of characters is defined as to the nodal value of the corresponding node, to be stored to the number of characters, wherein, described two Tree data structure defines the storage order of node according to the inorder traversal order of binary tree in advance.
With reference to second aspect, the embodiments of the invention provide the possible embodiment of the first of second aspect, wherein, institute Stating read module includes:
Statistic unit, for counting the number of characters of each position in the text data;
Sequencing unit, for the order according to the position, the number of characters is ranked up, obtains character Number Sequence;
Reading unit, for reading data to be stored in text data described in current time from the character Number Sequence Number of characters.
With reference to second aspect, the embodiments of the invention provide the possible embodiment of second of second aspect, wherein, institute Determining module is stated to be used for:
According to the storage order, first object node is searched from the binary tree data structure, and by described first Destination node as the corresponding node, wherein, storage of the first object node in the binary tree data structure The sorting position to sort with the position in the text data is identical.
With reference to second aspect, the embodiments of the invention provide the possible embodiment of the third of second aspect, wherein, institute Stating text character number storage device also includes:
Operation module, for obtaining the operational order of user's transmission, according to the operational order to the b-tree data Structure performs corresponding operation,
Wherein, the operational order comprises at least one below:Change operational order, insertion operation instruction, deletion action Instruction.
With reference to the third possible embodiment of second aspect, the embodiments of the invention provide the 4th of second aspect kind Possible embodiment, wherein, the operation module includes positioning unit, and the positioning unit is used to perform:
The root node of the binary tree data structure is obtained, and the root node is defined as initial pending node, instead Following steps are performed again, until meet circulation stop condition,
First comparison step, for will be compared in the number of nodes of the pending node at current time and target value Compared with, wherein, the target value is line number of the target line of the pending operation in the text data and 1 difference;
Second comparison step, the number of nodes for the pending node at current time is not less than the target value In the case of, by the number of nodes of the left sibling of the pending node at current time compared with the target value;
First determines step, and the number of nodes for the left sibling of the pending node at current time is more than the target In the case of numerical value, the pending node of subsequent time will be defined as in the left sibling of the pending node at current time;
Second determines step, and the number of nodes for the left sibling of the pending node at current time is less than the target In the case of numerical value, the pending node of subsequent time will be defined as in the right node of the pending node at current time, and pass through More new formula is updated to the target value, wherein, the more new formula is:ki=ki-1- (subsequent time it is pending The number of nodes+1 of left sibling in node), kiFor the target value after renewal, ki-1For the target value before renewal;
Return to step, for will be defined as in the pending node of subsequent time in current time pending node, and return The comparison step is performed, wherein, the subsequent time is the subsequent time at the current time, and the circulation stop condition is It is less than the target value in the number of nodes of the left sibling of the pending node at current time, wherein, after circulation terminates, The pending node at current time is defined as the second destination node, based on second destination node to the b-tree data Structure is operated.
With reference to the 4th kind of possible embodiment of second aspect, the embodiments of the invention provide the 5th of second aspect kind Possible embodiment, wherein, the operation module includes modification unit, and the modification unit is used for:
In the case of the operational order is modification operational order,
It is described that the binary tree data structure is operated based on second destination node, including:
The target value carried in the modification operational order and modification number of characters are obtained, wherein, the modification word Symbol number is the number of characters after being modified to the target line;
The nodal value of second destination node is replaced with into the modification number of characters.
With reference to the 4th kind of possible embodiment of second aspect, the embodiments of the invention provide the 6th of second aspect kind Possible embodiment, wherein, the operation module includes insertion unit, and the insertion unit is used for:
In the case where the operational order is insertion operation instruction,
It is described that the binary tree data structure is operated based on second destination node, including:
The target value carried in the insertion operation instruction and insertion number of characters are obtained, wherein, the insertion word Symbol number is the number of characters of the text inserted before the target line,
Nodal value in first positive node to be repaired is defined as to the nodal value of the second positive node to be repaired successively, and inserted described Enter the nodal value that number of characters is defined as second destination node;
Wherein, the described second positive node to be repaired is the next of the first positive node to be repaired described in the binary tree data structure Individual node, first positive node to be repaired are second destination node, and are located in the storage order and described second Node after destination node.
With reference to the 4th kind of possible embodiment of second aspect, the embodiments of the invention provide the 7th of second aspect kind Possible embodiment, wherein, the operation module includes deleting unit, and the deletion unit is used for:
In the case where the operational order includes deletion action instruction,
It is described that the binary tree data structure is operated based on second destination node, including:
Obtain the target value carried in the deletion action instruction;
Nodal value using the nodal value in the 3rd positive node to be repaired as the 4th positive node to be repaired successively, and by the y-bend Last nodal value performed in the node of storage operation in data tree structure empties, or, delete it is described last Perform the node of storage operation;
Wherein, the 3rd positive node to be repaired be the 4th positive node to be repaired after next node, the described 4th Positive node to be repaired is second destination node, and be located in the storage order and second destination node after section Point.
With reference to second aspect, the embodiments of the invention provide the possible embodiment of the 8th of second aspect kind, wherein, institute Stating text character number storage device also includes:Summation module, the summation module are used for:Described in the number of characters is defined as After the nodal value of corresponding node,
The 3rd destination node is extracted, wherein, the 3rd destination node is any one in the binary tree data structure Individual node;
The nodal value sum of all nodes of subtree representated by the 3rd destination node is calculated, obtains the 3rd destination node Node and, wherein, the 3rd destination node be the subtree root node;
Corresponding storage is carried out by the node and with the 3rd destination node, obtains storage information, wherein, the storage The character that information is used for the text data is positioned.
The embodiment of the present invention brings following beneficial effect:Obtain and wait to deposit in text data and current time text data Store up data;Then the number of characters of data to be stored is read, and reads position of the data to be stored in text data, position bag Include:Line number or columns;Search the node corresponding with position in the binary tree data structure built in advance, and by number of characters It is defined as the nodal value of corresponding node, to be stored to number of characters, wherein, binary tree data structure is in advance according to binary tree Inorder traversal order define the storage order of node.Node is defined by the inorder traversal order in advance according to binary tree The binary tree data structure of storage order store the number of characters of data to be stored so that each row or respectively arranged in text data The lookup and maintenance of number of characters are more convenient, are advantageous to according to each row in text data or the number of characters respectively arranged positioning target word Symbol, existing less efficient technical problem during so as to alleviate target character in localization of text in the prior art.
Other features and advantages of the present invention will illustrate in the following description, also, partly become from specification Obtain it is clear that or being understood by implementing the present invention.The purpose of the present invention and other advantages are in specification, claims And specifically noted structure is realized and obtained in accompanying drawing.
To enable the above objects, features and advantages of the present invention to become apparent, preferred embodiment cited below particularly, and coordinate Appended accompanying drawing, is described in detail below.
Brief description of the drawings
, below will be to specific in order to illustrate more clearly of the specific embodiment of the invention or technical scheme of the prior art The required accompanying drawing used is briefly described in embodiment or description of the prior art, it should be apparent that, in describing below Accompanying drawing is some embodiments of the present invention, for those of ordinary skill in the art, before creative work is not paid Put, other accompanying drawings can also be obtained according to these accompanying drawings.
Fig. 1 is the inorder traversal schematic diagram of binary tree;
Fig. 2 is a kind of flow chart of the storage method for text character number that the embodiment of the present invention one provides;
Fig. 3 is the flow chart of the storage method for another text character number that the embodiment of the present invention one provides;
Fig. 4 is a kind of flow chart for localization method that the embodiment of the present invention one provides;
Fig. 5 is a kind of flow chart for amending method that the embodiment of the present invention one provides;
Fig. 6 is a kind of flow chart for insertion method that the embodiment of the present invention one provides;
Fig. 7 is a kind of flow chart for delet method that the embodiment of the present invention one provides;
Fig. 8 is a kind of flow chart for summation method that the embodiment of the present invention one provides;
Fig. 9 is a kind of structured flowchart of the storage device for text data that the embodiment of the present invention two provides;
Figure 10 is the structured flowchart of the storage device for another text data that the embodiment of the present invention two provides;
Figure 11 is the structured flowchart for the operation module that the embodiment of the present invention two provides.
Icon:100- acquisition modules;200- read modules;300- determining modules;400- operation modules;401- positioning is single Member;402- changes unit;403- inserts unit;404- deletes unit.
Embodiment
To make the purpose, technical scheme and advantage of the embodiment of the present invention clearer, below in conjunction with accompanying drawing to the present invention Technical scheme be clearly and completely described, it is clear that described embodiment is part of the embodiment of the present invention, rather than Whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art are not making creative work premise Lower obtained every other embodiment, belongs to the scope of protection of the invention.
Localization method of the prior art is in above two storage mode, searches target word from the beginning in the text , for larger file, the relatively low technical problem of location efficiency be present in symbol.Based on this, a kind of text provided in an embodiment of the present invention Notebook data storage method and device, existing less efficient skill during target character in localization of text in the prior art can be alleviated Art problem.
Before the specific embodiment of the present invention is described, first binary tree data structure seat is made a presentation:
(1) data storage, the data of destination node storage are referred to as the " section of destination node to binary tree data structure in node Point value ";
(2) each node in binary tree data structure at most has two child nodes, the son section on the left of destination node Point is referred to as " left sibling " of destination node, and the child node positioned at right side is referred to as " the right node " of destination node;
(3) " number of nodes " of the number of nodes contained by the subtree representated by destination node, referred to as destination node, wherein, Subtree representated by destination node refers to:The root node of subtree is destination node;
(4) " the node of the nodal value sum, referred to as destination node of all nodes contained by the subtree representated by destination node With ";
(5) the traversal of binary tree order of binary tree data structure includes:Preamble traversal, postorder traversal and inorder traversal. Inorder traversal is illustrated again, inorder traversal travels through left subtree first, then travels through root node, finally travels through right subtree, Wherein, when traveling through left and right subtree, still according to first traveling through left subtree, then root node is traveled through, finally travels through the order of right subtree Traveled through.Reference picture 1, in the binary tree data structure shown in Fig. 1, the order of inorder traversal is DBEAFCG.
Embodiment one
The embodiments of the invention provide a kind of storage method of text character number, as shown in Fig. 2 including:
Step S12, obtain the data to be stored in text data and current time text data.
Step S14, the number of characters of data to be stored is read, and reads position of the data to be stored in text data, Position includes:Line number or columns.
Specifically, in the case where text data is sorted with row, position includes row;And in text data to arrange the feelings of sequence Under condition, position includes row.
Step S16, searches the node corresponding with position in the binary tree data structure built in advance, and by number of characters It is defined as the nodal value of corresponding node, to be stored to number of characters, wherein, binary tree data structure is in advance according to binary tree Inorder traversal order define the storage order of node.
In the embodiment of the present invention, the storage order of node is defined by the inorder traversal order in advance according to binary tree Binary tree data structure stores the number of characters of data to be stored so that the lookup of each row or the number of characters respectively arranged in text data It is more convenient with safeguarding, be advantageous to according to each row in text data or the number of characters respectively arranged positioning target character, so as to alleviate Existing less efficient technical problem during target character in localization of text in the prior art.
In one optional embodiment of the embodiment of the present invention, the number of characters of data to be stored is read, including:
Count the number of characters of each position in text data;
According to the order of position, number of characters is ranked up, obtains character Number Sequence;
The number of characters of data to be stored in current time text data is read from character Number Sequence.
In another optional embodiment of the embodiment of the present invention, in the binary tree data structure built in advance search with The corresponding node in position, including:
According to storage order, search first object node from binary tree data structure, and using first object node as Corresponding node, wherein, memory sequencing of the first object node in binary tree data structure is with position in text data Sorting position is identical.For example, in the case where data to be stored is the first rows in text data, then the y-bend shown in Fig. 1 The node corresponding with the first row in data tree structure is A nodes;It is the third line in text data in data to be stored In the case of, then the node corresponding with the third line in the binary tree data structure shown in Fig. 1 is F nodes.
In another optional embodiment of the embodiment of the present invention, as shown in figure 3, text character number date storage method is also Including:
Step S18, the operational order that user sends is obtained, binary tree data structure is performed according to operational order corresponding Operation,
Wherein, operational order comprises at least one below:Change operational order, insertion operation instruction, deletion action instruction.
In the embodiment of the present invention, after the number of characters that text data is stored in binary tree data structure, used by obtaining The operational order that family is sent, corresponding operation is performed to binary tree data structure according to operational order, to reach to textual data The purpose safeguarded during according to modifying to binary tree data structure.
In the case where operational order includes modification operational order, insertion operation instruction, deletion action instruction respectively, to two The flow that tree data structure is safeguarded is as follows:
In another optional embodiment of the embodiment of the present invention, as shown in figure 4, according to operational order pair in step S18 Binary tree data structure performs corresponding operation, includes first:Positioning step, positioning step include:
Step S41, the root node of binary tree data structure is obtained, and root node is defined as initial pending node, instead Following steps are performed again, until meet circulation stop condition,
Step S42, the first comparison step, for by the number of nodes and target value of the pending node at current time It is compared, wherein, target value is line number of the target line of pending operation in text data and 1 difference.
Specifically, in the case where the number of nodes of the pending node at current time is less than target value, then it is fixed to terminate Position step.
Step S43, the second comparison step, the number of nodes for the pending node at current time are not less than number of targets In the case of value, by the number of nodes of the left sibling of the pending node at current time compared with target value;
Step S44, first determines step, and the number of nodes for the left sibling of the pending node at current time is more than In the case of target value, the pending node of subsequent time will be defined as in the left sibling of the pending node at current time;
Step S45, second determines step, and the number of nodes for the left sibling of the pending node at current time is less than In the case of target value, the pending node of subsequent time will be defined as in the right node of the pending node at current time, and Target value is updated by more new formula, wherein, more new formula is:ki=ki-1- (the pending node of subsequent time In left sibling number of nodes+1), kiFor the target value after renewal, ki-1For the target value before renewal;
Step S46, return to step, for will be defined as in the pending node of subsequent time in current time pending section Point, and execution comparison step is returned, wherein, subsequent time is the subsequent time at current time, and circulation stop condition is current The number of nodes of the left sibling of the pending node at moment is less than target value.
Wherein, after circulation terminates, step S47 is performed, the pending node at current time is defined as the second target Node, binary tree data structure is operated based on the second destination node.
The embodiment of the present invention gives and first treated when performing corresponding operation to binary tree data structure according to operational order The target line for performing operation is positioned, next to implement further operation based on the target line navigated to.
It is emphasized that alternatively, can also be by second after the second destination node corresponding to target line is navigated to The nodal value of destination node is exported to user, to reach the purpose for the number of characters for allowing user to search target line.It should be noted that " user " in the embodiment of the present invention includes being in the people using a side or equipment, similarly hereinafter.
In another optional embodiment of the embodiment of the present invention, as shown in figure 5, being modification operational order in operational order In the case of, binary tree data structure is operated based on the second destination node in step S47, including:
Step S51, the target value carried in modification operational order and modification number of characters are obtained, wherein, change number of characters For the number of characters after being modified to target line;
Step S52, the nodal value of the second destination node is replaced with into modification number of characters.
Specifically, a certain line character in text data modifies (deletion, increase and the replacement that include words), If total line number of text is not increased or decreased, combination step S51 and step suitable for the embodiment of the present invention S52 and the flow safeguarded to binary tree data structure provided.
In another optional embodiment of the embodiment of the present invention, as shown in fig. 6, being instructed in operational order for insertion operation In the case of, binary tree data structure is operated based on the second destination node in step S47, including:
Step S61, binary tree data structure is operated based on the second destination node, including:
Step S62, the target value carried in insertion operation instruction and insertion number of characters are obtained, wherein, insert number of characters For the number of characters of the text inserted before target line,
Step S63, the nodal value in the first positive node to be repaired is defined as to the nodal value of the second positive node to be repaired successively, and Insertion number of characters is defined as to the nodal value of the second destination node;
Wherein, the second positive node to be repaired be binary tree data structure in the first positive node to be repaired next node, first Positive node to be repaired is the second destination node, and be located in storage order and the second destination node after node.
Specifically, when inserting a line character to text data, then suitable for the combination step in the embodiment of the present invention S61, step S62 and step S63 and the flow safeguarded to binary tree data structure provided.
In another optional embodiment of the embodiment of the present invention, as shown in fig. 7, referring in operational order including deletion action In the case of order, binary tree data structure is operated based on the second destination node in step S47, including:
Step S71, obtain the target value carried in deletion action instruction;
Step S72, the successively nodal value using the nodal value in the 3rd positive node to be repaired as the 4th positive node to be repaired, and will Last nodal value performed in the node of storage operation in binary tree data structure empties, or, delete last Perform the node of storage operation;
Wherein, the 3rd positive node to be repaired is the next node after the 4th positive node to be repaired, and the 4th positive node to be repaired is Second destination node, and be located in storage order and the second destination node after node.
Specifically, when increasing a line character newly to text data, then suitable for the combination step in the embodiment of the present invention The flow safeguarded to binary tree data structure that S71 and step S72 are provided.
In another optional embodiment of the embodiment of the present invention, the number of characters is being defined as the corresponding node Nodal value after, the storage method of text data also includes:
The 3rd destination node is extracted, wherein, the 3rd destination node is any one node in binary tree data structure;
The nodal value sum of all nodes of subtree representated by the 3rd destination node is calculated, obtains the section of the 3rd destination node Point and, wherein, the 3rd destination node be subtree root node;
Corresponding storage is carried out by node and with the 3rd destination node, obtains storage information, wherein, storage information is used for text The character of data is positioned.
Further, reference picture 8, can be by following in the number of characters summation of n rows before user needs acquisition text data N line character number summations before step pushes to user:
Step S81, initial value is assigned to preceding n line characters number summation:Preceding n line characters number summation sum=0, then obtains y-bend The root node of data tree structure, and root node is defined as initial pending node, step S82, step S83, step are performed repeatedly Rapid S84 and step S85, until meet circulation stop condition, wherein,
Step S82, for will be compared in the number of nodes of the pending node at current time and target value, its In, target value is line number of the target line of pending operation in text data and 1 difference, i.e. target value k=n-1;
Specifically, number of nodes be less than target value in the case of, information to be displayed " mistake " can be returned, terminate to Before user's push the step of n line character number summations;In the case where number of nodes is not less than target value, step S83 is performed.
Step S83, the number of nodes of the left sibling of the pending node at current time and target value are compared.
Wherein, in the case where the number of nodes of left sibling is more than target value, step S84 is performed;In the section of left sibling In the case that point quantity is less than target value, step S85 is performed;It is equal to the situation of target value in the number of nodes of left sibling Under, end loop
Step S84, the left sibling in the pending node at current time is defined as in the pending node of subsequent time, And it will be defined as, in current time pending node, returning and performing step S82 in the pending node of subsequent time;
Step S85, the right node in the pending node at current time is defined as in the pending node of subsequent time, And perform the first assignment procedure:sumi=sumi-1+ (node of the left sibling in the pending node of subsequent time and+is lower for the moment The nodal value for the pending node carved) and the second target value renewal step ki=ki-1- (in the pending node of subsequent time Left sibling number of nodes+1), and will be defined as in the pending node of subsequent time in current time pending node, return Step S82 is performed, wherein, kiThe target value after being updated in step, k are updated for target valuei-1Update and walk for target value Target value before being updated in rapid;
Wherein, after circulation terminates, step S86 is performed, then terminates the step of n line character number summations before being pushed to user Suddenly, wherein,
Step S86, for performing the second assignment procedure:sumi=sumi-1+ (the left side in the pending node at current time The nodal value of the node of node and the pending node at+current time), then terminate, can be by sumiExport to user, its In, sumiThe value of the preceding n line characters number summation obtained for current time in circulation step, sumi-1The preceding n obtained for last moment The value of line character number summation.
It should be noted that subsequent time is the subsequent time at current time, last moment is the upper a period of time at current time Carve.Circulation stop condition is number of nodes of the comparative result in step S83 for the left sibling of the pending node at current time Equal to target value.
Embodiment two
The embodiment of the present invention also provides a kind of storage device of text data, as shown in figure 9, including:
Acquisition module 100, for obtaining the data to be stored in text data and current time text data;
Read module 200, for reading the number of characters of data to be stored, and data to be stored is read in text data Position, position includes:Line number or columns;
Determining module 300, for searching the node corresponding with position in the binary tree data structure built in advance, and Number of characters is defined as to the nodal value of corresponding node, to be stored to number of characters, wherein, binary tree data structure is pressed in advance The storage order of node is defined according to the inorder traversal order of binary tree.
In the embodiment of the present invention, acquisition module 100 obtains the number to be stored in text data and current time text data According to then read module 200 reads the number of characters of data to be stored, and reads position of the data to be stored in text data Put, determining module 300 passes through the binary tree in the storage order for defining node according to the inorder traversal order of binary tree in advance Data structure stores the number of characters of data to be stored so that the lookup and maintenance of each row or the number of characters respectively arranged in text data It is more convenient, be advantageous to according to each row in text data or the number of characters respectively arranged positioning target character, so as to alleviate existing skill Existing less efficient technical problem during target character in Intraoperative position text.
In one optional embodiment of the embodiment of the present invention, read module 200 includes:
Statistic unit, for counting the number of characters of each position in text data;
Sequencing unit, for the order according to position, number of characters is ranked up, obtains character Number Sequence;
Reading unit, for reading the number of characters of data to be stored in current time text data from character Number Sequence.
In one optional embodiment of the embodiment of the present invention, determining module 300 is used for:
According to storage order, search first object node from binary tree data structure, and using first object node as Corresponding node, wherein, memory sequencing of the first object node in binary tree data structure is with position in text data Sorting position is identical.
In one optional embodiment of the embodiment of the present invention, as shown in Figure 10, text character number storage device also includes:
Operation module 400, for obtaining the operational order of user's transmission, binary tree data structure is held according to operational order The corresponding operation of row,
Wherein, operational order comprises at least one below:Change operational order, insertion operation instruction, deletion action instruction.
In one optional embodiment of the embodiment of the present invention, reference picture 11, operation module 400 includes positioning unit 401, Positioning unit 401 is used for:
Obtain the root node of binary tree data structure, and root node be defined as initial pending node, perform repeatedly with Lower step, until meet circulation stop condition,
First comparison step, for will be compared in the number of nodes of the pending node at current time and target value Compared with, wherein, target value is line number of the target line of pending operation in text data and 1 difference;
Second comparison step, the number of nodes for the pending node at current time are not less than the situation of target value Under, by the number of nodes of the left sibling of the pending node at current time compared with target value;
First determines step, and the number of nodes for the left sibling of the pending node at current time is more than target value In the case of, the pending node of subsequent time will be defined as in the left sibling of the pending node at current time;
Second determines step, and the number of nodes for the left sibling of the pending node at current time is less than target value In the case of, the pending node of subsequent time will be defined as in the right node of the pending node at current time, and pass through renewal Formula is updated to target value, wherein, more new formula is:ki=ki-1- (the left section in the pending node of subsequent time The number of nodes+1 of point), kiFor the target value after renewal, ki-1For the target value before renewal;
Return to step, for will be defined as in the pending node of subsequent time in current time pending node, and return Comparison step is performed, wherein, subsequent time is the subsequent time at current time, and circulation stop condition is to wait to locate at current time The number of nodes for managing the left sibling of node is less than target value, wherein, after circulation terminates, by the pending section at current time Point is defined as the second destination node, and binary tree data structure is operated based on the second destination node.
In one optional embodiment of the embodiment of the present invention, reference picture 11, operation module 400 includes modification unit 402, Modification unit 402 is used for:
In the case of operational order is modification operational order,
Binary tree data structure is operated based on the second destination node, including:
The target value carried in modification operational order and modification number of characters are obtained, wherein, modification number of characters is to target The number of characters gone after modifying;
The nodal value of second destination node is replaced with into modification number of characters.
In one optional embodiment of the embodiment of the present invention, reference picture 11, operation module 400 includes insertion unit 403, Insertion unit 403 is used for:
In the case where operational order is insertion operation instruction,
Binary tree data structure is operated based on the second destination node, including:
The target value carried in insertion operation instruction and insertion number of characters are obtained, wherein, insertion number of characters is in target The number of characters for the text that row inserts before,
Nodal value in first positive node to be repaired is defined as to the nodal value of the second positive node to be repaired successively, and word will be inserted Symbol number is defined as the nodal value of the second destination node;
Wherein, the second positive node to be repaired be binary tree data structure in the first positive node to be repaired next node, first Positive node to be repaired is the second destination node, and be located in storage order and the second destination node after node.
In one optional embodiment of the embodiment of the present invention, reference picture 11, operation module 400 includes deleting unit 404, Unit 404 is deleted to be used for:
In the case where operational order includes deletion action instruction,
Binary tree data structure is operated based on the second destination node, including:
Obtain the target value carried in deletion action instruction;
Nodal value using the nodal value in the 3rd positive node to be repaired as the 4th positive node to be repaired successively, and by binary tree number The nodal value performed according to last in structure in the node of storage operation empties, or, delete last and perform storage The node of operation;
Wherein, the 3rd positive node to be repaired is the next node after the 4th positive node to be repaired, and the 4th positive node to be repaired is Second destination node, and be located in storage order and the second destination node after node.
In one optional embodiment of the embodiment of the present invention, text character number storage device also includes:Summation module, ask It is used for module:After the number of characters is defined as into the nodal value of the corresponding node,
The 3rd destination node is extracted, wherein, the 3rd destination node is any one node in binary tree data structure;
The nodal value sum of all nodes of subtree representated by the 3rd destination node is calculated, obtains the section of the 3rd destination node Point and, wherein, the 3rd destination node be subtree root node;
Corresponding storage is carried out by node and with the 3rd destination node, obtains storage information, wherein, storage information is used for text The character of data is positioned.
Further, n line character numbers ask for unit before summation module can connect a text data, and sum unit is used to hold Step S81, step S82, step S83, step S84, step S85 and step S86 in row embodiment one.
Further, the positioning unit 401 in the text character number storage device of the embodiment of the present invention, modification unit 402, insert Data transmission interface can be set by entering unit 403, deletion unit 404 and sum unit, and data receiver port receives user's hair The corresponding operating instruction sent, the data for then wanting to obtain to user output user according to the data included in operational order.
The text storage method and the computer program product of device that the embodiment of the present invention is provided, including store program The computer-readable recording medium of code, the instruction that described program code includes can be used for performing described in previous methods embodiment Method, specific implementation can be found in embodiment of the method, will not be repeated here.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description With the specific work process of device, the corresponding process in preceding method embodiment is may be referred to, will not be repeated here.
In addition, in the description of the embodiment of the present invention, unless otherwise clearly defined and limited, term " installation ", " phase Even ", " connection " should be interpreted broadly, for example, it may be being fixedly connected or being detachably connected, or be integrally connected;Can To be mechanical connection or electrical connection;Can be joined directly together, can also be indirectly connected by intermediary, Ke Yishi The connection of two element internals.For the ordinary skill in the art, with concrete condition above-mentioned term can be understood at this Concrete meaning in invention.
If the function is realized in the form of SFU software functional unit and is used as independent production marketing or in use, can be with It is stored in a computer read/write memory medium.Based on such understanding, technical scheme is substantially in other words The part to be contributed to prior art or the part of the technical scheme can be embodied in the form of software product, the meter Calculation machine software product is stored in a storage medium, including some instructions are causing a computer equipment (can be People's computer, server, or network equipment etc.) perform all or part of step of each embodiment methods described of the present invention. And foregoing storage medium includes:USB flash disk, mobile hard disk, read-only storage (ROM, Read-Only Memory), arbitrary access are deposited Reservoir (RAM, Random Access Memory), magnetic disc or CD etc. are various can be with the medium of store program codes.
In the description of the invention, it is necessary to explanation, term " " center ", " on ", " under ", "left", "right", " vertical ", The orientation or position relationship of the instruction such as " level ", " interior ", " outer " be based on orientation shown in the drawings or position relationship, merely to Be easy to the description present invention and simplify description, rather than instruction or imply signified device or element must have specific orientation, With specific azimuth configuration and operation, therefore it is not considered as limiting the invention.
In addition, term " first ", " second ", " the 3rd " are only used for describing purpose, and it is not intended that instruction or implying phase To importance.
Finally it should be noted that:Embodiment described above, it is only the embodiment of the present invention, to illustrate the present invention Technical scheme, rather than its limitations, protection scope of the present invention is not limited thereto, although with reference to the foregoing embodiments to this hair It is bright to be described in detail, it will be understood by those within the art that:Any one skilled in the art The invention discloses technical scope in, it can still modify to the technical scheme described in previous embodiment or can be light Change is readily conceivable that, or equivalent substitution is carried out to which part technical characteristic;And these modifications, change or replacement, do not make The essence of appropriate technical solution departs from the spirit and scope of technical scheme of the embodiment of the present invention, should all cover the protection in the present invention Within the scope of.Therefore, protection scope of the present invention described should be defined by scope of the claims.

Claims (10)

  1. A kind of 1. storage method of text data, it is characterised in that including:
    Obtain the data to be stored in text data described in text data and current time;
    The number of characters of the data to be stored is read, and reads position of the data to be stored in the text data, The position includes:Line number or columns;
    The node corresponding with the position is searched in the binary tree data structure built in advance, and the number of characters is determined For the nodal value of the corresponding node, to be stored to the number of characters, wherein, the binary tree data structure is pressed in advance The storage order of node is defined according to the inorder traversal order of binary tree.
  2. 2. according to the method for claim 1, it is characterised in that the number of characters of the data to be stored is read, including:
    Count the number of characters of each position in the text data;
    According to the order of the position, the number of characters is ranked up, obtains character Number Sequence;
    The number of characters of data to be stored in text data described in current time is read from the character Number Sequence.
  3. 3. according to the method for claim 1, it is characterised in that lookup and institute in the binary tree data structure built in advance Rheme puts corresponding node, including:
    According to the storage order, first object node is searched from the binary tree data structure, and by the first object Node as the corresponding node, wherein, memory sequencing of the first object node in the binary tree data structure It is identical with sorting position of the position in the text data.
  4. 4. according to the method for claim 1, it is characterised in that store the number of characters into the corresponding node Afterwards, methods described also includes:
    The operational order that user sends is obtained, corresponding behaviour is performed to the binary tree data structure according to the operational order Make,
    Wherein, the operational order comprises at least one below:Change operational order, insertion operation instruction, deletion action instruction.
  5. 5. according to the method for claim 4, it is characterised in that according to the operational order to the binary tree data structure Corresponding operation is performed, including:
    The root node of the binary tree data structure is obtained, and the root node is defined as initial pending node, is held repeatedly Row following steps, until meet circulation stop condition,
    First comparison step, for will be compared in the number of nodes of the pending node at current time and target value, its In, the target value is line number of the target line of the pending operation in the text data and 1 difference;
    Second comparison step, the number of nodes for the pending node at current time are not less than the situation of the target value Under, by the number of nodes of the left sibling of the pending node at current time compared with the target value;
    First determines step, and the number of nodes for the left sibling of the pending node at current time is more than the target value In the case of, the pending node of subsequent time will be defined as in the left sibling of the pending node at current time;
    Second determines step, and the number of nodes for the left sibling of the pending node at current time is less than the target value In the case of, the pending node of subsequent time will be defined as in the right node of the pending node at current time, and pass through renewal Formula is updated to the target value, wherein, the more new formula is:ki=ki-1- (the pending node of subsequent time In left sibling number of nodes+1), kiFor the target value after renewal, ki-1For the target value before renewal;
    Return to step, for will be defined as in the pending node of subsequent time in current time pending node, and return to execution The comparison step, wherein, the subsequent time is the subsequent time at the current time, and the circulation stop condition is to work as The number of nodes of the left sibling of the pending node at preceding moment is less than the target value, wherein, ought after circulation terminates The pending node at preceding moment is defined as the second destination node, based on second destination node to the binary tree data structure Operated.
  6. 6. according to the method for claim 5, it is characterised in that in the case of the operational order is modification operational order,
    It is described that the binary tree data structure is operated based on second destination node, including:
    The target value carried in the modification operational order and modification number of characters are obtained, wherein, the modification number of characters For the number of characters after being modified to the target line;
    The nodal value of second destination node is replaced with into the modification number of characters.
  7. 7. according to the method for claim 5, it is characterised in that in the situation that the operational order is insertion operation instruction Under,
    It is described that the binary tree data structure is operated based on second destination node, including:
    The target value carried in the insertion operation instruction and insertion number of characters are obtained, wherein, the insertion number of characters For the number of characters of the text inserted before the target line,
    Nodal value in first positive node to be repaired is defined as to the nodal value of the second positive node to be repaired successively, and by the insertion word Symbol number is defined as the nodal value of second destination node;
    Wherein, the described second positive node to be repaired is next section of the first positive node to be repaired described in the binary tree data structure Point, first positive node to be repaired are second destination node, and are located in the storage order and second target Node after node.
  8. 8. according to the method for claim 5, it is characterised in that include the situation of deletion action instruction in the operational order Under,
    It is described that the binary tree data structure is operated based on second destination node, including:
    Obtain the target value carried in the deletion action instruction;
    Nodal value using the nodal value in the 3rd positive node to be repaired as the 4th positive node to be repaired successively, and by the binary tree number The nodal value performed according to last in structure in the node of storage operation empties, or, delete last described execution Store the node of operation;
    Wherein, the 3rd positive node to be repaired is the next node after the 4th positive node to be repaired, and the described 4th is to be repaired Positive node is second destination node, and be located in the storage order and second destination node after node.
  9. 9. according to the method for claim 1, it is characterised in that the number of characters is being defined as the corresponding node After nodal value, methods described also includes:
    The 3rd destination node is extracted, wherein, the 3rd destination node is any one section in the binary tree data structure Point;
    The nodal value sum of all nodes of subtree representated by the 3rd destination node is calculated, obtains the section of the 3rd destination node Point and, wherein, the 3rd destination node be the subtree root node;
    Corresponding storage is carried out by the node and with the 3rd destination node, obtains storage information, wherein, the storage information Character for the text data is positioned.
  10. A kind of 10. storage device of text data, it is characterised in that including:
    Acquisition module, for obtaining the data to be stored in text data described in text data and current time;
    Read module, for reading the number of characters of the data to be stored, and the data to be stored is read in the text Position in data, the position include:Line number or columns;
    Determining module, for searching the node corresponding with the position in the binary tree data structure built in advance, and will The number of characters is defined as the nodal value of the corresponding node, to be stored to the number of characters, wherein, the binary tree Data structure defines the storage order of node according to the inorder traversal order of binary tree in advance.
CN201710664232.0A 2017-08-04 2017-08-04 Text data storage method and device Active CN107463676B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710664232.0A CN107463676B (en) 2017-08-04 2017-08-04 Text data storage method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710664232.0A CN107463676B (en) 2017-08-04 2017-08-04 Text data storage method and device

Publications (2)

Publication Number Publication Date
CN107463676A true CN107463676A (en) 2017-12-12
CN107463676B CN107463676B (en) 2020-06-30

Family

ID=60548543

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710664232.0A Active CN107463676B (en) 2017-08-04 2017-08-04 Text data storage method and device

Country Status (1)

Country Link
CN (1) CN107463676B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108829872A (en) * 2018-06-22 2018-11-16 武汉轻工大学 Immediate processing method, equipment, system and the storage medium of lossless compression file
CN110032366A (en) * 2019-04-19 2019-07-19 北京奇艺世纪科技有限公司 A kind of Code location method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2011221845A (en) * 2010-04-12 2011-11-04 Fujitsu Ltd Text processing apparatus, text processing method and text processing program
CN102831121A (en) * 2011-06-15 2012-12-19 阿里巴巴集团控股有限公司 Method and system for extracting webpage information
CN104750834A (en) * 2015-04-03 2015-07-01 浪潮通信信息系统有限公司 Rule storage method and matching method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2011221845A (en) * 2010-04-12 2011-11-04 Fujitsu Ltd Text processing apparatus, text processing method and text processing program
CN102831121A (en) * 2011-06-15 2012-12-19 阿里巴巴集团控股有限公司 Method and system for extracting webpage information
CN104750834A (en) * 2015-04-03 2015-07-01 浪潮通信信息系统有限公司 Rule storage method and matching method and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108829872A (en) * 2018-06-22 2018-11-16 武汉轻工大学 Immediate processing method, equipment, system and the storage medium of lossless compression file
CN108829872B (en) * 2018-06-22 2021-03-09 武汉轻工大学 Method, device, system and storage medium for rapidly processing lossless compressed file
CN110032366A (en) * 2019-04-19 2019-07-19 北京奇艺世纪科技有限公司 A kind of Code location method and device
CN110032366B (en) * 2019-04-19 2022-07-22 北京奇艺世纪科技有限公司 Code positioning method and device

Also Published As

Publication number Publication date
CN107463676B (en) 2020-06-30

Similar Documents

Publication Publication Date Title
Chang et al. IEPAD: Information extraction based on pattern discovery
CN107220300B (en) Information mining method, electronic device and readable storage medium storing program for executing
JP4698738B2 (en) Multi-segment string search
US20120310630A1 (en) Tokenization platform
US20090063538A1 (en) Method for normalizing dynamic urls of web pages through hierarchical organization of urls from a web site
US20020021838A1 (en) Adaptively weighted, partitioned context edit distance string matching
CN108520002A (en) Data processing method, server and computer storage media
CN101464905A (en) Web page information extraction system and method
CN102867049B (en) Chinese PINYIN quick word segmentation method based on word search tree
CA2519179C (en) A computer implemented compact 0-complete tree dynamic storage structure and method of processing stored data
CN106469120A (en) Scrap cleaning method, device and equipment
CN105989015B (en) Database capacity expansion method and device and method and device for accessing database
He et al. Compact reachability labeling for graph-structured data
CN111507400B (en) Application classification method, device, electronic equipment and storage medium
CN107463676A (en) Text data store method and device
CN104424222A (en) Database indexing method and device
CN102725754B (en) Method and device for processing index data
CN108932350A (en) Based on shifty rice pest intelligent answer method
RU2433467C1 (en) Method of forming aggregated data structure and method of searching for data through aggregated data structure in data base management system
CN115269745B (en) Method, equipment and storage medium for mapping relational data to graph data
CN109684418A (en) Date storage method and device based on power grid chart database
CN108376054A (en) A kind of processing method and processing device that mark data is indexed
KR101067819B1 (en) Method and apparatus for document clustering using ontology
Zhang et al. Boilerplate detection via semantic classification of TextBlocks
CN111966686A (en) Product depth tracing method based on data association model

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
CB02 Change of applicant information

Address after: 310052 188 Lianhui street, Xixing street, Binjiang District, Hangzhou, Zhejiang Province

Applicant after: DBAPPSECURITY Ltd.

Address before: Zhejiang Zhongcai Building No. 68 Binjiang District road Hangzhou City, Zhejiang Province, the 310051 and 15 layer

Applicant before: DBAPPSECURITY Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant