PostgreSQL中REPLACEMENT SELECTION SORT使用与哪种情况

57次阅读
没有评论

共计 1651 个字符,预计需要花费 5 分钟才能阅读完成。

本篇内容主要讲解“PostgreSQL 中 REPLACEMENT SELECTION SORT 使用与哪种情况”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“PostgreSQL 中 REPLACEMENT SELECTION SORT 使用与哪种情况”吧!

REPLACEMENT SELECTION SORT, 适用于内存较小的情况 (在高德纳提出该算法的年代, 内存比起现在少了 N 个数量级).
该算法在 PG 9.x 或以下版本在使用, 在高版本已被废弃. 其算法实现如下:

Let m be the number of records to be sorted which can be kept in the main memory. Imagine that these memory locations are registers and assume we can mark them as“on”or“off”. Replacement selection can overlap reading, sorting and writing.

Step1: The m registers are filled with records from the input to be sorted.
Step2: All registers are put into the “on” state.
Step3: Select the register which has the smallest of all “on” registers.
Step4: Transfer the contents of the selected register to the output (call it as key Y).
Step5: Replace the contents of the selected register by the next input record.
 If new record key   Y
 Go to step 3
 If new record key = =Y
 Go to step 4
 If new record key   Y
 Go to step 6
Step6: Turn the selected key register “off”.
 If all registers are now “off” We have completed a sorted substring(run).
 We start a new substring group and go to step 2.
 Else
 Go to step 3

下面是该算法的一个例子:

Example: Suppose number of registers is 3 and input keys are 5, 2, 9, 7, 0, 8, 1, 6, 3, 4 ...
 Registers Output
 5 2 9 2
 5 7 9 5
*0 7 9 7
*0 8 9 8
*0*1 9 9
*0*1*6
0 1 6 0
3 1 6 1
3 4 6 3
- 4 6 4
- - 6 6
- - -

相关的数据结构: 两个数组, 一个存储读取的实际数据, 一个标记数组; 一个外存, 用于存储已完成排序的一个 run.
如标记数组全为 F(非活动状态), 则产生一个 run, 周而复始, 直至所有输入被耗尽为止.
通过这个方法, 可以生成 N 个 runs(每个 run 对应的是已完成排序的部分数据).

CS 351 -Data Organization and Management (Section: 02)
External_sorting
replacement-selection-sort vs selection-sort

到此,相信大家对“PostgreSQL 中 REPLACEMENT SELECTION SORT 使用与哪种情况”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-24发表,共计1651字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)