Sorting data using std::map or std::multimap
<p>Happy New Year.  Hope everyone is ok.  I have not been here for a while.  </p>

<p>I have some contact lens data I'm trying to sort.  I have some sort rules are static (hard-coded) followed by other rules form 'normal' rules</p>

<p>Here are the requirements: </p>

<ol>
<li><p>First sort by Company and Product is a static order (hard-coded, non alphbetic)</p>

<p>Sample        </p>

<h2>o  Company          ProductName</h2>

<ol>
<li>Ciba             1. Focus,  2. AirOptics, 3. Dailies, 4. then alphabetical.</li>
<li>Bausch &amp; Lomb    1. PureVision, 2. LiquidEye, 3. Softlens then alphabetical.</li>
</ol></li>
<li><p>Followed by Package size decending (80, 30 ...)</p></li>
<li><p>Followed by Base Curve decending (8.6, 8,0 ...) </p></li>
<li><p>Followed by Sphere decending (-0.5, 0.0, 1.0 ...) </p></li>
</ol>

<p>In the end the result might look like the following </p>

<pre><code>Sample data
CO    PR     PS    BC    Sp
-------------------------------
Ciba  Focus  10    8.6    0.00
Ciba  Focus  20    8.6   -0.25
Ciba  Focus  20    8.6   -0.10
Ciba  Focus  20    8.6   +0.25
Ciba  Air    10    8.6   -0.25
Ciba  Air    10    8.6   -0.10
Ciba  Air    20    8.1   -0.25
Ciba  Air    20    8.1   -0.10
Ciba  Air    20    8.1    0.00
Ciba  Air    20    8.6   +0.25
Ciba  Air    20    8.6   +0.40
</code></pre>

<p>The data is contained in a struct with other data.  The stuct is used in a map with a key.  I am building a key to sort for the static requirments such as below.  </p>

<p>The key contains a prefix at the front of the key to force the static sort (non alphabetical), followed by a suffix to make the key unique.  Sample key: "1_1_Ciba_Focus Monthlys_4"</p>

<p>My plan to sort the other requirments is to take each of the other requirments (PackageSize, Base Curve and Sphere) and sort them against the previous element with the key.  </p>

<p>Since I will be sorting the following agaist the Package Size (10, 20 ...) - maybe I should be using the multimap, as it might be easter to sort this stuff without having the unique ID at the end of key ?? </p>

<p>With the key of "1_1_Ciba  Focus" I would sort on the PackSize and then set the key to produce the correct sort</p>

<pre><code>start: (std::multimap)
key: 1_1_Ciba  Focus"
Sample data
CO    PR     Key
-------------------------------
Ciba  Focus  1_1_Ciba  Focus
Ciba  Focus  1_1_Ciba  Focus
Ciba  Focus  1_1_Ciba  Focus
Ciba  Focus  1_1_Ciba  Focus

Sample data
CO    PR     PS    Key
-------------------------------
Ciba  Focus  10    1_1_1_Ciba  Focus
Ciba  Focus  20    1_1_2_Ciba  Focus
Ciba  Focus  20    1_1_2_Ciba  Focus
Ciba  Focus  20    1_1_2_Ciba  Focus
</code></pre>

<p>Thanks, 
Chris
chris@macgowan.com</p>
