You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/07/24 21:45:38 UTC

[GitHub] [calcite] zabetak commented on a change in pull request #2080: [CALCITE-3920] Improve ORDER BY computation in Enumerable convention by exploiting LIMIT

zabetak commented on a change in pull request #2080:
URL: https://github.com/apache/calcite/pull/2080#discussion_r460301691



##########
File path: linq4j/src/main/java/org/apache/calcite/linq4j/TopNHeap.java
##########
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.linq4j;
+
+import org.apache.calcite.linq4j.function.Function1;
+
+import java.util.Comparator;
+
+/**
+ * Implementation of a stable binary heap with a fetch and an offset.
+ * Stable means that if two items are considered equal,
+ * they will appear in the same order as they were offered to the heap.
+ *
+ * @param <TSource> type of the element that will be added to the heap
+ * @param <TKey> type of the key, which the comparator will use for comparisons
+ */
+public class TopNHeap<TSource, TKey> {

Review comment:
       I had the same question with @julianhyde :) Apart from the priority queues I had also in mind a plain `TreeMap`. I did some preliminary benchmarks at some point (WIP in https://github.com/zabetak/jmh-micro-benchmarks/blob/master/core-java/src/main/java/com/github/zabetak/benchmark/PartialSortBenchmark.java) and `TreeMap` was not bad at all. Plus the risk for bugs is much smaller. 




----------------------------------------------------------------
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.

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