<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[was nimmt man am einfachsten fürs mappen?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>die Frage ist vermutlich ganz einfach, aber bei der Hitze bin ich verwirrt. Ich habe folgendes Problem: Ich muss für eine bestimmte Knotennummer einen Ausgangsport auf einen Zielport mappen. Das ganze soll statisch erfolgen. Schön wäre so was wie:</p>
<p>int destPort = map(nodeID, outPort);</p>
<p>Das Problem ist aber das jeder Knoten eine unterschiedliche Anzahl von Ausgängen haben kann, es sind mindestens 1 und maximal 7. Wie macht man dies?</p>
<p>Ein genaues Beispiel wäre so:</p>
<pre><code>NODE_ID, OUT_PORT ---&gt; DEST_PORT
        0 1 --&gt;  0
        0 2 --&gt;  1
        0 3 --&gt;  2
        0 4 --&gt;  3
        1 0 --&gt;  0
        2 0 --&gt;  0
        3 0 --&gt;  0
        4 0 --&gt;  0
        4 5 --&gt;  1
        4 6 --&gt;  2
        5 4 --&gt;  0
        6 4 --&gt;  0
</code></pre>
<p>Mit mehrdimensionalen Arrays geht dies ja nicht, oder?<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270633/was-nimmt-man-am-einfachsten-fürs-mappen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 01:15:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270633.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Jul 2010 14:20:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:35:21 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>die Frage ist vermutlich ganz einfach, aber bei der Hitze bin ich verwirrt. Ich habe folgendes Problem: Ich muss für eine bestimmte Knotennummer einen Ausgangsport auf einen Zielport mappen. Das ganze soll statisch erfolgen. Schön wäre so was wie:</p>
<p>int destPort = map(nodeID, outPort);</p>
<p>Das Problem ist aber das jeder Knoten eine unterschiedliche Anzahl von Ausgängen haben kann, es sind mindestens 1 und maximal 7. Wie macht man dies?</p>
<p>Ein genaues Beispiel wäre so:</p>
<pre><code>NODE_ID, OUT_PORT ---&gt; DEST_PORT
        0 1 --&gt;  0
        0 2 --&gt;  1
        0 3 --&gt;  2
        0 4 --&gt;  3
        1 0 --&gt;  0
        2 0 --&gt;  0
        3 0 --&gt;  0
        4 0 --&gt;  0
        4 5 --&gt;  1
        4 6 --&gt;  2
        5 4 --&gt;  0
        6 4 --&gt;  0
</code></pre>
<p>Mit mehrdimensionalen Arrays geht dies ja nicht, oder?<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926721</guid><dc:creator><![CDATA[uwerothfeld]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:35:21 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:26:48 GMT]]></title><description><![CDATA[<p>Am einfachsten vielleicht mit einer std::map&lt;int,int&gt; und</p>
<pre><code class="language-cpp">return theMap[10*nodeID+1*outPort];
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1926729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926729</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:26:48 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:31:41 GMT]]></title><description><![CDATA[<p>Keine Ahnung was bei dir Knoten, outPort und destPort sein soll, aber fuer die Abbildung in deinem Beispiel gibt es viele Moeglichkeiten. Vielleicht std::map mit eine Paar als Schluessel und entsprechender Vergleichsfunktion.</p>
<blockquote>
<p>Mit mehrdimensionalen Arrays geht dies ja nicht, oder?</p>
</blockquote>
<p>Warum nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926731</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:31:41 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:33:22 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>aber eine Map lässt doch explizit keine doppelten Schlüssel zu, welche ich ja habe, siehe die NODE_ID 0 Einträge. Oder wie meinst du dies?<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926734</guid><dc:creator><![CDATA[uwerothfeld]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:33:22 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:37:22 GMT]]></title><description><![CDATA[<p>uwerothfeld schrieb:</p>
<blockquote>
<p>Hey,</p>
<p>aber eine Map lässt doch explizit keine doppelten Schlüssel zu, welche ich ja habe, siehe die NODE_ID 0 Einträge. Oder wie meinst du dies?<br />
Danke.</p>
</blockquote>
<p>Deswegen habe ich die nodeID doch vorher mit 10 plutimiziert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926738</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 14:46:24 GMT]]></title><description><![CDATA[<p>Hey volkard,</p>
<p>10 * 0 ? Wie soll das Helfen?</p>
<p>Mit würde dann irgendwie sowas vorschweben:</p>
<pre><code class="language-cpp">typedef std::pair&lt;int, int&gt; SOURCE_TA_DEST_TA;
        std::map&lt;SOURCE_TA_DEST_TA, int&gt; TA_PORT_MAP;

        TA_PORT_MAP.insert(std::make_pair(0,1),0);
        TA_PORT_MAP.insert(std::make_pair(0,2),1);
        TA_PORT_MAP.insert(std::make_pair(0,3),2);
        TA_PORT_MAP.insert(std::make_pair(0,4),3);
        TA_PORT_MAP.insert(std::make_pair(1,0),0);
        TA_PORT_MAP.insert(std::make_pair(2,0),0);
        TA_PORT_MAP.insert(std::make_pair(3,0),0);
        TA_PORT_MAP.insert(std::make_pair(4,0),0);
        TA_PORT_MAP.insert(std::make_pair(4,5),1);
        TA_PORT_MAP.insert(std::make_pair(4,6),2);
        TA_PORT_MAP.insert(std::make_pair(5,4),0);
        TA_PORT_MAP.insert(std::make_pair(6,4),0);
</code></pre>
<p>Aber kann man das auch const definieren? Also das es nur in einer H Datei steht? Wohl nicht, oder?<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926747</guid><dc:creator><![CDATA[uwerothfeld_]]></dc:creator><pubDate>Thu, 15 Jul 2010 14:46:24 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Thu, 15 Jul 2010 15:06:40 GMT]]></title><description><![CDATA[<p>uwerothfeld_ schrieb:</p>
<blockquote>
<p>Hey volkard,<br />
10 * 0 ? Wie soll das Helfen?</p>
</blockquote>
<p>Du denkst</p>
<pre><code>NODE_ID, OUT_PORT ---&gt; DEST_PORT 
        0 1 --&gt;  0 
        0 2 --&gt;  1 
        0 3 --&gt;  2 
        0 4 --&gt;  3 
        1 0 --&gt;  0 
        2 0 --&gt;  0 
        3 0 --&gt;  0 
        4 0 --&gt;  0 
        4 5 --&gt;  1 
        4 6 --&gt;  2 
        5 4 --&gt;  0 
        6 4 --&gt;  0
</code></pre>
<p>Und ich denke</p>
<pre><code>NODE_ID, OUT_PORT ---&gt; DEST_PORT 
          1 --&gt;  0 
          2 --&gt;  1 
          3 --&gt;  2 
          4 --&gt;  3 
         10 --&gt;  0 
         20 --&gt;  0 
         30 --&gt;  0 
         40 --&gt;  0 
         45 --&gt;  1 
         46 --&gt;  2 
         54 --&gt;  0 
         64 --&gt;  0
</code></pre>
<p>Und das Initialisieren kannst Du zum Beispiel wegmachen mit</p>
<p>Header</p>
<pre><code class="language-cpp">std::map&lt;...,int&gt;&amp; getTA_PORT_MAP();
</code></pre>
<p>*.cpp</p>
<pre><code class="language-cpp">std::map&lt;...,int&gt; createTheTA_PORT_MAP(){
  static std::map&lt;...,int&gt; theTA_PORT_MAP;
  theTA_PORT_MAP[12]=4;//usw...
  return theTA_PORT_MAP;
}
std::map&lt;...,int&gt;&amp; getTA_PORT_MAP();{
  static std::map&lt;...,int&gt; theTA_PORT_MAP=createTheTA_PORT_MAP();
  return theTA_PORT_MAP;
}
</code></pre>
<p>Und verwendet mit</p>
<pre><code class="language-cpp">cout&lt;&lt; getTA_PORT_MAP()[10*node+port] &lt;&lt;'\n';

//oder bei häufiger verwendung sich ne lokale Referenz ziehen

std::map&lt;...,int&gt;&amp; portMap=getTA_PORT_MAP();
cout&lt;&lt; portMap[10*node+port] &lt;&lt;'\n';
</code></pre>
<p>Wobei der *10-Trick nicht zwingend ist. Kannst auch std::pair nehmen oder ein zweidimensionales Array, dabei die nichtbelegten Ports auf 0 oder 8 oder wasauchimmer Ungültigkeit definiert. Oder schauen, daß 4 Bit pro Portnummer mal 8 Ports == 32 Bit und paßt noch supi in einen int32 und ein eindimensionales nehmen. Oder 8 Bit zum Nachschauen, ob Port existiert, plus 8*3 wären genau 32. Oh, das ist ja nichts anderes als wenn man 4 Bit für die Zahlen 0 bis 15 nimmt und Zahlen von 8 bis 15 sagen Ungültigkeit.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1926760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1926760</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 15 Jul 2010 15:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Fri, 16 Jul 2010 07:21:33 GMT]]></title><description><![CDATA[<p>Hallo volkard,</p>
<p>sehr schön. Verstehe. Ist die Hitze, behaupte ich mal <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Eine Frage noch, warum machst du dies:</p>
<pre><code class="language-cpp">std::map&lt;...,int&gt;&amp; getTA_PORT_MAP();{
  static std::map&lt;...,int&gt; theTA_PORT_MAP=createTheTA_PORT_MAP();
  return theTA_PORT_MAP;
}
</code></pre>
<p>Also warum die lokale static Variable?</p>
<p>Gruß und vielen Dank. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927013</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927013</guid><dc:creator><![CDATA[uwerothfeld]]></dc:creator><pubDate>Fri, 16 Jul 2010 07:21:33 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Fri, 16 Jul 2010 11:18:08 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927019</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:18:08 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Fri, 16 Jul 2010 12:24:39 GMT]]></title><description><![CDATA[<p>Weil es sonst komplizierter wäre, die Variable anzulegen.<br />
(Sie wäre entweder global oder static in der Klasse, was aufs gleiche hinausführt)<br />
Auf jeden Fall müsste man Sie trotzdem noch irgendwo initialisieren und befüllen.<br />
Das macht die Fkt alles schon von alleine.</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927218</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:24:39 GMT</pubDate></item><item><title><![CDATA[Reply to was nimmt man am einfachsten fürs mappen? on Fri, 16 Jul 2010 12:28:27 GMT]]></title><description><![CDATA[<p>uwerothfeld schrieb:</p>
<blockquote>
<p>Also warum die lokale static Variable?<br />
Gruß und vielen Dank. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
</blockquote>
<p>Da gehts nur ums static, was dafür sorgt, daß noch schnell geprüft wird, ob die Variable schon initialisiert wurde, und die Initialisierung (hier den teuren Funktionsaufruf) nur macht, wenn das während dieses Programmlaufs noch nicht geschehen ist.<br />
Den Trick benutzt man gerne, wenn man sich die teure Initialisierung zu Programmstart sparen will und sie so weit nach hinten verzögertm bis sie wirklich gebraucht wird. Aber zu Kosten von einem if pro Zugriff. Dabei bin ich sonst gar kein solcher Fan von Kosten. Hier der Code, wie er zu Programmstart initialisiert und kein if drin hat.</p>
<pre><code class="language-cpp">std::map&lt;...,int&gt; createTheTA_PORT_MAP(){
  static std::map&lt;...,int&gt; theTA_PORT_MAP;
  theTA_PORT_MAP[12]=4;//usw...
  return theTA_PORT_MAP;
}
static std::map&lt;...,int&gt; theTA_PORT_MAP=createTheTA_PORT_MAP();
std::map&lt;...,int&gt;&amp; getTA_PORT_MAP();{
  return theTA_PORT_MAP;
}
</code></pre>
<p>Man beachte die furchtbar unterscvhiedlichen Bedeutungen von static. Welch ein Zufall, daß die Zeile trotzdem im Ganzen verschoben werden wollte.</p>
<p>Oder im header die map per extern deklarieren und einfach als globale Variable leben lassen.<br />
*.h</p>
<pre><code class="language-cpp">extern static std::map&lt;...,int&gt; theTA_PORT_MAP;
</code></pre>
<p>*.cpp</p>
<pre><code class="language-cpp">std::map&lt;...,int&gt; createTheTA_PORT_MAP(){
  static std::map&lt;...,int&gt; theTA_PORT_MAP;
  theTA_PORT_MAP[12]=4;//usw...
  return theTA_PORT_MAP;
}
std::map&lt;...,int&gt; theTA_PORT_MAP=createTheTA_PORT_MAP();
</code></pre>
<p>Dann aber nicht mehr drauf zugreifen, bevor die main() gestartet wurde.</p>
<p>Oder gleich richtig machen und<br />
*.cpp</p>
<pre><code class="language-cpp">static std::map&lt;...,int&gt; theTA_PORT_MAP...

int getDestPort(int nodeID,int destPort){
   //hier schlaue Implementierung, denn der *10-Trick muß ja weg
   //und darf nicht in den Anwendungscode. 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1927222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927222</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:28:27 GMT</pubDate></item></channel></rss>