Php Data Structure hash table

Source: Internet
Author: User
This data structure contains an integer Variable n (indicating the number of current elements) and two arrays members and position. The former is used to store the elements in the current set, and the latter is an array with a length of N, used to record the position of each number in the members array (in other words, members [position [I] I is always true ). To query whether m is in the current status

This data structure contains an integer Variable n (indicating the number of current elements) and two arrays members and position. The former is used to store the elements in the current set, and the latter is an array with a length of N, used to record the position of each number in the members array (in other words, members [position [I] = I is always true ). To query whether m is in the current status

This data structure contains an integer Variable n (indicating the number of current elements) and two arrays members and position. The former is used to store the elements in the current set, and the latter is an array with a length of N, used to record the position of each number in the members array (in other words, members [position [I] = I is always true ).

To query whether m is in the current set, you only need to check whether position [m] is in the range of 0 to n-1, and whether members [position [m] is indeed equal to m. To add an element, you only need to put the new element into members [n ++] and update the corresponding position data. To delete an element, you only need to move it to the end of the members Queue (change the nth Number of the element and the members array), update the corresponding position data, and then subtract n. To clear a set, you only need to make n equal to 0. The traversal element only needs to scan the currently valid section in the members array, which is obviously O (n. Variable n is the number of elements. If you need to query the number of elements, return n directly.

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.