Skip to content

Commit

Permalink
API convenience extensions. QTable, QDictionary and QKeyedTable now i…
Browse files Browse the repository at this point in the history
…mplements generic version of IEnumerable<T> interface.

Fix: QDictionary enumerator failing to retrieve values.
  • Loading branch information
maciejlach committed Aug 10, 2015
1 parent 0e39f57 commit 4352820
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 45 deletions.
6 changes: 3 additions & 3 deletions AsynchClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: AsynchQuery")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


9 changes: 9 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
------------------------------------------------------------------------------
qSharp 2.2.0 [2015.08.x]
------------------------------------------------------------------------------

- API convenience extensions
- QTable, QDictionary and QKeyedTable now implements generic version of
IEnumerable interface
- Fix: QDictionary enumerator failing to retrieve values

------------------------------------------------------------------------------
qSharp 2.1.2 [2015.07.17]
------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions Publisher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: Publisher")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- img src="http://www.devnet.de/fileadmin/images/DEVnet_Logo2014.png" width="150px" height="150px"/-->

qSharp 2.1
qSharp 2.2
==========

The q/kdb+ interface is implemented as a set of C# classes and provides:
Expand Down
6 changes: 3 additions & 3 deletions RemoteConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: RemoteConsole")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


6 changes: 3 additions & 3 deletions Subscriber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: Subscriber")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


6 changes: 3 additions & 3 deletions TickClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: TickClient")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


6 changes: 3 additions & 3 deletions TickSubscriber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp: TickSubscriber")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


6 changes: 3 additions & 3 deletions qSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -12,7 +12,7 @@
[assembly: System.Reflection.AssemblyTitle("qSharp")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2015")]
[assembly: System.Reflection.AssemblyVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.1.0.0")]
[assembly: System.Reflection.AssemblyVersion("2.2.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.2.0.0")]


8 changes: 4 additions & 4 deletions qSharp/src/IQTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
namespace qSharp
{
/// <summary>
/// Common interface for the q date/time types.
/// Common interface for the q table types.
/// </summary>
public interface IQTable
{
/// <summary>
/// Gets a number of rows in current QTable.
/// Gets a number of rows in table.
/// </summary>
int RowsCount { get; }

/// <summary>
/// Gets a number of columns in current QTable.
/// Gets a number of columns in table.
/// </summary>
int ColumnsCount { get; }
int ColumnsCount { get; }
}
}
42 changes: 35 additions & 7 deletions qSharp/src/QDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

using System;
using System.Collections;
using System.Collections.Generic;

namespace qSharp
{
/// <summary>
/// Represents a q dictionary type.
/// </summary>
public sealed class QDictionary : IEnumerable
public sealed class QDictionary : IEnumerable<QDictionary.KeyValuePair>
{
private readonly bool _areValuesArray;
private readonly Array _keys;
Expand Down Expand Up @@ -51,6 +52,7 @@ public QDictionary(Array keys, Array values)
_keys = keys;
_values = values;
_areValuesArray = true;
Count = keys.Length;
}

/// <summary>
Expand All @@ -76,6 +78,7 @@ public QDictionary(Array keys, QTable values)
_keys = keys;
_values = values;
_areValuesArray = false;
Count = keys.Length;
}

/// <summary>
Expand All @@ -94,15 +97,29 @@ public object Values
get { return _values; }
}

/// <summary>
/// Gets a number of entries in the dictionary.
/// </summary>
public int Count { get; private set; }

/// <summary>
/// Returns an enumerator that iterates through a dictionary keys and values.
/// </summary>
/// <returns>An QDictionaryEnumerator object that can be used to iterate through the dictionary</returns>
public IEnumerator GetEnumerator()
public IEnumerator<QDictionary.KeyValuePair> GetEnumerator()
{
return new QDictionaryEnumerator(this);
}

/// <summary>
/// Returns an enumerator that iterates through a dictionary keys and values.
/// </summary>
/// <returns>An QDictionaryEnumerator object that can be used to iterate through the dictionary</returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}

/// <summary>
/// Determines whether the specified System.Object is equal to the current QDictionary.
/// </summary>
Expand Down Expand Up @@ -199,9 +216,10 @@ public object Value
var qTable = _dictionary._values as QTable;
if (qTable != null) return qTable[_index];
}
var table = _dictionary._values as QTable;
if (table != null)
return table[_index];
else
{
return (_dictionary._values as Array).GetValue(_index);
}

throw new NotFiniteNumberException(string.Format("Type {0} is unsupported.", _dictionary._values != null ? _dictionary._values.GetType().Name : "null"));
}
Expand All @@ -211,7 +229,7 @@ public object Value
/// <summary>
/// Iterator over pairs [key, value] stored in a dictionary.
/// </summary>
private sealed class QDictionaryEnumerator : IEnumerator
private sealed class QDictionaryEnumerator : IEnumerator<QDictionary.KeyValuePair>
{
private readonly QDictionary _dictionary;
private int _index = -1;
Expand All @@ -221,11 +239,16 @@ public QDictionaryEnumerator(QDictionary dictionary)
_dictionary = dictionary;
}

public object Current
public QDictionary.KeyValuePair Current
{
get { return new KeyValuePair(_dictionary, _index); }
}

object IEnumerator.Current
{
get { return Current; }
}

public bool MoveNext()
{
_index++;
Expand All @@ -236,6 +259,11 @@ public void Reset()
{
_index = -1;
}

public void Dispose()
{
_index = -1;
}
}
}
}
29 changes: 24 additions & 5 deletions qSharp/src/QKeyedTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace qSharp
/// <summary>
/// Represents a q keyed table type.
/// </summary>
public sealed class QKeyedTable : IEnumerable, IQTable
public sealed class QKeyedTable : IEnumerable<QKeyedTable.KeyValuePair>, IQTable
{
private readonly QTable _keys;
private readonly QTable _values;
Expand Down Expand Up @@ -143,11 +143,20 @@ public QTable Values
/// Returns an enumerator that iterates through a table keys and values.
/// </summary>
/// <returns>An QKeyedTableEnumerator object that can be used to iterate through the table</returns>
public IEnumerator GetEnumerator()
public IEnumerator<QKeyedTable.KeyValuePair> GetEnumerator()
{
return new QKeyedTableEnumerator(this);
}

/// <summary>
/// Returns an enumerator that iterates through rows in a table.
/// </summary>
/// <returns>An QKeyedTableEnumerator object that can be used to iterate through the table</returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}

/// <summary>
/// Determines whether the specified System.Object is equal to the current QKeyedTable.
/// </summary>
Expand Down Expand Up @@ -196,7 +205,7 @@ public override string ToString()
/// <summary>
/// Defines a key/value pair that can be retrieved.
/// </summary>
private struct KeyValuePair
public struct KeyValuePair
{
private readonly int _index;
private readonly QKeyedTable _kt;
Expand Down Expand Up @@ -230,7 +239,7 @@ public object Value
/// <summary>
/// Iterator over pairs [key, value] stored in a keyed table.
/// </summary>
private sealed class QKeyedTableEnumerator : IEnumerator
private sealed class QKeyedTableEnumerator : IEnumerator<QKeyedTable.KeyValuePair>
{
private readonly QKeyedTable _kt;
private int _index = -1;
Expand All @@ -240,11 +249,16 @@ public QKeyedTableEnumerator(QKeyedTable table)
_kt = table;
}

public object Current
public QKeyedTable.KeyValuePair Current
{
get { return new KeyValuePair(_kt, _index); }
}

object IEnumerator.Current
{
get { return Current; }
}

public bool MoveNext()
{
_index++;
Expand All @@ -255,6 +269,11 @@ public void Reset()
{
_index = -1;
}

public void Dispose()
{
_index = -1;
}
}

public int RowsCount
Expand Down
Loading

0 comments on commit 4352820

Please sign in to comment.