public AssocMatrix() { mat = new NumericMatrix <V>(10, 10); r = new AssocArray <AI1, int> (); c = new AssocArray <AI2, int> (); keyRows = new Set <AI1>(); keyColumns = new Set <AI2>(); }
public AssocMatrix(AssocMatrix <AI1, AI2, V> mat2) { mat = new NumericMatrix <V>(mat2.mat); r = new AssocArray <AI1, int>(mat2.r); c = new AssocArray <AI2, int>(mat2.c); keyRows = new Set <AI1>(mat2.keyRows); keyColumns = new Set <AI2>(mat2.keyColumns); }
private void KeyExchange(ref Byte encryptMode) { while (keyExchanging) { Thread.Sleep(1); } if (key != null || encryptMode == 0) { return; } if ((key == null) && keyExchanged) { encryptMode = 0; return; } keyExchanging = true; Hashtable result = POST("phprpc_encrypt=true&phprpc_keylen=" + keylen); if (result.ContainsKey("phprpc_keylen")) { keylen = (UInt32)result["phprpc_keylen"]; } else { keylen = 128; } if (result.ContainsKey("phprpc_encrypt")) { AssocArray encrypt = (AssocArray)Deserialize((Byte[])result["phprpc_encrypt"]); BigInteger x = BigInteger.GenerateRandom((Int32)keylen - 1); x.SetBit(keylen - 2); BigInteger y = BigInteger.Parse(PHPConvert.ToString(encrypt["y"])); BigInteger p = BigInteger.Parse(PHPConvert.ToString(encrypt["p"])); BigInteger g = BigInteger.Parse(PHPConvert.ToString(encrypt["g"])); if (keylen == 128) { this.key = new byte[16]; Byte[] k = y.ModPow(x, p).GetBytes(); for (Int32 i = 1, n = Math.Min(k.Length, 16); i <= n; i++) { this.key[16 - i] = k[n - i]; } } else { key = MD5.Hash(encoding.GetBytes(y.ModPow(x, p).ToString())); } POST("phprpc_encrypt=" + g.ModPow(x, p).ToString()); } else { key = null; keyExchanged = true; encryptMode = 0; } keyExchanging = false; }
// Method // assign data to data member private void SetDataMember(Queue <ListedContSpec> contractSpec) { // Data member Set <string> s = new Set <string>(); // contains labels // Populate the set with label foreach (ListedContSpec l in contractSpec) { s.Insert(l.GetLabel); } // assigns CollectOfContrSpec = new AssocArray <string, ListedContSpec>(s, new Vector <ListedContSpec>(contractSpec.ToArray(), 0)); }
public static void Main() { AssocArray <int, double> assArr = new AssocArray <int, double> (); assArr[0] = 2.0; assArr[100] = 3.0; assArr[10] = 43.0; assArr[1000] = 34.0; Console.WriteLine(assArr[100]); foreach (KeyValuePair <int, double> kvp in assArr) { Console.WriteLine("{0}, {1}", kvp.Key, kvp.Value); } Set <string> RowNames = new Set <string>(); RowNames.Insert("A1"); RowNames.Insert("A2"); RowNames.Insert("A3"); RowNames.Insert("A4"); RowNames.Insert("B1"); Set <string> ColNames = new Set <string>(); ColNames.Insert("C1"); ColNames.Insert("C2"); ColNames.Insert("C3"); ColNames.Insert("C4"); ColNames.Insert("C5"); //double defaultValue = 10.0; // Contents of associative matrix (numeric values) NumericMatrix <double> mat1 = new NumericMatrix <double>(RowNames.Size(), ColNames.Size()); mat1.initCells(3.0); AssocMatrix <string, string, double> myMat = new AssocMatrix <string, string, double>(RowNames, ColNames, mat1); Factory fs = new DoubleFactory(); object b; b = fs.create(); Set <double> s1 = (Set <double>)b; Console.WriteLine(s1.Size()); }
// V2 /* * // Construct the map from a list of names and a REPEATED val * AssocMatrix(V rowStart, V columnStart, NumericMatrix<V> matrix) * { * * // Must build the associative arrays, they have the same values as the * // indices in the matrix * * VectorCollectionGenerator<V> rowGenerator = new VectorCollectionGenerator<V>(); * rowGenerator.Start = rowStart; * rowGenerator.Increment = new V(); * rowGenerator.Size = matrix.Rows; * * VectorCollectionGenerator<V> columnGenerator = new VectorCollectionGenerator<V>(); * columnGenerator.Start = columnStart; * columnGenerator.Increment = 1; * columnGenerator.Size = matrix.Columns; * * mat = new NumericMatrix<V>(matrix); * * // keyRows = new SetCreator<V, int>.createSet(rowGenerator); * //keyColumns = new SetCreator<V, int>.createSet(columnGenerator); * * * // Build rows * int start = mat.MinRowIndex; * r = new AssocArray<AI1, int> (); * * foreach (AI1 row in keyRows) * { * r[row] = start; * start = start + 1; * } * * // Build columns * start = mat.MinColumnIndex; * c = new AssocArray<AI2, int>(); * * foreach (AI2 col in keyColumns) * { * c[col] = start; * start = start + 1; * } * * // NO EXCEPTION HANDLING AT THE MOMENT * //print(c); * } * */ public AssocMatrix(Set <AI1> Rnames, Set <AI2> Cnames, NumericMatrix <V> matrix) { keyRows = new Set <AI1>(Rnames); keyColumns = new Set <AI2>(Cnames); // Must build the associative arrays, they have the same values as the // indices in the matrix //mat = new NumericMatrix<V>(matrix); mat = matrix; // Build rows int start = mat.MinRowIndex; r = new AssocArray <AI1, int> (); foreach (AI1 row in keyRows) { r[row] = start; start++; } // Build columns start = mat.MinColumnIndex; c = new AssocArray <AI2, int> (); foreach (AI2 col in keyColumns) { c[col] = start; start++; } // NO EXCEPTION HANDLING AT THE MOMENT //print(c); }
private void NextKeyExchange(Object state) { RequestState requestState = state as RequestState; Hashtable result = GetResponseBody(requestState.response, 0); #if SILVERLIGHT if (result.ContainsKey("phprpc_url")) { String phprpc_url = (String)result["phprpc_url"]; url = new Uri(phprpc_url); if (url.Query == "") { url = new Uri(phprpc_url + "?phprpc_id=" + clientID); } else { url = new Uri(phprpc_url + "&phprpc_id=" + clientID); } } #endif if (result.ContainsKey("phprpc_keylen")) { keylen = (UInt32)result["phprpc_keylen"]; } else { keylen = 128; } if (result.ContainsKey("phprpc_encrypt")) { AssocArray encrypt = (AssocArray)Deserialize((Byte[])result["phprpc_encrypt"]); BigInteger x = BigInteger.GenerateRandom((Int32)keylen - 1); x.SetBit(keylen - 2); BigInteger y = BigInteger.Parse(PHPConvert.ToString(encrypt["y"])); BigInteger p = BigInteger.Parse(PHPConvert.ToString(encrypt["p"])); BigInteger g = BigInteger.Parse(PHPConvert.ToString(encrypt["g"])); if (keylen == 128) { this.key = new byte[16]; Byte[] k = y.ModPow(x, p).GetBytes(); for (Int32 i = 1, n = Math.Min(k.Length, 16); i <= n; i++) { this.key[16 - i] = k[n - i]; } } else { key = MD5.Hash(encoding.GetBytes(y.ModPow(x, p).ToString())); } requestState = new RequestState(); requestState.bufferWrite = encoding.GetBytes("phprpc_encrypt=" + g.ModPow(x, p).ToString()); requestState.asyncCallback = new SendOrPostCallback(EndKeyExchange); POST(requestState); } else { key = null; requestState.encryptMode = 0; keyExchanged = true; EndKeyExchange(null); } }
public static void Main() { AssocArray <int, double> assArr = new AssocArray <int, double> (); assArr[0] = 2.0; assArr[100] = 3.0; assArr[10] = 43.0; assArr[1000] = 34.0; Console.WriteLine(assArr[100]); foreach (KeyValuePair <int, double> kvp in assArr) { Console.WriteLine("{0}, {1}", kvp.Key, kvp.Value); } Set <string> names = new Set <string>(); names.Insert("A1"); names.Insert("A2"); names.Insert("A3"); names.Insert("A4"); names.Insert("B1"); double defaultValue = 10.0; AssocArray <string, double> myAssocArray = new AssocArray <string, double>(names, defaultValue); myAssocArray.print(); myAssocArray["A4"] = 99.99; myAssocArray.print(); // Test other functions AssocArray <string, double> myAssocArray2 = new AssocArray <string, double> (myAssocArray); myAssocArray2.print(); AssocMatrix <string, string, double> myMat = new AssocMatrix <string, string, double>(); myMat.print(); // Create an associative matrix with 2 sets and a numeric matrix NumericMatrix <double> mat1 = new NumericMatrix <double>(names.Size(), names.Size()); AssocMatrix <string, string, double> myMat2 = new AssocMatrix <string, string, double>(names, names, mat1); myMat2.print(); // Now work with ranges in this associative matrix SpreadSheetVertex <long, string> ul = new SpreadSheetVertex <long, string> (); // Upper left ul.first = 1; ul.second = "B"; SpreadSheetVertex <long, string> lr = new SpreadSheetVertex <long, string> (); // Lower right lr.first = 3; lr.second = "D"; SpreadSheetRange <long, string> myRange = new SpreadSheetRange <long, string>(); myRange.upperLeft = ul; myRange.lowerRight = lr; // myMat22.modify(myRange, Modifier1); //print (*(myMat2.Data())); // print(myMat2.extract(myRange)); SpreadSheetVertex <string, string> ul2 = new SpreadSheetVertex <string, string>(); // Upper left ul2.first = "A1"; ul2.second = "A1"; SpreadSheetVertex <string, string> lr2 = new SpreadSheetVertex <string, string>(); // Upper left lr2.first = "A4"; lr2.second = "A4"; SpreadSheetRange <string, string> myRange2 = new SpreadSheetRange <string, string>(); myRange2.upperLeft = ul2; myRange2.lowerRight = lr2; // Now work with Dates; 101 example, later more extensive, eg. I/O witb Excel Set <DateTime> dates = new Set <DateTime>(); dates.Insert(DateTime.Now); dates.Insert(new DateTime(2009, 3, 17)); NumericMatrix <double> payments = new NumericMatrix <double>(dates.Size(), dates.Size()); AssocMatrix <DateTime, DateTime, double> Sheet = new AssocMatrix <DateTime, DateTime, double>(dates, dates, payments); }
public AssocArray(AssocArray <Key, Value> arr2) { // Copy constructor str = new Dictionary <Key, Value>(arr2.str); keys = new Set <Key>(arr2.keys); }