Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternative data structure needed for deeply nested dictionary/map situation
    primarykey
    data
    text
    <p><strong>Some background of the data</strong>: some different games are being played, and each of them hosts a number of players. Each game consists of a number of rounds, and during each round each player involved makes an action. What I am trying to do here is to construct a data structure in memory for storing the complete history of individual actions taken by the players across all the games being played.</p> <p><strong>An obvious structure</strong> is a deeply nested dictionary/hashmap, where each <code>game_id</code> is mapped to a number of <code>player_id</code>s, and each player_id is mapped to different <code>round_number</code>s, and each <code>round_number</code> is mapped to an <code>action</code>. </p> <p>In other words, <code>game_id:player_id:round_number:action</code>. On the other hand, I can also use <code>game_id:round_number:player_id:action</code></p> <p><strong>Problem arises</strong> when I try to access the data structures above for different analytical purposes. For example, it's inconvenient to have <code>game_id:player_id:round_number:action</code>, if I want to know all the actions made by players in a particular round of a given game. Conversely, it is equally inconvenient to have <code>game_id:round_number:player_id:action</code>, if I want to know all the actions made by a particular player during the course of a given game. Unfortunately, in my case, I need to ask both those questions frequently.</p> <p>I wonder if there is <strong>a single data structure</strong> which can store such data and is convenient for accessing both player-level and round-level data as described above. The implementation will be in Python, if that matters.</p> <p><strong>EDIT</strong>: a few people have recommended in-memory sqlite database to handle such relational queries. However, its performance may be an issue for me, as discussed here: <a href="https://stackoverflow.com/questions/764710/sqlite-performance-benchmark-why-is-memory-so-slow-only-1-5x-as-fast-as-d">SQLite Performance Benchmark -- why is :memory: so slow...only 1.5X as fast as disk?</a> </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.
 

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