You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "ifesdjeen (via GitHub)" <gi...@apache.org> on 2025/03/10 14:05:25 UTC

[PR] Fix serializers [cassandra-accord]

ifesdjeen opened a new pull request, #179:
URL: https://github.com/apache/cassandra-accord/pull/179

   (no comment)


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Fix serializers [cassandra-accord]

Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #179:
URL: https://github.com/apache/cassandra-accord/pull/179#discussion_r1988910940


##########
accord-core/src/main/java/accord/utils/SortedArrays.java:
##########
@@ -447,6 +447,93 @@ else if (cmp < 0)
         }
     }
 
+    // applies the update function to all entries in left, and any matching entries in right
+    public static <O, T extends O> O[] linearUpdate(T[] left, int leftStart, int leftEnd, T[] right, int rightStart, int rightEnd, AsymmetricComparator<? super T, ? super T> comparator, BiFunction<? super T, ? super T, ? extends T> update, ObjectBuffers<O> buffers)
+    {
+        int leftIdx = leftStart;
+        int rightIdx = rightStart;
+
+        T nextKey = null;
+        while (leftIdx < leftEnd && rightIdx < rightEnd)
+        {
+            T leftKey = left[leftIdx];
+            T rightKey = right[rightIdx];
+            int cmp = leftKey == rightKey ? 0 : comparator.compare(leftKey, rightKey);
+            if (cmp > 0)
+            {
+                ++rightIdx;
+                continue;
+            }
+
+            if (cmp < 0) rightKey = null;
+            else ++rightIdx;
+
+            T testKey = update.apply(leftKey, rightKey);
+            if (testKey != leftKey)
+            {
+                nextKey = testKey;
+                break;
+            }
+            ++leftIdx;
+        }
+
+        if (nextKey == null)
+        {
+            while (leftIdx < leftEnd)
+            {
+                T leftKey = left[leftIdx];
+                T testKey = update.apply(left[leftIdx], null);
+                if (testKey != leftKey)
+                {
+                    nextKey = testKey;
+                    break;
+                }
+                ++leftIdx;
+            }
+
+            if (nextKey == null)
+                return left;
+        }
+
+        O[] result = buffers.get(leftEnd - leftStart);
+        int resultSize = leftIdx - leftStart;
+        System.arraycopy(left, leftStart, result, 0, resultSize);
+        result[resultSize++] = nextKey;
+        ++leftIdx;
+
+        try
+        {
+            while (leftIdx < leftEnd && rightIdx < rightEnd)
+            {
+                T leftKey = left[leftIdx];
+                T rightKey = right[rightIdx];
+                int cmp = leftKey == rightKey ? 0 : comparator.compare(leftKey, rightKey);
+
+                if (cmp > 0)
+                {
+                    ++rightIdx;
+                    continue;
+                }
+
+                if (cmp < 0) rightKey = null;
+                else ++rightIdx;
+                ++leftIdx;
+
+                result[resultSize++] = update.apply(leftKey, rightKey);
+            }
+
+            while (leftIdx < leftEnd)

Review Comment:
   Just to make sure: do we always know that left is longer than right?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Fix serializers [cassandra-accord]

Posted by "belliottsmith (via GitHub)" <gi...@apache.org>.
belliottsmith commented on code in PR #179:
URL: https://github.com/apache/cassandra-accord/pull/179#discussion_r1989046283


##########
accord-core/src/main/java/accord/utils/SortedArrays.java:
##########
@@ -447,6 +447,93 @@ else if (cmp < 0)
         }
     }
 
+    // applies the update function to all entries in left, and any matching entries in right
+    public static <O, T extends O> O[] linearUpdate(T[] left, int leftStart, int leftEnd, T[] right, int rightStart, int rightEnd, AsymmetricComparator<? super T, ? super T> comparator, BiFunction<? super T, ? super T, ? extends T> update, ObjectBuffers<O> buffers)
+    {
+        int leftIdx = leftStart;
+        int rightIdx = rightStart;
+
+        T nextKey = null;
+        while (leftIdx < leftEnd && rightIdx < rightEnd)
+        {
+            T leftKey = left[leftIdx];
+            T rightKey = right[rightIdx];
+            int cmp = leftKey == rightKey ? 0 : comparator.compare(leftKey, rightKey);
+            if (cmp > 0)
+            {
+                ++rightIdx;
+                continue;
+            }
+
+            if (cmp < 0) rightKey = null;
+            else ++rightIdx;
+
+            T testKey = update.apply(leftKey, rightKey);
+            if (testKey != leftKey)
+            {
+                nextKey = testKey;
+                break;
+            }
+            ++leftIdx;
+        }
+
+        if (nextKey == null)
+        {
+            while (leftIdx < leftEnd)
+            {
+                T leftKey = left[leftIdx];
+                T testKey = update.apply(left[leftIdx], null);
+                if (testKey != leftKey)
+                {
+                    nextKey = testKey;
+                    break;
+                }
+                ++leftIdx;
+            }
+
+            if (nextKey == null)
+                return left;
+        }
+
+        O[] result = buffers.get(leftEnd - leftStart);
+        int resultSize = leftIdx - leftStart;
+        System.arraycopy(left, leftStart, result, 0, resultSize);
+        result[resultSize++] = nextKey;
+        ++leftIdx;
+
+        try
+        {
+            while (leftIdx < leftEnd && rightIdx < rightEnd)
+            {
+                T leftKey = left[leftIdx];
+                T rightKey = right[rightIdx];
+                int cmp = leftKey == rightKey ? 0 : comparator.compare(leftKey, rightKey);
+
+                if (cmp > 0)
+                {
+                    ++rightIdx;
+                    continue;
+                }
+
+                if (cmp < 0) rightKey = null;
+                else ++rightIdx;
+                ++leftIdx;
+
+                result[resultSize++] = update.apply(leftKey, rightKey);
+            }
+
+            while (leftIdx < leftEnd)

Review Comment:
   we don't, we just don't care if right is longer than left - this is meant to be like a left join; we only care about those items on the right that match those on the left.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Fix serializers [cassandra-accord]

Posted by "belliottsmith (via GitHub)" <gi...@apache.org>.
belliottsmith merged PR #179:
URL: https://github.com/apache/cassandra-accord/pull/179


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org