Given a, b two files, each store 5 billion URLs, each URL occupies 64 bytes, memory limit is 4G, how to find a, b file common URL?

Source: Internet
Author: User
You can estimate the size of each file as 5g*64=300g, far greater than4G. So it is not possible to fully load it into memory for processing. Consider adopting a divide-and-conquer approach.
Traversing filesA, for eachURL FetchHash (URL)%1000, and then, based on the resulting value,URLs are stored separately in the1000 Small files (set toA0,A1,... a999). So the size of each small file is about300m. Traverse file b, take and a the same way url are stored in 1000 small Files Span lang= "en-us" > (b0,b1....b999). After this processing, all possibly the same url are in the corresponding small file (a0 vs B0, A1 vs b1....a999 vs b999), does not correspond to small files (such as a0 vs B99) cannot have the same url. Then we only ask out 1000 the same url in small files.
For example, a0 vs B0, we can traverse a0 to store url in hash_map. Then traverse b0, if url in hash_map, then this url in the Span lang= "en-us" >a and b exist simultaneously and are saved to a file.
If the small files are not evenly divided, resulting in some small files too large (for example, greater than 2g), you can consider these too large small files and then in a similar way into small files can be

Yesterday Baidu interviewer asked to study today

The above describes the given a, b two files, each store 5 billion URLs, each URL occupies 64 bytes, memory limit is 4G, how to find a, b file common URL? , including the aspects of the content, want to be interested in PHP tutorial friends helpful.

  • 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.