CN109885840A - The dictionary sort method of space optimization is realized by 16 Trie trees - Google Patents
The dictionary sort method of space optimization is realized by 16 Trie trees Download PDFInfo
- Publication number
- CN109885840A CN109885840A CN201910165993.0A CN201910165993A CN109885840A CN 109885840 A CN109885840 A CN 109885840A CN 201910165993 A CN201910165993 A CN 201910165993A CN 109885840 A CN109885840 A CN 109885840A
- Authority
- CN
- China
- Prior art keywords
- node
- chain
- dictionary
- pointer
- class
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 29
- 238000005457 optimization Methods 0.000 title claims abstract description 11
- 238000003780 insertion Methods 0.000 claims abstract description 20
- 230000037431 insertion Effects 0.000 claims abstract description 20
- 229920003266 Leaf® Polymers 0.000 claims description 21
- 239000011800 void material Substances 0.000 claims 2
- 238000010276 construction Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 230000002123 temporal effect Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Abstract
The present invention provides a kind of dictionary sort method that space optimization is realized by 16 Trie trees, method includes the following steps: the empty Trie tree of creation and empty sequence chained list;Keyword is sequentially inserted into;Not only it had generated Trie tree but also had completed dictionary sequence.The case where this dictionary algorithm is in tree-like, and each node uses 16 (bit) expression child nodes, therefore it is named as 16 dictionary tree algorithms.When generating the dictionary of 16 Trie trees, one keyword key of every insertion is created that a chain node, while being orderly inserted into according to its keyword key to chained list.In addition, compared with quick sorting algorithm, 16 Trie tree dictionary sort algorithms can carry out dynamic order at any time, and the sequence of dictionary can be completed while building, it allows unordered data to combine the data combination for becoming orderly, additional sorting time is greatly saved.
Description
Technical field
The invention belongs to data structures and information retrieval field, more particularly to one kind to realize that spaces are excellent by 16 Trie trees
The dictionary sort method of change.
Background technique
Sequence is a kind of operation to data processing, and the purpose is to the records series of one group " unordered " are adjusted to " orderly "
Records series.In recent years, a large amount of universal with Intelligent mobile equipment With the fast development of internet, especially big data when
The arrival in generation, since network information is excessively huge, search result information is excessive, and useful information is not complete, and search result lacks a
Property, in information retrieval field, how preferably to retrieve the information to match with user search request is a worth research
The problem of.In general, searching system is often arranged using certain sort algorithm pair information relevant to user search request
Sequence.16 Trie tree dictionary sort algorithms are a kind of sort algorithms carried out on 16 Trie tree constructions, its main feature is that into
Dictionary sequence is completed while 16 Trie tree buildings of row.
Quick sorting algorithm is the modified version of bubble sort, is sort method most fast at present.Quicksort and 16
Trie tree dictionary sort algorithm is compared, slightly slow first on the time, and cannot handle frequent update, and more new sort is all each time
It needs to redistribute memory headroom to be ranked up, causes temporal waste, second, 16 Trie tree dictionary sort algorithms are not
Need data mobile, insertion is ordered into, and the mobile problem of data, compared with Insertion Sorting Algorithm, 16 is substantially absent
Trie tree dictionary sort algorithm does not need lookup mass data and determines insertion position, but closes on effective node by Trie tree
The position of sequence insertion can be read, therefore, the algorithm is even better in time.
Compared with quick sorting algorithm, 16 Trie tree dictionary sort algorithms can carry out dynamic order at any time, and in structure
The sequence that dictionary can be completed while building allows unordered data to combine the data combination for becoming orderly, volume is greatly saved
Outer sorting time.
Summary of the invention
In order to solve the above technical problem, the present invention provides a kind of dictionary rows that space optimization is realized by 16 Trie trees
Sequence method, method includes the following steps: the empty Trie tree of creation and empty sequence chained list;Keyword is sequentially inserted into;Both it generated
Tire tree completes dictionary sequence again.This dictionary algorithm is in tree-like, and each node indicates child nodes using 16 (bit)
Situation, therefore it is named as 16 dictionary tree algorithms.When generating the dictionary of 16 Trie trees, one keyword key of every insertion is just created
A chain node is built, while chained list is orderly inserted into according to its keyword key.In addition, being compared with quick sorting algorithm, 16
Position Trie tree dictionary sort algorithm can carry out dynamic order at any time, and the sequence of dictionary can be completed while building,
It allows unordered data to combine the data combination for becoming orderly, additional sorting time is greatly saved.
For this purpose, the embodiment of the invention discloses a kind of dictionary sort methods for realizing space optimization by 16 Trie trees.
Method includes the following steps: the empty Trie tree of creation and empty sequence chained list;Keyword key is sequentially inserted into;Both Tire is generated
Tree completes dictionary sequence again.
Preferably, using class bitNode as node class in the dictionary data of 16 Trie trees, with class LinkList
As chain node class, using class bitIndex as management class.
Preferably, root node, only a root node are indicated in the class bitIndex with root.
Preferably, the currently stored child node pointer of leafs array representation of the node in 16 Trie trees and
Chain node pointer, child nodes pointer are directed toward child node corresponding to present node, and chain node pointer is directed toward present node institute
Corresponding chain node, child node be not present and chain node pointer also in the absence of, leafs element number be 0, child node
In the presence of, leafs element number is child node quantity+1 (wherein chain node pointer occupies an element).
Preferably, whether the node is that effective node is indicated with hasData, and 0 is expressed as non-effective node, and 1 is expressed as
Effective node.
Preferably, it is described index the following steps are included:
A. empty Trie tree and empty sequence chained list are created;
B. the value of the first character section of keyword key is got, and obtains the high 4 place value high_4bits of the byte, by working as
Front nodal point inquiry indicates that the child node of high 4 nodal values whether there is, if corresponding child node exists, obtains high 4 nodes,
And continue in kind to inquire low 4 nodes of the byte, it is otherwise inserted into new node pBitNode, until keyword key is all
Until byte is inserted into;
C. when carrying out new node pBitNode insertion, while the section for meeting following two condition is marked with variable ParentNode
Point is denoted as father node: the node is effective node (hasData=1) on branch, or there are two the above sons on the branch
The father node of node (including two);
D. when keyword key completes the insertion of the last one node, which is denoted as pNewNode, passes through the father node of label
ParentNode and present node pNewNode obtains the effective node nearest apart from present node, if effectively node is deposited recently for this
The chain node pointer in effective node leafs array is then being obtained, pListNode chain node is denoted as, is creating a chain link
Point is inserted into newly-built chain node before or after pListNode chain node, while in the leafs of present node pNewNode
Newly-built chain node pointer (facilitating the chain node location for positioning effective node) is stored in array;
If e. the nearest effectively node is not present, a chain node is created, is inserted into after the chained list head node pHead that sorts new
The chain node built, while newly-built chain node pointer is stored in the leafs array of present node pNewNode;
Preferably, the sequence are as follows: the chain of generation is its all keyword key corresponding ranking results from small to large.
The present invention provides a kind of dictionary sort method that space optimization is realized by 16 Trie trees, and this method includes following
Step: empty Trie tree and empty sequence chained list are created;Keyword is sequentially inserted into;Not only it had generated Tire tree but also had completed dictionary row
Sequence.The case where this dictionary algorithm is in tree-like, and each node uses 16 (bit) expression child nodes, therefore it is named as 16
Dictionary tree algorithm.When generating the dictionary of 16 Trie trees, one keyword key of every insertion is created that a chain node, while root
Chained list is orderly inserted into according to its keyword key.In addition, comparing with quick sorting algorithm, 16 Trie tree dictionary sequences are calculated
Method can carry out dynamic order at any time, and the sequence of dictionary can be completed while building, allow unordered data to combine and become
It is combined at orderly data, additional sorting time is greatly saved.
It should be appreciated that the above general description and following detailed description are all illustrative and exemplaries, it is desirable to provide to institute
It is required that further explanation of the invention.
Detailed description of the invention
Fig. 1 is the module map that the embodiment of the present invention realizes sequence according to the current state of keyword key.
Fig. 2 is the structural map of dictionary data Trie tree in the embodiment of the present invention.
Fig. 3 is the sequence chained list figure of dictionary data Trie tree in the embodiment of the present invention.
Fig. 4 is the flow chart for the dictionary sort method that the embodiment of the present invention realizes space optimization by 16 Trie trees.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right
The present invention is described in further detail.It should be appreciated that the specific embodiment of description described herein is used only for explaining this hair
It is bright, it is not intended to limit the present invention.
The dictionary sort method provided in an embodiment of the present invention that space optimization is realized by 16 Trie trees.
As shown in Figure 1, being the mould for the dictionary sort method that the embodiment of the present invention realizes space optimization by 16 Trie trees
Block figure.
Step S110: creating empty Trie tree (root node root), creates empty sequence chained list (pHead-pRear).
It is inserted into keyword key, such as: to be inserted into following keyword: de, fg, ab, yf, a, dec, dea, ta, fc, fy.
Step S120: keyword is sequentially inserted into.
As shown in Fig. 2, being the final building result of 16 Trie trees.According to the key data in upper example, these words it
Between there is some common prefixes (i.e. identical father node), a dictionary tree, the knot of tree can be formed according to these prefixes
Point does as described below:
Circle of dotted line represents non-effective node (i.e. node hasData=0);
Solid line circle represents effective node (i.e. node hasData=1) of tree;
It is a complete entry in dictionary from the root root node of tree to the word that the currently active node is constituted;
Indicate whether present node is effective node with hasData in node, 0 is expressed as non-effective node, and 1 indicates to be effectively to save
Point.
Step S121: the building of above 16 Trie trees includes the following steps.
Step S122: with root node root building keyword for " the 16 of de, fg, ab, yf, a, dec, dea, ta, fc, fy "
Position Trie tree chained list.
Step S123: the first character section ' d ' of first keyword " de " is obtained, and obtains high 4 place value 6 of ' d ', is passed through
Root node inquiry indicates that nodal value is that 6 child node whether there is, and if it exists, then obtains high 4 nodes of ' d ';If it does not exist,
High 4 nodes of ' d ' are then inserted into, if root node is effective node or there are two father's sections of the above child node (comprising two)
Point is then marked with variable ParentNode, then by high 4 nodes of ' d ' as root node, similarly inquires low 4 of ' d '
Node, until the insertion of keyword " de " all bytes.
Step 123 pseudocode is as follows:
while (uKeyLen--)
{
pPNode = pNewNode;// Gao Siwei
pNewNode = pNewNode->AddChildNode((*pchKey) >> 4);
// label father node
if (pPNode->LeafsCount() > 1 || pPNode->mbHasData)
Effective nodal value under { // label father node
pParentNode = pPNode;
pVaildNodeValue = ((*pchKey) >> 4);
}
pPNode = pNewNode;// four low
pNewNode = pNewNode->AddChildNode((*pchKey) & 0x0F);
// label father node
if (pPNode->LeafsCount() > 1 || pPNode->mbHasData)
{
pParentNode = pPNode;
pVaildNodeValue = ((*pchKey) & 0x0F);
}
pNewNode->mbIsEndNode = true;
pchKey++;
}。
Step S125: when keyword " de " completes low four nodes insertion of ' e ', low four nodes for being somebody's turn to do ' e ' are denoted as
PNewNode1 judges that the nearest effective node of distance pNewNode1 is not present according to pNewNode1 and father node, then creates one
A chain node ListNode (de), in head node pHead followed by insertion, while in the leafs array of pNewNode1 node
The newly-built chain node pointer of upper storage (facilitates positioning chain node location);
Current sequence chained list are as follows: pHead-ListNode (de)-pRear.
Step S126: continuing into second keyword " fg " in example, when " fg " completes low four nodes insertion of ' g '
When, low four nodes for being somebody's turn to do ' g ' are denoted as pNewNode2, judge that distance pNewNode2 is nearest according to pNewNode2 and father node
Effective node be pNewNode1, judge that pNewNode1 ratio pNewNode2 nodal value is small, then take pNewNode1 node
ListNode (de) chain node pointer in leafs array creates a chain node ListNode (fg), at ListNode (de)
It is inserted into newly-built chain node after chain node, while storing newly-built chain node pointer in the leafs array of pNewNode2;
Current sequence chained list are as follows: pHead-ListNode (de)-ListNode (fg)-pRear.
Step 125 pseudocode is as follows:
(there is nearest effective node) in if
{
If (effectively node is after present node recently)
{
The chain node pointer in the leafs array of effective node recently is read,
Remember pMaxListNode node;
The newly-built chain node of insertion is carried out before pMaxListNode node;
Newly-built chain node pointer is saved in the leafs array of present node;
}
Else // nearest effectively node is before present node
{
The chain node pointer in the leafs array of effective node recently is read,
Remember pMinListNode node;
The newly-built chain node of insertion is carried out after pMinListNode node;
Newly-built chain node pointer is saved in the leafs array of present node;
}
}
Else // nearest effectively node is not present
{
Newly-built chain node is inserted directly into after head node;
Newly-built chain node pointer is saved in the leafs array of present node;
}。
The third keyword " ab " in example is continued into, steps be repeated alternatively until whole keyword insertions in example
Until;
Final chained list ranking results are as follows: pHead-ListNode (a)-ListNode (ab)-ListNode (de)-
ListNode(dea)-ListNode(dec)-ListNode(fc)-ListNode(fg)-ListNode(fy)-ListNode
(ta)-ListNode(yf)-pRear。
Step S130: not only having generated Tire tree but also completes dictionary sequence;
The sequence chained list of generation is as shown in figure 3, be all keyword key corresponding ranking results from small to large.
According to the above-mentioned specific descriptions to the embodiment of the present invention, it is clearly understood that providing according to the present invention a kind of logical
The dictionary sort method that 16 Trie trees realize space optimization is crossed, method includes the following steps: Trie tree and sky that creation is empty
Sequence chained list;Keyword is sequentially inserted into;Not only it had generated Tire tree but also had completed dictionary sequence.This dictionary algorithm is in tree-like, and
Each node uses the case where 16 (bit) expression child nodes, therefore is named as 16 dictionary tree algorithms.Generate 16 Trie trees
Dictionary when, one keyword key of every insertion is created that a chain node, while being had according to its keyword key to chained list
Sequence insertion, in addition, comparing with quick sorting algorithm, 16 Trie tree dictionary sort algorithms can carry out dynamic order at any time, and
The sequence that dictionary can be completed while building allows unordered data to combine the data combination for becoming orderly, greatlys save
Additional sorting time.
Claims (10)
1. the dictionary sort method of space optimization is realized by 16 Trie trees, it is characterized in that carrying out in accordance with the following steps:
Create empty Trie tree and empty sequence chained list;
Keyword key is sequentially inserted into;
Not only it had generated Tire tree but also had completed dictionary sequence.
2. the method according to claim 1, wherein with class in the dictionary data of 16 Trie trees
BitNode is as node class, using class LinkList as chain node class, using class bitIndex as management class.
3. according to claim 1 or method as claimed in claim 2, which is characterized in that publicly-owned data member packet in class bitNode
All information containing node, wherein key data information has:
LeafsInfo: child list information;
NodeValue: value representated by present node;
HasData: whether present node is effective node;
Endkey: whether present node is terminal node;
Leafs: child node pointer and chain node pointer are saved.
4. according to claim 1 or method as claimed in claim 2, which is characterized in that private data member in class LinkList
Information comprising chain node, wherein key data information has:
Node* pHead;// head node
Node* pRear;// tail node.
5. according to the method described in claim 4, it is characterized in that, the Node node type in class LinkList is customized
The member data information of structural body, structural body has:
typedef struct Node
{
void* mpData;The corresponding data of // storage keyword key;
void* mpKey;// storage keyword key;
int mCount;// record current chain number of nodes
Node* pNext;// lookup chain node is subsequent;
Node* pPrive;// search chain node forerunner;
}。
6. according to claim 1 or method for claim 2, which is characterized in that indicate root section in class bitIndex with root
Point, one and only one root node.
7. according to claim 1 or method as claimed in claim 3, which is characterized in that the node in 16 Trie trees is used
Leafs array representation currently stored child node pointer and chain node pointer, child nodes pointer are directed toward present node institute
Corresponding child node, chain node pointer are directed toward chain node corresponding to present node, and child node is not present and chain node refers to
Needle also in the absence of, leafs element number be 0, in the presence of chain node, leafs element number be child node quantity+1 (wherein
Chain node pointer occupies an element).
8. according to claim 1 or method as claimed in claim 3, which is characterized in that whether the node is that effective node is used
HasData indicates that 0 is expressed as non-effective node, and 1 is expressed as effective node.
9. the method according to claim 1, which is characterized in that it is described sequence the following steps are included:
A. empty Trie tree and empty sequence chained list are created;
B. the value of the first character section of keyword key is got, and obtains the high 4 place value high_4bits of the byte, by working as
Front nodal point inquiry indicates that the child node of high 4 nodal values whether there is, if corresponding child node exists, obtains high 4 nodes,
And continue in kind to inquire low 4 nodes of the byte, it is otherwise inserted into new node pBitNode, until keyword key is all
Until byte is inserted into;
C. when carrying out new node pBitNode insertion, while the section for meeting following two condition is marked with variable ParentNode
Point is denoted as father node: the node is effective node (hasData=1) on branch, or there are two the above sons on the branch
The father node of node (including two);
D. when keyword key completes the insertion of the last one node, which is denoted as pNewNode, passes through the father node of label
ParentNode and present node pNewNode obtains the effective node nearest apart from present node, if effectively node is deposited recently for this
The chain node pointer in effective node leafs array is then being obtained, pListNode chain node is denoted as, is creating a chain link
Point is inserted into newly-built chain node before or after pListNode chain node, while in the leafs of present node pNewNode
Newly-built chain node pointer (facilitating the chain node location for positioning effective node) is stored in array;
If e. the nearest effectively node is not present, a chain node is created, is inserted into after the chained list head node pHead that sorts new
The chain node built, while newly-built chain node pointer is stored in the leafs array of present node pNewNode.
10. according to claim 1 or method described in claim 11, which is characterized in that the sequence are as follows: the chain of generation is it
All keyword key corresponding ranking results from small to large.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910165993.0A CN109885840A (en) | 2019-03-06 | 2019-03-06 | The dictionary sort method of space optimization is realized by 16 Trie trees |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910165993.0A CN109885840A (en) | 2019-03-06 | 2019-03-06 | The dictionary sort method of space optimization is realized by 16 Trie trees |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109885840A true CN109885840A (en) | 2019-06-14 |
Family
ID=66930799
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910165993.0A Pending CN109885840A (en) | 2019-03-06 | 2019-03-06 | The dictionary sort method of space optimization is realized by 16 Trie trees |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109885840A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110569399A (en) * | 2019-11-07 | 2019-12-13 | 四川新网银行股份有限公司 | Link construction method based on pinpoint log |
-
2019
- 2019-03-06 CN CN201910165993.0A patent/CN109885840A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110569399A (en) * | 2019-11-07 | 2019-12-13 | 四川新网银行股份有限公司 | Link construction method based on pinpoint log |
CN110569399B (en) * | 2019-11-07 | 2020-03-06 | 四川新网银行股份有限公司 | Link construction method based on pinpoint log |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US5930805A (en) | Storage and retrieval of ordered sets of keys in a compact 0-complete tree | |
US8849876B2 (en) | Methods and apparatuses to optimize updates in a file system based on birth time | |
CN111190904B (en) | Method and device for hybrid storage of graph-relational database | |
US7526497B2 (en) | Database retrieval apparatus, retrieval method, storage medium, and program | |
US20040088307A1 (en) | Data structure for information systems | |
CN109471905B (en) | Block chain indexing method supporting time range and attribute range compound query | |
US20090327218A1 (en) | Systems and Methods of Reverse Lookup | |
US20060026138A1 (en) | Real-time indexes | |
JP2002501256A (en) | Database device | |
CN108197313B (en) | Dictionary indexing method for realizing space optimization through 16-bit Trie tree | |
AU2002249161A1 (en) | Data structure for information systems | |
CN111581215B (en) | Array tree data storage method, fast search method and readable storage medium | |
CN100565508C (en) | Structured-document management apparatus, search equipment, storage and searching method | |
CN103051543A (en) | Route prefix processing, lookup, adding and deleting method | |
CN100511229C (en) | Domain name information storage and inquiring method and system | |
US8493249B2 (en) | Compression match enumeration | |
CN109597829B (en) | Middleware method for realizing searchable encryption relational database cache | |
US20110029478A1 (en) | Stream Star Schema and Nested Binary Tree for Data Stream Analysis | |
CN114064984A (en) | Sparse array linked list-based world state increment updating method and device | |
CN108153907B (en) | Dictionary storage management method for realizing space optimization through 16-bit Trie tree | |
CN109885840A (en) | The dictionary sort method of space optimization is realized by 16 Trie trees | |
CN110995876B (en) | Method and device for storing and searching IP | |
US20030084031A1 (en) | System and method for searching a signature set for a target signature | |
Lin et al. | A multi-index hybrid trie for lookup and updates | |
KR101342560B1 (en) | Mobile Database System for Navigation and Method Therefor |
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 | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20190614 |