[Go to] search-Fig radixtree (base tree)

Source: Internet
Author: User

This article from: http://blog.csdn.net/yang_yulei/article/details/46371975

Base tree

 

For long integer data ing, how to solve hash conflicts and hash table size design is a headache.
The radix tree is used to search for this sparse long integer data, which can complete ing quickly and efficiently. With the help of the radix tree, we can implement routing for long integer data types. Using the radix tree, you can quickly find the corresponding object pointer based on a long integer (such as a long ID ).. This is simpler than hash ing, which also saves space. It is difficult to design hash functions using hash ing. Improper hash functions may increase conflicts or waste space.

Radix tree is a multi-cross search tree, and the leaf node of the tree is the actual data entry. Each node has a fixed 2 ^ n pointer pointing to the sub-node (each pointer is called a slot, and N is the size of the divided base)

 

 

Insert and delete

 

Radix tree (base tree) is almost a traditional binary tree. It uses every bit of the unsigned int type as the decision of the Tree node in the way of searching.
It can be said that, for example, if the number is 1000101010101010010101010010101010, the data inserted according to the radix tree is in the root node. If 0 is encountered, the data is directed to the left node. If 1 is encountered, the data is directed to the right node, create a tree node during the insertion process and delete the tree node during the deletion process. If you think there are too many calls to malloc, you can use Pooling technology to pre-allocate multiple nodes.
(Using a bit for determination will make the height of the tree too high and there will be too many non-leaf nodes. Therefore, in practical application, we generally use multiple bits as the decision tree node, but multiple bits will increase the sub-node slots of nodes and increase the node volume, generally, two or four bits are used as Tree nodes)

 

Insert:

When we insert a new node, we look down in the tree based on the bit of the data. If there is no corresponding node, the corresponding node is generated until the bit of the data is accessed, the corresponding object is mapped to the leaf node.

Delete:

We can "Delete the leaf node with inertia", that is, after finding the leaf node along the path, we can directly Delete the leaf node without deleting the non-leaf node in the middle.

 

Application

 

Applications of the radix tree in Linux:

The Linux base tree (Radix tree) is a mechanism that associates long integer values with pointers. It is efficient in storage and can be quickly queried for ing between integer values and pointers (for example: IDR mechanism), memory management, etc.
IDR (ID Radix) MechanismIs the object ID of the integral value of ID and Object PointerTo complete the conversion between IDs and pointers. The IDR mechanism uses the radix tree structure as a sparse array for retrieving pointers by ID indexing. Bitmap can be used to quickly allocate new IDs. The IDR mechanism avoids using fixed-size arrays to store pointers. The API functions of the IDR mechanism are implemented in lib/IDR. C.
Linux Radix tree is the most widely used Memory Management, Address_space Track core pages bound to address ing through the radix treeThe radix tree allows the memory management code to quickly find pages marked as dirty or writeback. It uses the fixed-length input version of the Data Type unsigned long. Each level represents a fixed number of digits in the input space. Linux Radix tree API functions are implemented in lib/radix-tree.c. (Map the structure of the page pointer and description page status to quickly query the information of a page .)

The Linux kernel uses the radix tree to quickly locate the File Cache page in the file offset.
In Linux (2.6.7), the split is 64 (2 ^ 6), and the tree height is 6 (64-bit system) or 11 (32-bit system ), it is used to quickly locate the 32-bit or 64-bit offset. Each leaf node in the radix tree points to the cache item corresponding to the corresponding offset in the file.

[The radix tree provides effective storage for sparse trees. Instead of fixed-size arrays, it provides a quick search for key-value-to-pointer pairs .]

 

Postscript

The idea of a radix tree is similar to that of a trie tree. You can even think of a trie tree as a radix tree with a base of 26. (You can also think of the radix tree as the variation of the tire tree)
The trie tree is used to map strings to objects. The radix tree is used to map long integers to objects.
The main problem with the trie tree is the tree height. If the pinyin text to be indexed is very long and abnormal, should we also build a very high and abnormal tree?
The radix tree can fix the layer height (for long strings, the feature values can be calculated using mathematical formulas and stored in the radix tree)

 

For more information about the code, see]

Http://www.cnblogs.com/Bozh/archive/2012/04/15/radix.html

[Go to] search-Fig radixtree (base tree)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.