User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
algorithm:fisher-yates_shuffle [2013/04/22 19:57]
will
algorithm:fisher-yates_shuffle [2015/02/02 08:28] (current)
Line 1: Line 1:
-[algorithm ​Fisher-Yates shuffle]+======= λ Fisher-Yates shuffle ​======
  
-====== Algorithm ======+<​nowiki>​ 
 +======= Algorithm ​=======
 <syntax js> <syntax js>
 function shuffle(a) { function shuffle(a) {
Line 13: Line 14:
 </​syntax>​ </​syntax>​
  
-====== Support ======+======= Support ​=======
 <syntax js> <syntax js>
 function swap(a, i, j) { function swap(a, i, j) {
Line 23: Line 24:
 </​syntax>​ </​syntax>​
  
-====== Visualisation ======+======= Tests ======= 
 +<syntax js> 
 +</​syntax>​ 
 + 
 +======= Options ======= 
 +<syntax js> 
 +
 +    "​title":"​Fisher-Yates shuffle",​ 
 +    "​height":"​270px"​ 
 +
 +</​syntax>​ 
 + 
 +======= Visualisation ​=======
 <syntax html> <syntax html>
 <​html>​ <​html>​
Line 65: Line 78:
 } }
  
-function args() { +function args(forCloning) { 
-    return a;+    ​if (forCloning) { 
 +        var a2 = []; 
 +        for (var i=0, c=a.length; i<c; i++) { 
 +            a2.push(a[i].data);​ 
 +        } 
 +        return a2; 
 +    } 
 +    else { 
 +        ​return a; 
 +    }
 } }
  
-function update(n, x, duration) {+function update(n, x, isRunning, duration) {
     if (duration < 0) {     if (duration < 0) {
         return; // State-less visualisation.         return; // State-less visualisation.
Line 80: Line 102:
     }     }
 } }
- 
-var oldI; 
  
 function drawGraph(a,​ idx, idx2, duration) { function drawGraph(a,​ idx, idx2, duration) {
Line 97: Line 117:
     bars.transition().duration(duration).attr("​x",​ function(d, i) { return barSpacing*i;​ });     bars.transition().duration(duration).attr("​x",​ function(d, i) { return barSpacing*i;​ });
     ​     ​
-    ​if (idx2 < idx) { +    bars.classed("​index", function(d, i) {return i===idx || i===idx2});
-        ​bars.classed("​index2", function(d, i) {return i===idx2}); +
-        bars.classed("​index",​ function(d, i) {return ​i===idx}); +
-    }+
 } }
 </​script>​ </​script>​
 </​head>​ </​head>​
-<​body ​style="​height:​270px"​>+<​body>​
 <div id="​chart"></​div>​ <div id="​chart"></​div>​
 </​body>​ </​body>​
 </​html>​ </​html>​
 </​syntax>​ </​syntax>​
 +</​nowiki>​
algorithm/fisher-yates_shuffle.1366685860.txt.gz · Last modified: 2015/02/02 08:23 (external edit)