Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IMO, you need to change the way your objects are stored. Something like the following:</p> <pre><code>std::map&lt;std::string, std::vector&lt;Composite&gt; &gt; </code></pre> <p>The key to the map is the prefix, and the index in the vector is the nth <code>Composite</code> object. You would need to provide a custom lookup function which split the passed in name.. e.g.</p> <pre><code>std::string query = "pipo_10"; </code></pre> <p>In your lookup function, </p> <pre><code>Composite* lookup(std::string const&amp; key) { // split the key to get the prefix and the index // lookup in the map using the prefix // return the index } </code></pre> <p>EDIT 1: To save all the string operations, you could define your own <em>custom key</em>, which is simply a pair (e.g, <code>std::pair&lt;std::string, int&gt;</code> which is the prefix and the index), and your lookup would simply use the values from this <em>key</em>.</p> <p><strike> EDIT 2: Thinking about this a little more, better to have a map of map, e.g.</p> <pre><code>std::map&lt;std::string, std::map&lt;int, Composite&gt; &gt; </code></pre> <p>Now instead of the index being an index in the vector, it's a lookup in the second map. This handles deletions better, the key will be the composite key as I said before (the pair). </strike></p> <p>Crediting @Steves' suggestion..</p> <pre><code>std::map&lt;std::pair&lt;std::string, int&gt;, Composite&gt; </code></pre> <p>Use the <code>lower_bound()</code> trick to locate the last index for the given <code>Composite</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload