diff --git a/src/DataStreamSuite/DataStream/BlueOrb/BlueAddIndexColumnTable.cs b/src/DataStreamSuite/DataStream/BlueOrb/BlueAddIndexColumnTable.cs index fa3b4d303..016a99f91 100644 --- a/src/DataStreamSuite/DataStream/BlueOrb/BlueAddIndexColumnTable.cs +++ b/src/DataStreamSuite/DataStream/BlueOrb/BlueAddIndexColumnTable.cs @@ -69,7 +69,7 @@ public class BlueAddIndexColumnTable : IBlueRowCollection { columnValues[idColIdx.Value] = idColValues; break; case -1: - columnValues = ArrayHelper.InsertExact(columnValues, idColIdx.Value, true, idColValues); + columnValues = ArrayUtils.InsertExact(columnValues, idColIdx.Value, true, idColValues); break; default: throw new ArgumentException("ColumnInfos length disagrees with columnValues length"); @@ -85,7 +85,7 @@ public class BlueAddIndexColumnTable : IBlueRowCollection { var c = origColInfos[i - 1]; columnInfos[i] = new(c.colName, c.colNo + 1, c.colType); } - columnValues = ArrayHelper.InsertExact(columnValues, 0, true, idColValues); + columnValues = ArrayUtils.InsertExact(columnValues, 0, true, idColValues); } return new(new BlueTableSchema(schema.tableName, columnInfos), columnValues); } diff --git a/src/DataStreamSuite/DataStream/BlueOrb/TimeSeriesStream.cs b/src/DataStreamSuite/DataStream/BlueOrb/TimeSeriesStream.cs index c1eb9ab60..b60a6c693 100644 --- a/src/DataStreamSuite/DataStream/BlueOrb/TimeSeriesStream.cs +++ b/src/DataStreamSuite/DataStream/BlueOrb/TimeSeriesStream.cs @@ -56,7 +56,7 @@ namespace bts.BlueOrb { colInfos = colInfos.ToArray(); colInfos[currTimeColIdx] = new(timeColumn, currTimeCol.colNo, typeof(DateTime)); } else { - colInfos = ArrayHelper.add(colInfos, new(timeColumn, colInfos.Length, typeof(DateTime))); + colInfos = ArrayUtils.Add(colInfos, new(timeColumn, colInfos.Length, typeof(DateTime))); } _table = new CircularBufferTable(new BlueTableSchema(colInfos, dp.newRows.schema.tableName), _size); } diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/BlueColumnTable.cs b/src/DataStreamSuite/DataStreamCore/BlueData/BlueColumnTable.cs index cf7ace1cd..757f32365 100644 --- a/src/DataStreamSuite/DataStreamCore/BlueData/BlueColumnTable.cs +++ b/src/DataStreamSuite/DataStreamCore/BlueData/BlueColumnTable.cs @@ -92,7 +92,7 @@ public class BlueColumnTable : IBlueRowCollection { idx = ~idx; for (int i = 0; i < columns.Length; i++) { int len = rowIds.Count; - ArrayHelper.Insert(ref columns[i], idx, values[i], ref len); + ArrayUtils.Insert(ref columns[i], idx, values[i], ref len); } rowIds.Insert(idx, id); } @@ -111,7 +111,7 @@ public class BlueColumnTable : IBlueRowCollection { int len; for (int i = 0; i < columns.Length; i++) { len = rowIds.Count; - ArrayHelper.Insert(ref columns[i], idx, values[i], ref len); + ArrayUtils.Insert(ref columns[i], idx, values[i], ref len); } rowIds.Insert(idx, id); } @@ -126,14 +126,14 @@ public class BlueColumnTable : IBlueRowCollection { } rowIds.RemoveAt(idx); for (int i = 0; i < columns.Length; i++) { - ArrayHelper.remove_at(ref columns[i], idx); + ArrayUtils.RemoveAt(ref columns[i], idx); } return true; } public void Trim() { for (int i = 0; i < columns.Length; i++) { - ArrayHelper.trim(ref columns[i], rowIds.Count); + ArrayUtils.Trim(ref columns[i], rowIds.Count); } } diff --git a/src/DataStreamSuite/PubSub/Misc/WorkScheduler.cs b/src/DataStreamSuite/PubSub/Misc/WorkScheduler.cs index 6c535f861..77436f35a 100644 --- a/src/DataStreamSuite/PubSub/Misc/WorkScheduler.cs +++ b/src/DataStreamSuite/PubSub/Misc/WorkScheduler.cs @@ -57,13 +57,13 @@ public class WorkScheduler : IWorkScheduler, IDisposable { public void Add(IWorker worker, TimeSpan interval) { using var _ = gate.BeginTransaction(); - workers = ArrayHelper.add(workers, new(worker, interval)); + workers = ArrayUtils.Add(workers, new(worker, interval)); } public void Remove(IWorker worker) { using var _ = gate.BeginTransaction(); if (workers.WrapSelector(w => w.Worker, null).TryFindIndex(worker, out var i)) { - workers = ArrayHelper.RemoveAt(workers, i); + workers = ArrayUtils.RemoveAt(workers, i); } } diff --git a/src/client/spark/Daemons/ErrorReporter.cs b/src/client/spark/Daemons/ErrorReporter.cs index 6a14bd25a..ab9546a74 100644 --- a/src/client/spark/Daemons/ErrorReporter.cs +++ b/src/client/spark/Daemons/ErrorReporter.cs @@ -180,7 +180,7 @@ namespace bts.spark { string title) { // try { - var results = await Task.WhenAll(execute as Task[] ?? ArrayHelper.clone_optimized(execute)); + var results = await Task.WhenAll(execute as Task[] ?? ArrayUtils.CloneOptimized(execute)); var result_values = new (TResult, string)[results.Length]; StringBuilder error_bd = null; for (int i = 0; i < results.Length; i++) { diff --git a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs index 89865be1e..e19168aa2 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs @@ -336,9 +336,9 @@ namespace mbts.spark { readonly AlgoPersistedKey[] _auto_revert_algos; public LadderFavoriteAlgosSettings(AlgoKey[] favorite_algos, int column_count, AlgoKey[] stickied_algos, AlgoKey[] auto_revert_algos) - : this(ArrayHelper.safe_convert(favorite_algos, k => new AlgoPersistedKey(k.persisted)), - ArrayHelper.safe_convert(stickied_algos, k => new AlgoPersistedKey(k.persisted)), - ArrayHelper.safe_convert(auto_revert_algos, k => new AlgoPersistedKey(k.persisted)), + : this(ArrayUtils.safe_convert(favorite_algos, k => new AlgoPersistedKey(k.persisted)), + ArrayUtils.safe_convert(stickied_algos, k => new AlgoPersistedKey(k.persisted)), + ArrayUtils.safe_convert(auto_revert_algos, k => new AlgoPersistedKey(k.persisted)), column_count) { } LadderFavoriteAlgosSettings(AlgoPersistedKey[] favorite_algos, AlgoPersistedKey[] stickied_algos, AlgoPersistedKey[] auto_revert_algos, int column_count) { diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs index 2643231ca..9a6a74f9a 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs @@ -824,7 +824,7 @@ namespace bts.shell.pnl { if (filter.security_criteria is null) { filter.security_criteria = SecurityCriteria.from_expirations(exp); } else { - filter.security_criteria.clauses = ArrayHelper.add( + filter.security_criteria.clauses = ArrayUtils.add( filter.security_criteria.clauses, SecurityCriteriaClause.from_expirations(exp)); } } diff --git a/src/client/spark/core/Collections/ObservableAutoWrapper.cs b/src/client/spark/core/Collections/ObservableAutoWrapper.cs index 29786c1d0..96d6af915 100644 --- a/src/client/spark/core/Collections/ObservableAutoWrapper.cs +++ b/src/client/spark/core/Collections/ObservableAutoWrapper.cs @@ -317,7 +317,7 @@ namespace mbts.ui.utility { } break; case NotifyCollectionChangedAction.Reset: - ArrayHelper.ensure_capacity(ref _values, _src_collection.Count); + ArrayUtils.EnsureCapacity(ref _values, _src_collection.Count); if (_size > _src_collection.Count) { Array.Clear(_values, _src_collection.Count, _size - _src_collection.Count); } @@ -341,7 +341,7 @@ namespace mbts.ui.utility { IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); int _assert_remove(T value) { - ArrayHelper.remove_sorted(ref _values, ref _size, value, _comparer, out int? pos); + ArrayUtils.RemoveSorted(ref _values, ref _size, value, _comparer, out int? pos); if (!pos.HasValue) throw new InvalidOperationException("Failed to remove value, SortedWrapper is now out of sync with its source."); return pos.Value; @@ -353,7 +353,7 @@ namespace mbts.ui.utility { } int _add(T value) { - ArrayHelper.add_sorted(ref _values, ref _size, value, _comparer, out int pos); + ArrayUtils.AddSorted(ref _values, ref _size, value, _comparer, out int pos); return pos; } diff --git a/src/client/spark/core/Utility/PropertyChangeDetector.cs b/src/client/spark/core/Utility/PropertyChangeDetector.cs index 59c42ebd4..5bd5a6b48 100644 --- a/src/client/spark/core/Utility/PropertyChangeDetector.cs +++ b/src/client/spark/core/Utility/PropertyChangeDetector.cs @@ -70,7 +70,7 @@ _property_monitors[pm_pos++] = (pad.prop_info.Name, initialize, refresh); } } - ArrayHelper.trim(ref _property_monitors, pm_pos); + ArrayUtils.Trim(ref _property_monitors, pm_pos); } public IDisposable detect_changes(T target) { diff --git a/src/client/spark/view/Converters/PartialConverter.cs b/src/client/spark/view/Converters/PartialConverter.cs index 684001b8f..a76fb73fb 100644 --- a/src/client/spark/view/Converters/PartialConverter.cs +++ b/src/client/spark/view/Converters/PartialConverter.cs @@ -22,7 +22,7 @@ namespace mbts.ui.converters { break; default: if (values[0] is IMultiValueConverter mvc) { - ArrayHelper.remove_at(ref values, 0); + ArrayUtils.remove_at(ref values, 0); return mvc.Convert(values, targetType, parameter, culture); } break; diff --git a/src/client/spark_api/Orders/AlgoDefinitionPersistedMetadata.cs b/src/client/spark_api/Orders/AlgoDefinitionPersistedMetadata.cs index 0d8c810d0..2b1651ce6 100644 --- a/src/client/spark_api/Orders/AlgoDefinitionPersistedMetadata.cs +++ b/src/client/spark_api/Orders/AlgoDefinitionPersistedMetadata.cs @@ -47,7 +47,7 @@ namespace bts.persist.algo { public IReadOnlyList favorite_templates => _favorite_templates ?? Array.Empty(); public AlgoDefinitionMetadata to_definition_data() => - new AlgoDefinitionMetadata(id.to_algo_key(), default_template.to_algo_key(), ArrayHelper.safe_convert(_favorite_templates, k => k.to_algo_key()), is_favorite, is_hidden, abbreviation, badge_color.value); + new AlgoDefinitionMetadata(id.to_algo_key(), default_template.to_algo_key(), ArrayUtils.SafeConvert(_favorite_templates, k => k.to_algo_key()), is_favorite, is_hidden, abbreviation, badge_color.value); public AlgoDefinitionPersistedMetadata with(AlgoPersistedKey? default_template = null, IEnumerable favorite_templates = null, bool? is_favorite = null, bool? is_hidden = null, string abbreviation = null, NullableColorProto? badge_color = null) => new AlgoDefinitionPersistedMetadata(id, diff --git a/src/client/spark_core/Collections/ArrayList.cs b/src/client/spark_core/Collections/ArrayList.cs index 4449f0f50..9bf10f047 100644 --- a/src/client/spark_core/Collections/ArrayList.cs +++ b/src/client/spark_core/Collections/ArrayList.cs @@ -32,7 +32,7 @@ public class ArrayList : IList { public bool IsReadOnly => false; public void Add(T item) => - ArrayHelper.Add(ref items, item, ref count); + ArrayUtils.Add(ref items, item, ref count); public void Clear() => count = 0; @@ -60,19 +60,19 @@ public class ArrayList : IList { } public void Insert(int index, T item) => - ArrayHelper.Insert(ref items, index, item, ref count); + ArrayUtils.Insert(ref items, index, item, ref count); public bool Remove(T item) { int idx = IndexOf(item); if (idx == -1) { return false; } - ArrayHelper.remove_at(ref items, ref count, idx); + ArrayUtils.RemoveAt(ref items, idx, ref count); return true; } public void RemoveAt(int index) => - ArrayHelper.remove_at(ref items, ref count, index); + ArrayUtils.RemoveAt(ref items, index, ref count); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/src/client/spark_core/Collections/CircularBuffer.cs b/src/client/spark_core/Collections/CircularBuffer.cs index cec8ddc86..7a8294c07 100644 --- a/src/client/spark_core/Collections/CircularBuffer.cs +++ b/src/client/spark_core/Collections/CircularBuffer.cs @@ -252,7 +252,7 @@ public class CircularBuffer : IList, IReadOnlyList { if (idx < origin) { origin--; } - ArrayHelper.remove_at(ref items, ref count, idx); + ArrayUtils.RemoveAt(ref items, idx, ref count); return true; } @@ -263,7 +263,7 @@ public class CircularBuffer : IList, IReadOnlyList { index -= count; origin--; } - ArrayHelper.remove_at(ref items, ref count, index); + ArrayUtils.RemoveAt(ref items, index, ref count); } public void RemoveRange(int index, int count) { @@ -276,14 +276,14 @@ public class CircularBuffer : IList, IReadOnlyList { int rem = this.count - origin; if (index < rem) { if (count < rem) { - ArrayHelper.RemoveRange(ref items, origin + index, count); + ArrayUtils.RemoveRange(ref items, origin + index, count); } else { - ArrayHelper.RemoveRange(ref items, origin + index, rem); - ArrayHelper.RemoveRange(ref items, 0, count - rem); + ArrayUtils.RemoveRange(ref items, origin + index, rem); + ArrayUtils.RemoveRange(ref items, 0, count - rem); origin -= count - rem; } } else { - ArrayHelper.RemoveRange(ref items, index - rem, count); + ArrayUtils.RemoveRange(ref items, index - rem, count); } this.count -= count; } diff --git a/src/client/spark_core/Collections/ObservableSortedCollection.cs b/src/client/spark_core/Collections/ObservableSortedCollection.cs index 753e43c98..dc601dad3 100644 --- a/src/client/spark_core/Collections/ObservableSortedCollection.cs +++ b/src/client/spark_core/Collections/ObservableSortedCollection.cs @@ -101,7 +101,7 @@ namespace Spark.Core.Collections { CollectionHelper.binary_search(_values, item, 0, _size, _comparer, _eq_comparer); void _insert_and_notify(int index, T item) { - ArrayHelper.Insert(ref _values, index, item, ref _size); + ArrayUtils.Insert(ref _values, index, item, ref _size); CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(CollectionHelper.indexer_name)); @@ -110,10 +110,10 @@ namespace Spark.Core.Collections { void _remove_and_notify(int index) { var cc = CollectionChanged; if (cc == null) { - ArrayHelper.remove_at(ref _values, ref _size, index); + ArrayUtils.RemoveAt(ref _values, index, ref _size); } else { var old_item = _values[index]; - ArrayHelper.remove_at(ref _values, ref _size, index); + ArrayUtils.RemoveAt(ref _values, index, ref _size); cc(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, old_item, index)); } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); diff --git a/src/client/spark_core/Strings/DisplayNameHelper.cs b/src/client/spark_core/Strings/DisplayNameHelper.cs index 4da05f508..9b1b2bed2 100644 --- a/src/client/spark_core/Strings/DisplayNameHelper.cs +++ b/src/client/spark_core/Strings/DisplayNameHelper.cs @@ -174,7 +174,7 @@ namespace mbts.ui.utilities { char[] numeric_chars = new char[0]; int len = 0; while ((pos + len) < str.Length && _is_numeric_related(str[pos + len])) { - ArrayHelper.ensure_capacity(ref numeric_chars, len + 1); + ArrayUtils.EnsureCapacity(ref numeric_chars, len + 1); numeric_chars[len] = str[pos + len]; len++; } diff --git a/src/client/spark_core/utils/ArrayUtils.cs b/src/client/spark_core/utils/ArrayUtils.cs index 74818d8f9..7c2d652cc 100644 --- a/src/client/spark_core/utils/ArrayUtils.cs +++ b/src/client/spark_core/utils/ArrayUtils.cs @@ -5,8 +5,8 @@ using System.Collections; using System.Collections.Generic; namespace bts.utils { - public static class ArrayHelper { - public static void trim(ref T[] array, int size) { + public static class ArrayUtils { + public static void Trim(ref T[] array, int size) { if (array.Length > size) { T[] trimmed = new T[size]; Array.Copy(array, trimmed, size); @@ -14,16 +14,16 @@ namespace bts.utils { } } - public static void ensure_capacity(ref T[] array, int min) { + public static void EnsureCapacity(ref T[] array, int min) { if (array.Length < min) { int twice_cap = array.Length * 2; - expand(ref array, min > twice_cap ? min : twice_cap); + Expand(ref array, min > twice_cap ? min : twice_cap); } } - public static void expand(ref T[] array) => expand(ref array, array.Length * 2); + public static void Expand(ref T[] array) => Expand(ref array, array.Length * 2); - public static void expand(ref T[] array, int new_capacity) { + public static void Expand(ref T[] array, int new_capacity) { if (array.Length < new_capacity) { T[] expanded = new T[new_capacity]; Array.Copy(array, expanded, array.Length); @@ -31,7 +31,7 @@ namespace bts.utils { } } - public static TResult[] safe_convert(T[] array, Func convert) => + public static TResult[] SafeConvert(T[] array, Func convert) => array == null ? Array.Empty() : Array.ConvertAll(array, new Converter(convert)); public static TResult[] convert(ICollection source, Func convert) { @@ -42,7 +42,7 @@ namespace bts.utils { return array; } - public static T[] clone(T[] array) { + public static T[] Clone(T[] array) { T[] rv = new T[array.Length]; Array.Copy(array, rv, array.Length); return rv; @@ -57,7 +57,7 @@ namespace bts.utils { /// The type of elements. /// The source that will be copied to the resultant array. /// An array containing the elements from the specified source. - public static T[] clone_optimized(IEnumerable source) { + public static T[] CloneOptimized(IEnumerable source) { if (source == null) return Array.Empty(); T[] result; @@ -81,10 +81,10 @@ namespace bts.utils { result = new[] { en.Current }; i = 1; while (en.MoveNext()) { - ensure_capacity(ref result, i + 1); + EnsureCapacity(ref result, i + 1); result[i++] = en.Current; } - trim(ref result, i); + Trim(ref result, i); } else { return Array.Empty(); } @@ -164,9 +164,9 @@ namespace bts.utils { return rv; } - public static void remove_at(ref T[] array, int index) { + public static void RemoveAt(ref T[] array, int index) { int sz = array.Length; - remove_at(ref array, ref sz, index); + RemoveAt(ref array, index, ref sz); } public static T[] RemoveAt(T[] array, int index) { @@ -179,7 +179,7 @@ namespace bts.utils { return rv; } - public static void remove_at(ref T[] array, ref int size, int index) { + public static void RemoveAt(ref T[] array, int index, ref int size) { // validate size/index if (size < 0) throw ExceptionBuilder.ArgumentOutOfRange.lt_zero(nameof(size)); @@ -226,7 +226,7 @@ namespace bts.utils { } } - public static void remove_sorted(ref T[] array, ref int size, T value, IComparer comparer, out int? pos) { + public static void RemoveSorted(ref T[] array, ref int size, T value, IComparer comparer, out int? pos) { int p = Array.BinarySearch(array, 0, size, value, comparer); if (p < 0) { pos = null; @@ -238,7 +238,7 @@ namespace bts.utils { } } - public static T[] add(T[] array, T value) { + public static T[] Add(T[] array, T value) { T[] clone = new T[array.Length + 1]; Array.Copy(array, clone, array.Length); clone[array.Length] = value; @@ -267,7 +267,7 @@ namespace bts.utils { public static void add_sorted(ref T[] array, ref int size, T value, IComparer comparer, out int pos) { pos = peek_sorted_index(array, size, value, comparer); - ensure_capacity(ref array, size + 1); + EnsureCapacity(ref array, size + 1); Array.Copy(array, pos, array, pos + 1, size - pos); array[pos] = value; size++; diff --git a/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs b/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs index d5e4b5329..295707a38 100644 --- a/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs +++ b/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs @@ -31,7 +31,7 @@ public class JsonRpcRequestAsyncEnumerable { yield return req; } } else if (offset == buffer.Length) { - ArrayHelper.expand(ref buffer, buffer.Length * 2); + ArrayUtils.Expand(ref buffer, buffer.Length * 2); } } diff --git a/src/client/spark_websocket/JsonRpc/JsonRpcRequestObservable.cs b/src/client/spark_websocket/JsonRpc/JsonRpcRequestObservable.cs index c06384ed2..5ce26ce1f 100644 --- a/src/client/spark_websocket/JsonRpc/JsonRpcRequestObservable.cs +++ b/src/client/spark_websocket/JsonRpc/JsonRpcRequestObservable.cs @@ -43,7 +43,7 @@ public class JsonRpcRequestObservable { observer.OnNext(req); } } else if (offset == buffer.Length) { - ArrayHelper.expand(ref buffer, buffer.Length * 2); + ArrayUtils.Expand(ref buffer, buffer.Length * 2); } } }