Disk file sequencing-programming Zhu Ji Nanxiong

Source: Internet
Author: User

Http://www.cnblogs.com/luxiaoxun/archive/2012/09/12/2681268.html

http://blog.csdn.net/wangkechuang/article/details/7906540

First, merge

1. Sort within
Because the required memory is 1MB, you can sort the 250K data in memory each time, and then write the ordered number to the hard disk.
Then 10M of data needs to loop 40 times, resulting in 40 sequential files.

2. Multi-Way Merge sort
(1) The first number of each file is read into (because of the order, so the minimum number of the file), stored in a size of 40 first_data array;
(2) Select the smallest number min_data in the First_data array, and its corresponding file index;
(3) writes the smallest number in the First_data array to the file result, and then updates the array first_data (the next number of the file is read by index instead of the min_data);
(4) Determine if all data is read, otherwise return (2).

Second, bitmap

Bitmap scheme. For example, as described in "Programming Zhu Ji Nanxiong", a 20-bit long bit string is used to represent a simple non-negative integer set of all elements that are less than 20, and the bounding box represents the collection {1,2,3,5,8,13} with the following string:
0 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0
The corresponding positions in the above set are placed at 1, and no corresponding number is placed at 0.

Referring to the bitmap scheme in the book "Programming Zhu Ji Nanxiong", the problem of disk file sorting for 10^7 data volumes can be considered, as each 7-bit decimal integer represents an integer less than 10 million. This file can be represented with a string of 10 million bits, where the I bit is 1 if and only if the integer i exists in the file. The scheme to take this bitmap is because we are faced with the particularity of this problem: 1, the input data is limited to a relatively small range, 2, the data is not duplicated, 3, each of which is a single positive integer, there is no other data associated with it.
Therefore, this problem is resolved in the following three steps with the bitmap scheme:
The first step is to set all the bits to 0, thereby initializing the collection to null.
The second step is to set up the collection by reading each integer in the file, setting each corresponding bit to 1.
The third step, check each bit, if the bit is 1, the output corresponding integer.

Disk file sequencing-programming Zhu Ji Nanxiong

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.