diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 56cd972..58fb4d6 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,5 +1,5 @@
------------------------------------------------------------------------------
- qSharp 2.2.0 [2015.08.x]
+ qSharp 2.2.0 [2015.08.14]
------------------------------------------------------------------------------
- API convenience extensions
diff --git a/qSharp/src/IQTable.cs b/qSharp/src/IQTable.cs
index 7c46ab1..5aebb9a 100644
--- a/qSharp/src/IQTable.cs
+++ b/qSharp/src/IQTable.cs
@@ -32,5 +32,20 @@ public interface IQTable
/// Gets a number of columns in table.
///
int ColumnsCount { get; }
+
+ ///
+ /// Checks whether table contains column with given name.
+ ///
+ /// Name of the column
+ /// true if table contains column with given name, false otherwise
+ bool HasColumn(string column);
+
+ ///
+ /// Gets a column index for specified name.
+ ///
+ /// Name of the column
+ /// 0 based column index
+ int GetColumnIndex(string column);
+
}
}
\ No newline at end of file
diff --git a/qSharp/src/QKeyedTable.cs b/qSharp/src/QKeyedTable.cs
index a4c3241..4a9b512 100644
--- a/qSharp/src/QKeyedTable.cs
+++ b/qSharp/src/QKeyedTable.cs
@@ -157,6 +157,33 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
return this.GetEnumerator();
}
+ ///
+ /// Checks whether table contains column with given name.
+ ///
+ /// Name of the column
+ /// true if table contains column with given name, false otherwise
+ public bool HasColumn(string column)
+ {
+ return _keys.HasColumn(column) || _values.HasColumn(column);
+ }
+
+ ///
+ /// Gets a column index for specified name.
+ ///
+ /// Name of the column
+ /// 0 based column index
+ public int GetColumnIndex(string column)
+ {
+ if (_keys.HasColumn(column))
+ {
+ return _keys.GetColumnIndex(column);
+ }
+ else
+ {
+ return _values.GetColumnIndex(column) + _keys.ColumnsCount;
+ }
+ }
+
///
/// Determines whether the specified System.Object is equal to the current QKeyedTable.
///
diff --git a/qSharp/src/QTable.cs b/qSharp/src/QTable.cs
index 081f8de..d9d2b9e 100644
--- a/qSharp/src/QTable.cs
+++ b/qSharp/src/QTable.cs
@@ -63,7 +63,7 @@ public QTable(string[] columns, Array data)
_columns = columns;
Data = data;
- RowsCount = ((Array) data.GetValue(0)).Length;
+ RowsCount = ((Array)data.GetValue(0)).Length;
}
///
@@ -120,14 +120,24 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
return this.GetEnumerator();
}
+ ///
+ /// Checks whether table contains column with given name.
+ ///
+ /// Name of the column
+ /// true if table contains column with given name, false otherwise
+ public bool HasColumn(string column)
+ {
+ return _columnsMap.Contains(column);
+ }
+
///
/// Gets a column index for specified name.
///
/// Name of the column
- /// 0 based column index
+ /// 0 based column index
public int GetColumnIndex(string column)
{
- return (int) _columnsMap[column];
+ return (int)_columnsMap[column];
}
///
@@ -148,7 +158,7 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
- return 31*Columns.GetHashCode() + Data.GetHashCode();
+ return 31 * Columns.GetHashCode() + Data.GetHashCode();
}
///
@@ -228,7 +238,8 @@ public struct Row : IEnumerable
///
/// Initializes a new instance of the Row.
///
- public Row(QTable table, int rowIndex) : this()
+ public Row(QTable table, int rowIndex)
+ : this()
{
if (rowIndex < 0 || rowIndex > table.RowsCount)
{
diff --git a/qSharp/test/DataTypeTest.cs b/qSharp/test/DataTypeTest.cs
index a287a1f..f9fb417 100644
--- a/qSharp/test/DataTypeTest.cs
+++ b/qSharp/test/DataTypeTest.cs
@@ -15,6 +15,7 @@
//
using NUnit.Framework;
+using System;
namespace qSharp.test
{
@@ -88,6 +89,12 @@ public void TestQTable()
var t = new QTable(columns, data);
Assert.AreEqual(t, new QTable(columns, data));
+ Assert.IsTrue(t.HasColumn("pos"));
+ Assert.IsFalse(t.HasColumn("unknown"));
+
+ Assert.AreEqual(1, t.GetColumnIndex("dates"));
+ Assert.Throws(() => t.GetColumnIndex("unknown"));
+
int i = 0;
var e = t.GetEnumerator();
@@ -111,6 +118,14 @@ public void TestQKeyedTable()
var kt = new QKeyedTable(columns, keyColumns, data);
Assert.AreEqual(kt, new QKeyedTable(columns, keyColumns, data));
+ Assert.IsTrue(kt.HasColumn("pos"));
+ Assert.IsFalse(kt.HasColumn("unknown"));
+
+ Assert.AreEqual(0, kt.GetColumnIndex("eid"));
+ Assert.AreEqual(1, kt.GetColumnIndex("pos"));
+ Assert.AreEqual(2, kt.GetColumnIndex("dates"));
+ Assert.Throws(() => kt.GetColumnIndex("unknown"));
+
int i = 0;
var e = kt.GetEnumerator();