Note that there are some explanatory texts on larger screens.

plurals
  1. PONeat way of computing functions on key-value pairs
    primarykey
    data
    text
    <p>Suppose you have a have list with key - value pairs. Neither keys, nor values, nor the pair are required to be unique.</p> <p>The following example</p> <pre><code>a -&gt; 1 b -&gt; 2 c -&gt; 3 a -&gt; 3 b -&gt; 1 </code></pre> <p>would be valid.</p> <p>Now suppose I want to associate to any key value pair (k->v) another value V, which has the following properties:</p> <ul> <li>it is the same for two pairs, if their keys are identical</li> <li>it is uniquely determined by the set of key-value pairs in the entire list</li> </ul> <p>This sounds abstract, but for example the sum, the maximum and counting function qualify as examples</p> <pre><code> Pair SUM MAX COUNT a -&gt; 1 4 3 2 b -&gt; 2 3 2 2 c -&gt; 3 3 3 1 a -&gt; 3 4 3 2 b -&gt; 1 3 2 2 </code></pre> <p>I am looking for a fast methods/data structures to compute such functions on the entire list.</p> <p>If the keys can be sorted, one can simply sort the list, then iterate through the sorted list, and compute the function V in each block with identical keys.</p> <p>I am asking whether there are nice methods to do this, if the values are not comparable or one does not want to change the order of the entries.</p> <p>Some thoughts:</p> <ol> <li>Of course, one could apply a hash function to the keys, in order to obtain sortable keys.</li> <li>Of course, one could also store the original position of each pair, then do the sorting, then compute the function, and finally undo the sorting.</li> </ol> <p>So essentially the question is already answered. However, I am interested in whether there are more elegant solutions maybe using some adapt data structure</p> <p>EDIT: To clarify Sunny Agrawal comment, what I mean by associate. Well this is also part of the question on how to nicely arrange the data structure. In my example, I would get another list/map with (k->v) as key and V as value. However, it might make sense to not arrange the data that way. I require, that V is stored in such a way that for given k it needs constant time to obtain V.</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.
 

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