-
Notifications
You must be signed in to change notification settings - Fork 102
Optimize DataSetWithoutTimeGenerator with primitive long heap/set #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hongzhi-gao
merged 5 commits into
develop
from
optimize/dataset-without-time-generator-primitive-heap
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b9cc9f
Optimize DataSetWithoutTimeGenerator with primitive long heap/set
hongzhi-gao 9137ad8
Fix spotless formatting for LongOpenHashSet and LongHeapPriorityQueue
hongzhi-gao fd2bd72
Address review: use Set.add return value and gate perf test
hongzhi-gao ac902c7
Add fastutil license attribution for derived heap and hash set
hongzhi-gao 17dcc8d
Remove fastutil attribution from NOTICE
hongzhi-gao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
java/tsfile/src/main/java/org/apache/tsfile/utils/LongHeapPriorityQueue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * 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.tsfile.utils; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.NoSuchElementException; | ||
|
|
||
| /** | ||
| * A type-specific heap-based priority queue for {@code long} values (natural order). | ||
| * | ||
| * <p>Copied and trimmed from fastutil 8.5.8 (Apache License 2.0, http://fastutil.di.unimi.it/): | ||
| * | ||
| * <ul> | ||
| * <li>{@code it.unimi.dsi.fastutil.longs.LongHeapPriorityQueue} | ||
| * <li>{@code it.unimi.dsi.fastutil.longs.LongHeaps} ({@code upHeap}/{@code downHeap} | ||
| * natural-order branches inlined below) | ||
| * </ul> | ||
| * | ||
| * <p>Comparator / serialization / collection constructors were dropped. Array growth uses {@link | ||
| * Arrays#copyOf} instead of fastutil {@code LongArrays#grow}. | ||
| * | ||
| * <p>Copyright (C) 2003-2022 Paolo Boldi and Sebastiano Vigna | ||
| */ | ||
| public class LongHeapPriorityQueue { | ||
|
|
||
| private static final long[] EMPTY = new long[0]; | ||
|
|
||
| /** The heap array. Copied from fastutil {@code LongHeapPriorityQueue#heap}. */ | ||
| private long[] heap = EMPTY; | ||
|
|
||
| /** | ||
| * The number of elements in this queue. Copied from fastutil {@code LongHeapPriorityQueue#size}. | ||
| */ | ||
| private int size; | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue(int)} (natural order only). */ | ||
| public LongHeapPriorityQueue(int capacity) { | ||
| if (capacity > 0) { | ||
| this.heap = new long[capacity]; | ||
| } | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue()}. */ | ||
| public LongHeapPriorityQueue() { | ||
| this(0); | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue#enqueue(long)}. */ | ||
| public void enqueue(long x) { | ||
| if (size == heap.length) { | ||
| heap = grow(heap, size + 1); | ||
| } | ||
| heap[size++] = x; | ||
| upHeap(heap, size, size - 1); | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue#dequeueLong()}. */ | ||
| public long dequeueLong() { | ||
| if (size == 0) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
| final long result = heap[0]; | ||
| heap[0] = heap[--size]; | ||
| if (size != 0) { | ||
| downHeap(heap, size, 0); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue#firstLong()}. */ | ||
| public long firstLong() { | ||
| if (size == 0) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
| return heap[0]; | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue#size()}. */ | ||
| public int size() { | ||
| return size; | ||
| } | ||
|
|
||
| public boolean isEmpty() { | ||
| return size == 0; | ||
| } | ||
|
|
||
| /** Copied from fastutil {@code LongHeapPriorityQueue#clear()}. */ | ||
| public void clear() { | ||
| size = 0; | ||
| } | ||
|
|
||
| /** Local substitute for fastutil {@code LongArrays#grow(long[], int)}. */ | ||
| private static long[] grow(final long[] array, final int length) { | ||
| int newLength = (int) Math.min(Math.max(2L * array.length, length), Integer.MAX_VALUE - 8); | ||
| if (newLength < length) { | ||
| newLength = length; | ||
| } | ||
| return Arrays.copyOf(array, newLength); | ||
| } | ||
|
|
||
| /** | ||
| * Copied from fastutil {@code LongHeaps#downHeap(long[], int, int, LongComparator)} natural-order | ||
| * branch ({@code c == null}). | ||
| */ | ||
| private static int downHeap(final long[] heap, final int size, int i) { | ||
| final long e = heap[i]; | ||
| int child; | ||
| while ((child = (i << 1) + 1) < size) { | ||
| long t = heap[child]; | ||
| final int right = child + 1; | ||
| if (right < size && heap[right] < t) { | ||
| t = heap[child = right]; | ||
| } | ||
| if (e <= t) { | ||
| break; | ||
| } | ||
| heap[i] = t; | ||
| i = child; | ||
| } | ||
| heap[i] = e; | ||
| return i; | ||
| } | ||
|
|
||
| /** | ||
| * Copied from fastutil {@code LongHeaps#upHeap(long[], int, int, LongComparator)} natural-order | ||
| * branch ({@code c == null}). | ||
| */ | ||
| private static int upHeap(final long[] heap, final int size, int i) { | ||
| final long e = heap[i]; | ||
| while (i != 0) { | ||
| final int parent = (i - 1) >>> 1; | ||
| final long t = heap[parent]; | ||
| if (t <= e) { | ||
| break; | ||
| } | ||
| heap[i] = t; | ||
| i = parent; | ||
| } | ||
| heap[i] = e; | ||
| return i; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, switched to if (timeSet.add(time)) to avoid the double probe.