In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "exploring the implementation principle of database". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The idea of merge join is similar to that of merge sorting, as detailed in the code notes.
# include # include "merge_sort.h" / * array: array to be processed low: low middle: middle high: high * / void merge_array (int array [], int low,int middle,int high) {/ / the size of the left array (middle in the left array, plus 1) int N1 = middle-low + 1; / / the size of the right array int N2 = high-middle / / printf ("- merge_array: low =% d merge_array high =% d.\ n", low,high,middle); / / initialize the left and right side array int left [N1], right [N2]; for (int I = 0bot I)
< n1;i++) left[i] = array[low+i]; for(int i = 0;i < n2;i++) right[i] = array[middle+i+1]; //归并 int i=0,j=0,k=low; //同时遍历左右两边数组,较小值进入到结果数组中(回填) for(;i < n1 && j < n2;) if(left[i] < right[j]) array[k++] = left[i++]; else array[k++] = right[j++]; //处理数组中剩余的其他元素 while(i < n1) array[k++] = left[i++]; while(j < n2) array[k++] = right[j++]; // printf("--- merge_array : ---\n"); // print_array(array+low,n1 + n2);}/*array : 待处理的数组low : 低位high : 高位*/void merge_arraybyrange(int array[],int low,int high){ if (low >= high) return;// low position is greater than or equal to the high value, exit / / take the middle position int middle = (low + high) / 2; / / printf ("- merge_sort: low =% d.\ n", low,high,middle); / / sort the left array by merge_arraybyrange (array,low,middle); / / sort the right array by merge_arraybyrange (array,middle+1,high) / / after sorting the arrays on both sides, merge the arrays on both sides merge_array (array,low,middle,high); / / printf ("- merge_sort: -\ n"); / / print_array (array+low,high-low + 1);} / * Recursive call method array: array to be processed low: low order high: high bit * / void merge_sort_recursion (array * tmparr) {int low = 0; int high = tmparr- > counter-1 Merge_arraybyrange (tmparr- > arr,low,high);} / * non-recursive invocation method: array c: sorted array c: result array * / void merge_twoarrays2one (array * a _ array * b ~ * array * c) {int iMago _ counter=-1; for _ 0; c-> array
< a->Counter & & j
< b->Counter;) {/ / merge sort. If any array ends, the loop ends if (a-> arr [I]
< b->Arr [j]) {c-> arr [+ + c-> counter] = a-> arr [iTunes +];} else {c-> arr [+ + c-> counter] = b-> arr [jacks +];}} / / processes the rest of the data while (I
< a->Counter) {c-> arr [+ + c-> counter] = a-> arr [iTunes +];} while (j)
< b->Counter) {c-> arr [+ + c-> counter] = b-> arr [jacks +];} / / count from 0, counter+1 c-> counter++;} / * tmparr: array structure to be sorted * / void merge_sort (array * tmparr) {/ / temporary array int TMP [tmparr-> counter]; / / temporary array (cache) array buffer; buffer.arr = tmp; for (int item1iti)
< tmparr->Counter;i=i*2) {/ / I = number of comparisons = 2 ^ x = 1, 2, 2, 2, 4, and 8. For (int juni0witj
< tmparr->Counter;j+=i*2) {/ / j = comparison starting position, the number of if (Jaimi > = tmparr- > counter) break; array arr1,arr2; / / points to the position of comparison (array 1) arr1.arr = tmparr- > arr+j; arr1.counter = I; / / points to the position of comparison (array 2) arr2.arr = tmparr- > arr+j+i; arr2.counter = I / / the number of array 2, so as not to cross the boundary if (j+i*2 > = tmparr- > counter) arr2.counter = tmparr- > counter-(jigi); / / merge array 1q2 merge_twoarrays2one (& arr1,&arr2,&buffer); / / printf ("- I =% d _ Magi j =% d _ counter =% d\ n", I _ jjjj _ buffer.counter) / / print_array (buffer.arr,buffer.counter); / / copy the merged data to tmparr memcpy (tmparr- > arr+j,buffer.arr,buffer.counter*sizeof (int));} / / printf ("- I =% d\ n", I); / / print_array (tmparr- > arr,tmparr- > counter);}}
Running output
Ethanhe@DESKTOP-V73MH70 / is 21item is 30item is 30item [6] is 99item [7] is 100item [8] is 200item [9] is 301item [10] is 400-test_merge by recursion-- -item [0] is 1item [1] is 5item [2] is 10item [3] is 21item [4] is 30item [5] is 40item [6] is 99item [7] is 100item [8] is 200item [9] is 301item [10] is 400 "exploring the implementation principle of Database" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.