Find--Text Xiang Radixtree (radix tree)

Source: Internet
Author: User


Cardinality tree


Formapping of long-integer data, how to solve the hash conflict and hash table size design is a headache problem.
The radix tree is a fast and space-saving mapping for this sparse, long-integer data lookup. With the help of the radix tree, we canimplementing routing for long Integer data types。 using the radix tree, you can quickly find its corresponding object pointer based on a long integer type (such as a long ID)。 This is more simple than hash mapping, but also more space-saving, using hash mapping hash function is difficult to design, improper hash function may increase conflict, or waste space.

Radix tree is a kind of multi-fork search trees, the tree's leaf node is the actual data entry. Each node has a fixed, 2^n pointer to the sub-node (each pointer is called a slot slot,n the size of the base divided)


Insert, delete  

Radix tree (radix) is almost a traditional two-fork tree, just looking for ways to make use of each bit of a type such as a unsigned int as a tree node judgment.
It can be said that, for example, a number 1000101010101010010101010010101010, then follow the radix tree is inserted in the root node, if you encounter 0, point to the left node, if you encounter 1 point to the right node, during the insertion process to construct the tree node, Delete the tree node during the removal process. If you feel too many calls to malloc, you can use pooling techniques to pre-allocate multiple nodes.
(using a bit-bit judgment will make the height of the tree too high, too many non-leaf nodes.) Therefore, in the practical application, we generally use multiple bits as the tree node judgment, but multi-bit will make the node sub-node slot more, increase the volume of the node, generally choose 2 or 4 bits as a tree node can be)


Insert:

When we insert a new node, we look down in the tree based on the bits of the data, and if there is no corresponding node, the corresponding node is generated until the bits of the data are accessed, and the corresponding object is established for the leaf node mapping.

Delete:

We can "lazy delete", that is, after the path to find the leaf node, directly delete the leaf node, the middle of the non-leaf node is not deleted.


Application

Application of Radix tree in Linux:

The Linux cardinality tree (radix trees) is a mechanism that associates a long integer key value with a pointer, which is stored efficiently and can be queried quickly for integer values and pointers (such as the IDR mechanism), memory management, and so on.
IDR (ID Radix) mechanismis the object's identification number integer value ID and object Pointer Establish association tableTo complete the conversion from ID to pointer. The IDR mechanism uses the radix tree as a sparse array to index the pointer by ID, and the new ID,IDR mechanism can be quickly allocated by using bitmaps to avoid storing pointers using fixed-size arrays. The API functions of the IDR mechanism are implemented in LIB/IDR.C.
The most extensive use of Linux radix trees is to Memory Management, Structural Address_space binding to a core page on an address map through radix tree tracking, the radix tree allows memory management code to quickly find pages that are identified as dirty or writeback. It uses a fixed-length input version of the data type unsigned long. Each level represents the number of input space fixed digits. The API functions of the Linux radix tree are implemented in lib/radix-tree.c. (Map the page pointer and the structure that describes the state of the page so that you can quickly query the information for a page.) )

The Linux kernel uses the radix tree to quickly locate file cache pages by offsetting files within the file.
The fork in the Linux (2.6.7) kernel is 64 (2^6), the tree height is 6 (64-bit system) or 11 (32-bit system), which is used to quickly locate the 32-bit or 64-bit offsets, and each leaf node in the radix tree points to the cache entry corresponding to the corresponding offset within the file.

The radix tree provides efficient storage for sparse trees, instead of fixed-size arrays, which provide quick lookups of key values to pointers. 】

Postscript

radix tree and Trie tree thought a bit similar , can even see the trie tree as a base of 26 radix tree. (The radix tree can also be seen as a variation of the tire tree)
Trie trees are typically used for string-to-object mappings, and radix trees are typically used for long integer-to-object mappings.
Trie tree is the main problem is the height of the tree, if you want to index the word pinyin is very long and abnormal, we also want to build a very high and abnormal tree?
Radix tree can be fixed layer height (for longer strings, you can use mathematical formulas to calculate their eigenvalues, and then use the radix tree to store these eigenvalues)


"The relevant code can refer to "

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



----------------------------------Thank you for your visit and hope to help you. We welcome your attention, collection and comment. ----------------------------------



Find--Text Xiang Radixtree (radix tree)

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.