lundi 20 avril 2015

Round-robin table using only basic data structures

Vote count: 0

I have a list of elements (database tables) that may have relations with each other, including themselves.

Let's assume I have table1, table2, table3 and table4. What I would like to create and use in a loop would be structure like this:

      |table1|table2|table3|table4||
table1| 1:1  |      |      |      ||
table2|      |  1:1 |      |      ||
table3|      |      | 1:1  |      ||
table4|      |      |      |  1:1 ||

Note that while it is not necessary to have 1:1 relations pre-filled, it is important for me to be able easily address any of these cells in a loop.

There will be while(True) loop that will iterate over and over again until the iteration without change occurs.

What I am currently struggling with is to find an efficient and pythonic way of doing this with basic python structures, while keeping decent performance and easy addressing.

Example of what I tried

tableNames = d.items(); # returns me this format ([(tableName, ['column1', 'column2']), ... ])
for tName in tableNames:
  # some sort of comparism and conditions resulting in whatever decision
  # for example, that I need to insert information about 
  # relation on [actualtable][table2]

  fancyStructure[actualtable][table2] = "1:N";

Is it a good idea to use dictionary? Respectively dictionary of dictionaries? What is the best way?

And is it okay to pre-initialize that dictionary to the values that I will change in time? Note that this script will work with millions or even billions of records.

asked 1 min ago



Round-robin table using only basic data structures

Aucun commentaire:

Enregistrer un commentaire