@@ -147,7 +147,7 @@ public static VBuffer<T> CreateDense<T>(int length)
147
147
/// Applies <paramref name="visitor"/> to every explicitly defined element of the vector,
148
148
/// in order of index.
149
149
/// </summary>
150
- public static void ForEachDefined < T > ( ref VBuffer < T > a , Action < int , T > visitor )
150
+ public static void ForEachDefined < T > ( in ReadOnlyVBuffer < T > a , Action < int , T > visitor )
151
151
{
152
152
Contracts . CheckValue ( visitor , nameof ( visitor ) ) ;
153
153
@@ -573,9 +573,9 @@ public static void CreateMaybeSparseCopy<T>(ref VBuffer<T> src, ref VBuffer<T> d
573
573
/// <param name="src">Argument vector, whose elements are only read</param>
574
574
/// <param name="dst">Argument vector, that could change</param>
575
575
/// <param name="manip">Function to apply to each pair of elements</param>
576
- public static void ApplyWith < TSrc , TDst > ( ref VBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip )
576
+ public static void ApplyWith < TSrc , TDst > ( in ReadOnlyVBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip )
577
577
{
578
- ApplyWithCore ( ref src , ref dst , manip , outer : false ) ;
578
+ ApplyWithCore ( in src , ref dst , manip , outer : false ) ;
579
579
}
580
580
581
581
/// <summary>
@@ -608,9 +608,9 @@ public static void ApplyWithCopy<TSrc, TDst>(ref VBuffer<TSrc> src, ref VBuffer<
608
608
/// <param name="src">Argument vector, whose elements are only read</param>
609
609
/// <param name="dst">Argument vector, that could change</param>
610
610
/// <param name="manip">Function to apply to each pair of elements</param>
611
- public static void ApplyWithEitherDefined < TSrc , TDst > ( ref VBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip )
611
+ public static void ApplyWithEitherDefined < TSrc , TDst > ( in ReadOnlyVBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip )
612
612
{
613
- ApplyWithCore ( ref src , ref dst , manip , outer : true ) ;
613
+ ApplyWithCore ( in src , ref dst , manip , outer : true ) ;
614
614
}
615
615
616
616
/// <summary>
@@ -636,7 +636,7 @@ public static void ApplyWithEitherDefinedCopy<TSrc, TDst>(ref VBuffer<TSrc> src,
636
636
/// where necessary depending on whether this is an inner or outer join of the
637
637
/// indices of <paramref name="src"/> on <paramref name="dst"/>.
638
638
/// </summary>
639
- private static void ApplyWithCore < TSrc , TDst > ( ref VBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip , bool outer )
639
+ private static void ApplyWithCore < TSrc , TDst > ( in ReadOnlyVBuffer < TSrc > src , ref VBuffer < TDst > dst , PairManipulator < TSrc , TDst > manip , bool outer )
640
640
{
641
641
Contracts . Check ( src . Length == dst . Length , "Vectors must have the same dimensionality." ) ;
642
642
Contracts . CheckValue ( manip , nameof ( manip ) ) ;
@@ -773,7 +773,7 @@ private static void ApplyWithCore<TSrc, TDst>(ref VBuffer<TSrc> src, ref VBuffer
773
773
// This is unnecessary -- falling through to the sparse code will
774
774
// actually handle this case just fine -- but it is more efficient.
775
775
Densify ( ref dst ) ;
776
- ApplyWithCore ( ref src , ref dst , manip , outer ) ;
776
+ ApplyWithCore ( src , ref dst , manip , outer ) ;
777
777
return ;
778
778
}
779
779
@@ -892,7 +892,7 @@ private static void ApplyWithCore<TSrc, TDst>(ref VBuffer<TSrc> src, ref VBuffer
892
892
Densify ( ref dst ) ;
893
893
int [ ] indices = dst . Indices ;
894
894
Utils . EnsureSize ( ref indices , src . Count , src . Length , keepOld : false ) ;
895
- Array . Copy ( src . Indices , indices , newCount ) ;
895
+ src . Indices . CopyTo ( indices ) ;
896
896
dst = new VBuffer < TDst > ( src . Length , newCount , dst . Values , indices ) ;
897
897
for ( sI = 0 ; sI < src . Count ; sI ++ )
898
898
manip ( src . Indices [ sI ] , src . Values [ sI ] , ref dst . Values [ sI ] ) ;
@@ -1152,15 +1152,15 @@ private static void ApplyWithCoreCopy<TSrc, TDst>(ref VBuffer<TSrc> src, ref VBu
1152
1152
/// </summary>
1153
1153
/// <seealso cref="ApplyWith{TSrc,TDst}"/>
1154
1154
/// <seealso cref="ApplyWithEitherDefined{TSrc,TDst}"/>
1155
- public static void ApplyIntoEitherDefined < TSrc , TDst > ( ref VBuffer < TSrc > src , ref VBuffer < TDst > dst , Func < int , TSrc , TDst > func )
1155
+ public static void ApplyIntoEitherDefined < TSrc , TDst > ( in ReadOnlyVBuffer < TSrc > src , ref VBuffer < TDst > dst , Func < int , TSrc , TDst > func )
1156
1156
{
1157
1157
Contracts . CheckValue ( func , nameof ( func ) ) ;
1158
1158
1159
1159
// REVIEW: The analogous WritableVector method insisted on
1160
1160
// equal lengths, but I don't care here.
1161
1161
if ( src . Count == 0 )
1162
1162
{
1163
- dst = new VBuffer < TDst > ( src . Length , src . Count , dst . Values , dst . Indices ) ;
1163
+ dst = new VBuffer < TDst > ( src . Length , 0 , dst . Values , dst . Indices ) ;
1164
1164
return ;
1165
1165
}
1166
1166
int [ ] indices = dst . Indices ;
@@ -1174,7 +1174,7 @@ public static void ApplyIntoEitherDefined<TSrc, TDst>(ref VBuffer<TSrc> src, ref
1174
1174
else
1175
1175
{
1176
1176
Utils . EnsureSize ( ref indices , src . Count , src . Length , keepOld : false ) ;
1177
- Array . Copy ( src . Indices , indices , src . Count ) ;
1177
+ src . Indices . CopyTo ( indices ) ;
1178
1178
for ( int i = 0 ; i < src . Count ; ++ i )
1179
1179
values [ i ] = func ( src . Indices [ i ] , src . Values [ i ] ) ;
1180
1180
}
@@ -1189,7 +1189,7 @@ public static void ApplyIntoEitherDefined<TSrc, TDst>(ref VBuffer<TSrc> src, ref
1189
1189
/// necessarily be dense. Otherwise, if both are sparse, the output will be sparse iff
1190
1190
/// there is any slot that is not explicitly represented in either vector.
1191
1191
/// </summary>
1192
- public static void ApplyInto < TSrc1 , TSrc2 , TDst > ( ref VBuffer < TSrc1 > a , ref VBuffer < TSrc2 > b , ref VBuffer < TDst > dst , Func < int , TSrc1 , TSrc2 , TDst > func )
1192
+ public static void ApplyInto < TSrc1 , TSrc2 , TDst > ( in ReadOnlyVBuffer < TSrc1 > a , in ReadOnlyVBuffer < TSrc2 > b , ref VBuffer < TDst > dst , Func < int , TSrc1 , TSrc2 , TDst > func )
1193
1193
{
1194
1194
Contracts . Check ( a . Length == b . Length , "Vectors must have the same dimensionality." ) ;
1195
1195
Contracts . CheckValue ( func , nameof ( func ) ) ;
@@ -1277,7 +1277,7 @@ public static void ApplyInto<TSrc1, TSrc2, TDst>(ref VBuffer<TSrc1> a, ref VBuff
1277
1277
if ( newCount == a . Count )
1278
1278
{
1279
1279
// Case 3, a and b actually have the same indices!
1280
- Array . Copy ( a . Indices , indices , a . Count ) ;
1280
+ a . Indices . CopyTo ( indices ) ;
1281
1281
for ( aI = 0 ; aI < a . Count ; aI ++ )
1282
1282
{
1283
1283
Contracts . Assert ( a . Indices [ aI ] == b . Indices [ aI ] ) ;
@@ -1287,7 +1287,7 @@ public static void ApplyInto<TSrc1, TSrc2, TDst>(ref VBuffer<TSrc1> a, ref VBuff
1287
1287
else
1288
1288
{
1289
1289
// Case 4, a's indices are a subset of b's.
1290
- Array . Copy ( b . Indices , indices , b . Count ) ;
1290
+ b . Indices . CopyTo ( indices ) ;
1291
1291
aI = 0 ;
1292
1292
for ( bI = 0 ; aI < a . Count && bI < b . Count ; bI ++ )
1293
1293
{
@@ -1302,7 +1302,7 @@ public static void ApplyInto<TSrc1, TSrc2, TDst>(ref VBuffer<TSrc1> a, ref VBuff
1302
1302
else if ( newCount == a . Count )
1303
1303
{
1304
1304
// Case 5, b's indices are a subset of a's.
1305
- Array . Copy ( a . Indices , indices , a . Count ) ;
1305
+ a . Indices . CopyTo ( indices ) ;
1306
1306
bI = 0 ;
1307
1307
for ( aI = 0 ; bI < b . Count && aI < a . Count ; aI ++ )
1308
1308
{
0 commit comments