Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You must use associative arrays (so called Dictionaries), based on hash-tables. Average time-complexity for lookup — O(1 + n/k) and O(n) in worst case. You must organize your Table as dictionary of columns (with column names as key). And Column must be dictionary of values (with row names as key)</p> <p>More info: </p> <p><a href="http://en.wikipedia.org/wiki/Dictionary_(data_structure" rel="nofollow">http://en.wikipedia.org/wiki/Dictionary_(data_structure</a>) <a href="http://en.wikipedia.org/wiki/Hash_table" rel="nofollow">http://en.wikipedia.org/wiki/Hash_table</a></p> <p>Example in C#:</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; namespace Test { public class Test { class Table { class Column { public Dictionary&lt;string, string&gt; cells; public Column() { cells = new Dictionary&lt;string, string&gt;(); } public string Find(string rowName) { string resultValue; if (cells.TryGetValue(rowName, out resultValue)) return resultValue; else throw new Exception("oops, no such cell"); } } Dictionary&lt;string, Column&gt; columns; List&lt;string&gt; rowNames; public Table() { columns = new Dictionary&lt;string, Column&gt;(); rowNames = new List&lt;string&gt;(); } public void AddColumn(string columnName, params string[] values) { Column column = new Column(); columns.Add(columnName, column); // fill new cells int counter = 0; foreach (string rowName in rowNames) { if (counter &lt; values.Length) column.cells.Add(rowName, values[counter]); else column.cells.Add(rowName, ""); counter++; } } public void AddRow(string rowName, params string[] values) { rowNames.Add(rowName); // fill new cells int counter = 0; foreach (KeyValuePair&lt;string, Column&gt; columnPair in columns) { Column column = columnPair.Value; if (counter &lt; values.Length) column.cells.Add(rowName, values[counter]); else column.cells.Add(rowName, ""); counter++; } } public string Find(string columnName, string rowName) { Column resultColumn; if (columns.TryGetValue(columnName, out resultColumn)) return resultColumn.Find(rowName); else throw new Exception("oops, no such cell"); } } public static void Main() { Table table = new Table(); table.AddRow("a"); table.AddRow("b"); table.AddColumn("column 1", "asd", "asgf"); table.AddColumn("column 2", "awd", "aasf"); table.AddColumn("column 3", "asfc", "asgfc"); Console.WriteLine(table.Find("column 1", "b") ); } } } </code></pre>
 

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