<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Philben - Ms Access &#187; Tableau</title>
	<atom:link href="https://blog.developpez.com/philben/ptag/tableau/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/philben</link>
	<description></description>
	<lastBuildDate>Thu, 26 Sep 2013 19:43:53 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Indexer un tri de tableau</title>
		<link>https://blog.developpez.com/philben/p10858/vba-access/indexer_un_tri_de_tableau</link>
		<comments>https://blog.developpez.com/philben/p10858/vba-access/indexer_un_tri_de_tableau#comments</comments>
		<pubDate>Tue, 20 Mar 2012 20:40:41 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Numérique]]></category>
		<category><![CDATA[Tableau]]></category>
		<category><![CDATA[Trier]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Dans certaines circonstances, il est nécessaire de ne pas trier le tableau originel mais d&#8217;indexer le tri dans un tableau secondaire. Voici la fonction de tri indexé avec Shellsort&#8230; 'ShellsortIndex - Philben - v1.0 - 03/2012 'Utilisable pour des tailles &#8230; <a href="https://blog.developpez.com/philben/p10858/vba-access/indexer_un_tri_de_tableau">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Dans certaines circonstances, il est nécessaire de ne pas trier le tableau originel mais d&rsquo;indexer le tri dans un tableau secondaire.<br />
Voici la fonction de tri indexé avec Shellsort&#8230;<br />
<span id="more-5"></span></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">'ShellsortIndex - Philben - v1.0 - 03/2012 <br />
</span><span style="color: #008000;">'Utilisable pour des tailles de tableau jusqu'à 10 000 000 <br />
</span><span style="color: #008000;">'Les valeurs des gaps au-dessus de 1750 sont extrapolées et ne sont certainement pas les plus efficaces ! <br />
</span><span style="color: #008000;">'Si le type de tableau est Integer, modifier : <br />
</span><span style="color: #008000;">' &nbsp;- ByRef a() As Long &nbsp; &nbsp; en ByRef a() As Integer <br />
</span><span style="color: #008000;">' &nbsp;- Dim ref As Long &nbsp; &nbsp; &nbsp; en Dim ref As Integer <br />
</span><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> ShellSortIndex(<span style="color: #151B8D; font-weight: bold;">ByRef</span> a() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">ByRef</span> Idx() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> lowerBound <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> upperBound <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>) <br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> ref <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> <br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> h <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, m <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, n <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, refIdx <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, g <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span> <br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">ReDim</span> Idx(lowerBound <span style="color: #8D38C9; font-weight: bold;">To</span> upperBound) <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = lowerBound <span style="color: #8D38C9; font-weight: bold;">To</span> upperBound: Idx(i) = i: <span style="color: #8D38C9; font-weight: bold;">Next</span> i <br />
&nbsp;<br />
&nbsp; &nbsp;g = Array(1, 4, 10, 23, 57, 132, 301, 701, 1750, 4376, 10941, 27353, 68383, 170958, 427396, 1068491, 2671228) <br />
&nbsp; &nbsp;n = upperBound - lowerBound + 1 <br />
&nbsp;<br />
&nbsp; &nbsp;l = <span style="color: #151B8D; font-weight: bold;">LBound</span>(g) <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> n &lt; g(<span style="color: #151B8D; font-weight: bold;">UBound</span>(g)) <span style="color: #8D38C9; font-weight: bold;">Then</span> <br />
&nbsp; &nbsp; &nbsp; k = l <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> g(k + 1) &lt; n: k = k + 1: Wend <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span> <br />
&nbsp; &nbsp; &nbsp; k = <span style="color: #151B8D; font-weight: bold;">UBound</span>(g) <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span> <br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> k &gt;= l <br />
&nbsp; &nbsp; &nbsp; h = g(k) <br />
&nbsp; &nbsp; &nbsp; m = lowerBound + h <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = m <span style="color: #8D38C9; font-weight: bold;">To</span> upperBound <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ref = a(Idx(i)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;refIdx = Idx(i) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j = i <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Do</span> <span style="color: #8D38C9; font-weight: bold;">While</span> ref &lt; a(Idx(j - h)) &nbsp; <span style="color: #008000;">'&lt; pour un tri croissant, sinon &gt; <br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Idx(j) = Idx(j - h) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; j = j - h <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> j &lt; m <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #8D38C9; font-weight: bold;">Do</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Loop</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Idx(j) = refIdx <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i <br />
&nbsp; &nbsp; &nbsp; k = k - 1 <br />
&nbsp; &nbsp;Wend <br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>Le tableau Idx() contient l&rsquo;ordre des valeurs du tableau a().<br />
Par exemple, Les valeurs triées sont obtenues par :</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(Idx) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(Idx)<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> a(Idx(i))<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i</div></div>
<p><strong>Remarque</strong><br />
Le tri par index est moins rapide que le tri du tableau lui-même. Compter 40 à 50% de temps en plus.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fonction performante de tri de tableaux</title>
		<link>https://blog.developpez.com/philben/p10854/vba-access/fonction_performante_de_tri_de_tableaux</link>
		<comments>https://blog.developpez.com/philben/p10854/vba-access/fonction_performante_de_tri_de_tableaux#comments</comments>
		<pubDate>Mon, 19 Mar 2012 22:08:37 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Numérique]]></category>
		<category><![CDATA[Tableau]]></category>
		<category><![CDATA[Trier]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il existe plusieurs dizaines de méthodes de tri de tableaux et la plus renommée est Quicksort en terme de rapidité. Qu&#8217;en est-il en VBA ? J&#8217;ai testé plusieurs algorithmes dont Insertionsort, Heapsort, Mergesort, Quicksort, mais mon préféré reste Shellsort par &#8230; <a href="https://blog.developpez.com/philben/p10854/vba-access/fonction_performante_de_tri_de_tableaux">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il existe plusieurs dizaines de méthodes de tri de tableaux et la plus renommée est Quicksort en terme de rapidité.<br />
Qu&rsquo;en est-il en VBA ?<br />
<span id="more-4"></span><br />
J&rsquo;ai testé plusieurs algorithmes dont Insertionsort, Heapsort, Mergesort, Quicksort, mais mon préféré reste Shellsort par sa compacité, simplicité et sa rapidité. L&rsquo;efficacité de Shellsort réside dans le choix des gaps qui ont fait l&rsquo;objet de multiples publications depuis les années 60. Les meilleurs gaps semblent bien définis jusqu&rsquo;à la valeur de 1750.</p>
<p><strong>Ma fonction Shellsort</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">'Shellsort - Philben - v1.0 - 03/2012 <br />
</span><span style="color: #008000;">'Utilisable pour des tailles de tableau jusqu'à 10 000 000 <br />
</span><span style="color: #008000;">'La valeur des gaps au-dessus de 1750 sont extrapolées et ne sont certainement pas les plus efficaces ! <br />
</span><span style="color: #008000;">'Si le type de tableau est Integer, modifier : <br />
</span><span style="color: #008000;">' &nbsp;- ByRef a() As Long &nbsp;en ByRef a() As Integer <br />
</span><span style="color: #008000;">' &nbsp;- Dim ref As Long &nbsp; &nbsp;en Dim ref As Integer <br />
</span><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> ShellSort(<span style="color: #151B8D; font-weight: bold;">ByRef</span> a() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> lowerBound <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> upperBound <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>) <br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> ref <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> <br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> h <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, m <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, n <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, g <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span> <br />
&nbsp;<br />
&nbsp; &nbsp;g = Array(1, 4, 10, 23, 57, 132, 301, 701, 1750, 4376, 10941, 27353, 68383, 170958, 427396, 1068491, 2671228) <br />
&nbsp; &nbsp;n = upperBound - lowerBound + 1 <br />
&nbsp;<br />
&nbsp; &nbsp;l = <span style="color: #151B8D; font-weight: bold;">LBound</span>(g) <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> n &lt; g(<span style="color: #151B8D; font-weight: bold;">UBound</span>(g)) <span style="color: #8D38C9; font-weight: bold;">Then</span> <br />
&nbsp; &nbsp; &nbsp; k = l <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> g(k + 1) &lt; n: k = k + 1: Wend <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span> <br />
&nbsp; &nbsp; &nbsp; k = <span style="color: #151B8D; font-weight: bold;">UBound</span>(g) <br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span> <br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> k &gt;= l <br />
&nbsp; &nbsp; &nbsp; h = g(k) <br />
&nbsp; &nbsp; &nbsp; m = lowerBound + h <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = m <span style="color: #8D38C9; font-weight: bold;">To</span> upperBound <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ref = a(i) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j = i <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Do</span> <span style="color: #8D38C9; font-weight: bold;">While</span> ref &lt; a(j - h) <span style="color: #008000;">'&lt; pour un tri croissant, sinon &gt; <br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a(j) = a(j - h) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; j = j - h <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> j &lt; m <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #8D38C9; font-weight: bold;">Do</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Loop</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a(j) = ref <br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i <br />
&nbsp; &nbsp; &nbsp; k = k - 1 <br />
&nbsp; &nbsp;Wend <br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p><strong>Le face à face</strong><br />
Après avoir trouvé sur le <a href="http://epaperpress.com/sortsearch/index.html">web</a> une bonne implémentation de Qsort (Quicksort non récursif), j&rsquo;ai comparé leur rapidité à trier différentes tailles de tableau.<br />
Les résultats de Shellsort en prenant comme base 100 les résultats de Qsort pour le tri d&rsquo;entiers long :<br />
<img src="http://philben.developpez.com/shellsort.png" alt="Shellsort" title="Performance de Shellsort par rapport à Qsort" /></p>
<p><strong>Analyse des résultats</strong><br />
Shellsort est plus rapide (jusqu&rsquo;à 30% plus rapide !) que Qsort pour des tableaux inférieurs à 100 000 valeurs. Au-delà, Qsort creuse petit à petit l&rsquo;écart.<br />
Compter une dizaine de millisecondes pour trier un tableau de 10 000 valeurs, 160ms pour 100 000 et 2 secondes pour 1 million de valeurs.</p>
<p><strong>Conclusion</strong><br />
En VBA et pour des tableaux jusqu&rsquo;à 100 000 valeurs, Shellsort est un algorithme de tri très rapide. Si vous possédez une fonction encore plus rapide, merci de l&rsquo;ajouter en commentaire.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
