当前位置:懂科普 >

IT科技

> java shuffle

java shuffle

<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());

标签: shuffle java
  • 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/itkeji/nmgyyg.html