CurtHagenlocher commented on code in PR #40189:
URL: https://github.com/apache/arrow/pull/40189#discussion_r1537723184


##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -253,14 +255,99 @@ public TBuilder Resize(int length)
 
             public TBuilder Swap(int i, int j)
             {
-                // TODO: Implement
-                throw new NotImplementedException();
+                // Retrieve byte arrays for elements i and j
+                var iBytes = GetValueBytes(i);
+                var jBytes = GetValueBytes(j);
+
+                Set(i, jBytes);
+                Set(j, iBytes);
+
+                ValidityBuffer.Swap(i, j);
+                return Instance;
             }
 
+
             public TBuilder Set(int index, byte value)
             {
-                // TODO: Implement
-                throw new NotImplementedException();
+                int currentStart = ValueOffsets.Span[index];
+                int currentEnd = ValueOffsets.Span[index + 1];
+                int newEnd = currentStart + 1;
+
+                int currentLength = currentEnd - currentStart;
+                int newSize = 1;
+                int diffSize = currentLength - newSize;
+                if (currentLength != 1)
+                {
+                    ValueBuffer.Span.Slice(currentStart, 
currentLength).Clear();
+                    ValueBuffer.Span[currentStart] = value;
+                    ValueBuffer.Span.Slice(currentEnd, Length - currentEnd)
+                        .CopyTo(ValueBuffer.Span.Slice(newEnd, Length - 
newEnd));
+                    ValueBuffer.Span.Slice(Length - diffSize, 
diffSize).Clear();
+                    AdjustOffsets(index, currentLength - 1);
+                }
+
+                ValueBuffer.Span[index] = value;
+                ValidityBuffer.Set(index);
+                return Instance;
+            }
+
+            public TBuilder Set(int index, ReadOnlySpan<byte> bytes)
+            {
+                int startOffset = ValueOffsets.Span[index];
+                int newLength = bytes.Length;
+                bool isNull = bytes.IsEmpty;

Review Comment:
   I don't think this code uses an empty span to mean null; an empty span is 
just a value of length zero.



##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -19,6 +19,8 @@
 using System.Runtime.CompilerServices;
 using Apache.Arrow.Memory;
 using System.Collections;
+using System.ComponentModel.Design;
+using System.Threading.Tasks.Sources;

Review Comment:
   I suspect that these aren't needed. If you're using VS2022, it's extremely 
trigger-happy about adding "using" statements.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to