public static void Main( string[] args ) { int searchInt; // search key int position; // location of search key in array // create array and output it BinaryArray searchArray = new BinaryArray( 15 ); Console.WriteLine( searchArray ); // prompt and input first int from user Console.Write( "Please enter an integer value (-1 to quit): " ); searchInt = Convert.ToInt32( Console.ReadLine() ); Console.WriteLine(); // repeatedly input an integer; -1 terminates the application while ( searchInt != -1 ) { // use binary search to try to find integer position = searchArray.BinarySearch( searchInt ); // return value of -1 indicates integer was not found if ( position == -1 ) Console.WriteLine( "The integer {0} was not found.\n", searchInt ); else Console.WriteLine( "The integer {0} was found in position {1}.\n", searchInt, position); // prompt and input next int from user Console.Write( "Please enter an integer value (-1 to quit): " ); searchInt = Convert.ToInt32( Console.ReadLine() ); Console.WriteLine(); } // end while }
public void Visit(BinaryArray array) { _buffers.Add(CreateBuffer(array.NullBitmapBuffer)); _buffers.Add(CreateBuffer(array.ValueOffsetsBuffer)); _buffers.Add(CreateBuffer(array.ValueBuffer)); }
public void Visit(BinaryArray array) => throw new NotImplementedException();
public static Func <int, T> GetGetter <T>(IArrowArray array) { if (array is null) { return(null); } // TODO: determine fastest way to read out a value from the array. if (typeof(T) == typeof(bool)) { var booleanArray = new BooleanArray(array.Data); return((Func <int, T>)(object) new Func <int, bool>( index => booleanArray.GetBoolean(index).GetValueOrDefault())); } if (typeof(T) == typeof(bool?)) { var booleanArray = new BooleanArray(array.Data); return((Func <int, T>)(object) new Func <int, bool?>(booleanArray.GetBoolean)); } if (typeof(T) == typeof(sbyte)) { var int8Array = new Int8Array(array.Data); return((Func <int, T>)(object) new Func <int, sbyte>( index => int8Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(sbyte?)) { var int8Array = new Int8Array(array.Data); return((Func <int, T>)(object) new Func <int, sbyte?>(int8Array.GetValue)); } if (typeof(T) == typeof(byte)) { var uint8Array = new UInt8Array(array.Data); return((Func <int, T>)(object) new Func <int, byte>( index => uint8Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(byte?)) { var uint8Array = new UInt8Array(array.Data); return((Func <int, T>)(object) new Func <int, byte?>(uint8Array.GetValue)); } if (typeof(T) == typeof(short)) { var int16Array = new Int16Array(array.Data); return((Func <int, T>)(object) new Func <int, short>( index => int16Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(short?)) { var int16Array = new Int16Array(array.Data); return((Func <int, T>)(object) new Func <int, short?>(int16Array.GetValue)); } if (typeof(T) == typeof(ushort)) { var uint16Array = new UInt16Array(array.Data); return((Func <int, T>)(object) new Func <int, ushort>( index => uint16Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(ushort?)) { var uint16Array = new UInt16Array(array.Data); return((Func <int, T>)(object) new Func <int, ushort?>(uint16Array.GetValue)); } if (typeof(T) == typeof(int)) { var int32Array = new Int32Array(array.Data); return((Func <int, T>)(object) new Func <int, int>( index => int32Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(int?)) { var int32Array = new Int32Array(array.Data); return((Func <int, T>)(object) new Func <int, int?>(int32Array.GetValue)); } if (typeof(T) == typeof(uint)) { var uint32Array = new UInt32Array(array.Data); return((Func <int, T>)(object) new Func <int, uint>( index => uint32Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(uint?)) { var uint32Array = new UInt32Array(array.Data); return((Func <int, T>)(object) new Func <int, uint?>(uint32Array.GetValue)); } if (typeof(T) == typeof(long)) { var int64Array = new Int64Array(array.Data); return((Func <int, T>)(object) new Func <int, long>( index => int64Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(long?)) { var int64Array = new Int64Array(array.Data); return((Func <int, T>)(object) new Func <int, long?>(int64Array.GetValue)); } if (typeof(T) == typeof(ulong)) { var uint64Array = new UInt64Array(array.Data); return((Func <int, T>)(object) new Func <int, ulong>( index => uint64Array.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(ulong?)) { var uint64Array = new UInt64Array(array.Data); return((Func <int, T>)(object) new Func <int, ulong?>(uint64Array.GetValue)); } if (typeof(T) == typeof(double)) { var doubleArray = new DoubleArray(array.Data); return((Func <int, T>)(object) new Func <int, double>( index => doubleArray.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(double?)) { var doubleArray = new DoubleArray(array.Data); return((Func <int, T>)(object) new Func <int, double?>(doubleArray.GetValue)); } if (typeof(T) == typeof(float)) { var floatArray = new FloatArray(array.Data); return((Func <int, T>)(object) new Func <int, float>( index => floatArray.GetValue(index).GetValueOrDefault())); } if (typeof(T) == typeof(float?)) { var floatArray = new FloatArray(array.Data); return((Func <int, T>)(object) new Func <int, float?>(floatArray.GetValue)); } if (typeof(T) == typeof(DateTime)) { if (array.Data.DataType.TypeId == ArrowTypeId.Date32) { var date32Array = new Date32Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTime>( index => date32Array.GetDate(index).GetValueOrDefault().DateTime)); } else if (array.Data.DataType.TypeId == ArrowTypeId.Date64) { var date64Array = new Date64Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTime>( index => date64Array.GetDate(index).GetValueOrDefault().DateTime)); } } if (typeof(T) == typeof(DateTime?)) { if (array.Data.DataType.TypeId == ArrowTypeId.Date32) { var date32Array = new Date32Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTime?>( index => date32Array.GetDate(index)?.DateTime)); } else if (array.Data.DataType.TypeId == ArrowTypeId.Date64) { var date64Array = new Date64Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTime?>( index => date64Array.GetDate(index)?.DateTime)); } } if (typeof(T) == typeof(DateTimeOffset)) { if (array.Data.DataType.TypeId == ArrowTypeId.Date32) { var date32Array = new Date32Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTimeOffset>( index => date32Array.GetDate(index).GetValueOrDefault())); } else if (array.Data.DataType.TypeId == ArrowTypeId.Date64) { var date64Array = new Date64Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTimeOffset>( index => date64Array.GetDate(index).GetValueOrDefault())); } } if (typeof(T) == typeof(DateTimeOffset?)) { if (array.Data.DataType.TypeId == ArrowTypeId.Date32) { var date32Array = new Date32Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTimeOffset?>( date32Array.GetDate)); } else if (array.Data.DataType.TypeId == ArrowTypeId.Date64) { var date64Array = new Date64Array(array.Data); return((Func <int, T>)(object) new Func <int, DateTimeOffset?>( date64Array.GetDate)); } } if (typeof(T) == typeof(TimeSpan)) { var timestampArray = new TimestampArray(array.Data); return((Func <int, T>)(object) new Func <int, TimeSpan>( index => timestampArray.GetTimestamp(index).GetValueOrDefault().TimeOfDay)); } if (typeof(T) == typeof(TimeSpan?)) { var timestampArray = new TimestampArray(array.Data); return((Func <int, T>)(object) new Func <int, TimeSpan?>( index => timestampArray.GetTimestamp(index)?.TimeOfDay)); } if (typeof(T) == typeof(byte[])) { var binaryArray = new BinaryArray(array.Data); return((Func <int, T>)(object) new Func <int, byte[]>( // TODO: how to avoid this allocation/copy? index => binaryArray.GetBytes(index).ToArray())); } if (typeof(T) == typeof(string)) { var stringArray = new StringArray(array.Data); return((Func <int, T>)(object) new Func <int, string>( index => stringArray.GetString(index))); } // It's something else we don't yet support. switch (array.Data.DataType.TypeId) { case ArrowTypeId.Decimal: case ArrowTypeId.Dictionary: case ArrowTypeId.FixedSizedBinary: case ArrowTypeId.HalfFloat: case ArrowTypeId.Interval: case ArrowTypeId.List: case ArrowTypeId.Map: case ArrowTypeId.Null: case ArrowTypeId.Struct: case ArrowTypeId.Time32: case ArrowTypeId.Time64: case ArrowTypeId.Union: default: // TODO: support additional types? throw new NotSupportedException( $"Not supported array type: {array.Data.DataType.TypeId}"); } }
public void Test_BinaryArray() { using (BinaryArray binaryArray = new BinaryArray(1024 * 256, _bufferManager)) { Random random_a, random_b; { var seed = _random.Next(); random_a = new Random(seed); random_b = new Random(seed); } { for (int i = 0; i < 1024; i++) { var p = random_a.Next(0, 1024 * 256); binaryArray.Set(p, true); } for (int i = 0; i < 1024; i++) { var p = random_b.Next(0, 1024 * 256); Assert.IsTrue(binaryArray.Get(p)); } { int count = 0; for (int i = 0; i < 1024 * 256; i++) { if (binaryArray.Get(i)) { count++; } } Assert.IsTrue(count <= 1024); } } { for (int i = 0; i < 1024 * 256; i++) { binaryArray.Set(i, true); } for (int i = 0; i < 1024; i++) { var p = random_a.Next(0, 1024 * 256); binaryArray.Set(p, false); } for (int i = 0; i < 1024; i++) { var p = random_b.Next(0, 1024 * 256); Assert.IsTrue(!binaryArray.Get(p)); } { int count = 0; for (int i = 0; i < 1024 * 256; i++) { if (!binaryArray.Get(i)) { count++; } } Assert.IsTrue(count <= 1024); } } } }
public void Visit(BinaryArray array) => CompareBinaryArrays <BinaryArray>(array);
public abstract bool get_block_template(BlockTemplate b, AccountPublicAddress adr, ref ulong diffic, ref uint height, BinaryArray ex_nonce);
public void BinaryArraySpanTest() { byte[] byteArray = { 1, 2, 3, 4, 5 }; sbyte[] sbyteArray = { 1, 2, 3, 4, 5 }; char[] charArray = { 'a', 'b', 'c', 'd', 'e' }; Span <byte> testByteSpan = new Span <byte>(byteArray); Span <sbyte> testSByteSpan = new Span <sbyte>(sbyteArray); Span <char> testCharSpan = new Span <char>(charArray); BinaryArray ar = new BinaryArray(); ar.Assign((ReadOnlySpan <byte>)testByteSpan); Assert.AreEqual(5, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i + 1, ar[i]); } ar.Append(testByteSpan); Assert.AreEqual(10, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i % 5 + 1, ar[i]); } ar.Insert(5, testByteSpan); Assert.AreEqual(15, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i % 5 + 1, ar[i]); } ar.Assign(testSByteSpan); Assert.AreEqual(5, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i + 1, ar[i]); } ar.Append(testSByteSpan); Assert.AreEqual(10, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i % 5 + 1, ar[i]); } ar.Insert(5, testSByteSpan); Assert.AreEqual(15, ar.Count); for (int i = 0; i < ar.Count; ++i) { Assert.AreEqual(i % 5 + 1, ar[i]); } ar.Assign(testCharSpan); Assert.AreEqual(10, ar.Count); Assert.AreEqual("abcde", ar.ToString()); ar.Append(testCharSpan); Assert.AreEqual(20, ar.Count); Assert.AreEqual("abcdeabcde", ar.ToString()); ar.Insert(10, testCharSpan); Assert.AreEqual(30, ar.Count); Assert.AreEqual("abcdeabcdeabcde", ar.ToString()); Span <byte> span = new Span <byte>(new byte[30]); ar.ToByteArray(0, span); BinaryArray ar1 = new BinaryArray(span); Assert.AreEqual("abcdeabcdeabcde", ar1.ToString()); Span <byte> span1 = new Span <byte>(new byte[20]); ar1.ToByteArray(10, span1); BinaryArray ar2 = new BinaryArray(span1); Assert.AreEqual("abcdeabcde", ar2.ToString()); }