This is an automated email from the ASF dual-hosted git repository.

vaughn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d524760e chore: cmn algorithm optimization (#2134)
1d524760e is described below

commit 1d524760ebb6181ebbefee3a263d3cc02031b03f
Author: vaughn <[email protected]>
AuthorDate: Wed Mar 1 08:19:04 2023 +0800

    chore: cmn algorithm optimization (#2134)
---
 .../org/apache/hugegraph/backend/tx/GraphIndexTransaction.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
 
b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
index 3bf9a7c81..f4ff8b32e 100644
--- 
a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
+++ 
b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
@@ -1120,13 +1120,18 @@ public class GraphIndexTransaction extends 
AbstractTransaction {
             result = new ArrayList<>(n);
         }
 
+        int index = result.size();
         if (m == n) {
             result.addAll(all.subList(current, all.size()));
             n = 0;
         }
         if (n == 0) {
             // All n items are selected
-            return callback.apply(result);
+            Boolean apply = callback.apply(result);
+            while (index < result.size()) {
+                result.remove(index);
+            }
+            return apply;
         }
         if (current >= all.size()) {
             // Reach the end of items
@@ -1134,7 +1139,6 @@ public class GraphIndexTransaction extends 
AbstractTransaction {
         }
 
         // Select current item, continue to select C(m-1, n-1)
-        int index = result.size();
         result.add(all.get(current));
         if (cmn(all, m - 1, n - 1, ++current, result, callback)) {
             return true;

Reply via email to