IT科技

當前位置 /首頁/IT科技 > /列表

shuffle,java

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java shuffle是什麼?讓我們一起來了解一下吧!

java shuffle是java程序中的一種算法。Shuffle的意思是洗牌、混洗,把一些原本有規律規則的數據打亂變成沒有規矩的數據。

java shuffle

我們學習shuffle的具體流程之前,要先了解以下兩個概念:

1.block塊(物理劃分)

block是HDFS中的基本存儲單位,hadoop1.x默認大小為64M而hadoop2.x默認塊大小為128M。注意:當更改塊大小的配置後,新上載的文件的塊大小為新配置的值,以前上載的文件的塊大小為以前的配置值。

2.split分片(邏輯劃分)

Hadoop中split劃分屬於邏輯上的劃分,它的目的是為了讓map task更好地獲取數據。split是通過hadoop中的InputFormat接口中的getSplit()方法得到的。

java程序中shuffle算法的使用方法如下:

Fisher–Yates shuffle 基本思想(Knuth shuffle ): To shuffle an array a of n elements (indices 0..n-1): for i from n 1 downto 1 do j ← random integer with 0 ≤ j ≤ i exchange a[j] and a[i]

JDK源代碼如下:

/** * Moves every element of the List to a random new position in the list. * * @param list * the List to shuffle * * @throws UnsupportedOperationException * when replacing an element in the List is not supported */ public static void shuffle(List list) {undefined shuffle(list, new Random());

TAG標籤:shuffle java #