Repository navigation
feat(java): add chunk and edge-range primitives #968
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
+1,040
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08f50d4
feat(java): add chunk and edge-range primitives
keksmd 4f34d65
feat(java): resolve ordered adjacency ranges
keksmd a551002
ci(java): build the core module the workflow already watches
keksmd 2412d03
Make an offset chunk say which vertex chunk it came from
keksmd 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
|
|
||
| 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. | ||
|
|
||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.graphar</groupId> | ||
| <artifactId>graphar-root</artifactId> | ||
| <version>${graphar.version}</version> | ||
| <relativePath>../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>graphar-core</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>${graphar.version}</version> | ||
| <name>graphar-core</name> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>11</maven.compiler.source> | ||
| <maven.compiler.target>11</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.graphar</groupId> | ||
| <artifactId>graphar-info</artifactId> | ||
| <version>${graphar.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.13.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>com.diffplug.spotless</groupId> | ||
| <artifactId>spotless-maven-plugin</artifactId> | ||
| <version>${spotless-maven-plugin.version}</version> | ||
| <configuration> | ||
| <java> | ||
| <googleJavaFormat> | ||
| <version>1.7</version> | ||
| <style>AOSP</style> | ||
| </googleJavaFormat> | ||
| </java> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-javadoc-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-javadocs</id> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
79 changes: 79 additions & 0 deletions
79
maven-projects/core/src/main/java/org/apache/graphar/core/ChunkMath.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,79 @@ | ||
| /* | ||
| * 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.graphar.core; | ||
|
|
||
| /** Long-safe operations on GraphAr vertex and edge chunks. */ | ||
| public final class ChunkMath { | ||
| private ChunkMath() {} | ||
|
|
||
| /** | ||
| * Returns the chunk containing a non-negative element identifier. | ||
| * | ||
| * @param elementId an element identifier | ||
| * @param chunkSize a positive chunk size | ||
| * @return the zero-based chunk index | ||
| */ | ||
| public static long chunkIndex(long elementId, long chunkSize) { | ||
| validateElementId(elementId); | ||
| validateChunkSize(chunkSize); | ||
| return elementId / chunkSize; | ||
| } | ||
|
|
||
| /** | ||
| * Returns an element's zero-based position inside its chunk. | ||
| * | ||
| * @param elementId an element identifier | ||
| * @param chunkSize a positive chunk size | ||
| * @return the zero-based offset within the chunk | ||
| */ | ||
| public static long offsetInChunk(long elementId, long chunkSize) { | ||
| validateElementId(elementId); | ||
| validateChunkSize(chunkSize); | ||
| return elementId % chunkSize; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of chunks required for a non-negative number of elements. | ||
| * | ||
| * @param elementCount a number of elements | ||
| * @param chunkSize a positive chunk size | ||
| * @return the number of chunks needed to contain the elements | ||
| */ | ||
| public static long chunkCount(long elementCount, long chunkSize) { | ||
| if (elementCount < 0) { | ||
| throw new IllegalArgumentException( | ||
| "Element count must be non-negative: " + elementCount); | ||
| } | ||
| validateChunkSize(chunkSize); | ||
| return elementCount == 0 ? 0 : 1 + (elementCount - 1) / chunkSize; | ||
| } | ||
|
|
||
| static void validateElementId(long elementId) { | ||
| if (elementId < 0) { | ||
| throw new IllegalArgumentException("Element ID must be non-negative: " + elementId); | ||
| } | ||
| } | ||
|
|
||
| static void validateChunkSize(long chunkSize) { | ||
| if (chunkSize <= 0) { | ||
| throw new IllegalArgumentException("Chunk size must be positive: " + chunkSize); | ||
| } | ||
| } | ||
| } |
105 changes: 105 additions & 0 deletions
105
maven-projects/core/src/main/java/org/apache/graphar/core/ChunkRange.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,105 @@ | ||
| /* | ||
| * 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.graphar.core; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** A half-open range of non-negative chunk indexes. */ | ||
| public final class ChunkRange { | ||
| private final long begin; | ||
| private final long end; | ||
|
|
||
| /** | ||
| * Creates a chunk range. | ||
| * | ||
| * @param begin the first included non-negative chunk index | ||
| * @param end the first excluded chunk index | ||
| */ | ||
| public ChunkRange(long begin, long end) { | ||
| if (begin < 0) { | ||
| throw new IllegalArgumentException("Chunk range begin must be non-negative: " + begin); | ||
| } | ||
| if (end < begin) { | ||
| throw new IllegalArgumentException( | ||
| "Chunk range end must not precede begin: [" + begin + ", " + end + ")"); | ||
| } | ||
| this.begin = begin; | ||
| this.end = end; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the first included chunk index. | ||
| * | ||
| * @return the first included chunk index | ||
| */ | ||
| public long begin() { | ||
| return begin; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the first excluded chunk index. | ||
| * | ||
| * @return the first excluded chunk index | ||
| */ | ||
| public long end() { | ||
| return end; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether this range selects no chunks. | ||
| * | ||
| * @return whether the range is empty | ||
| */ | ||
| public boolean isEmpty() { | ||
| return begin == end; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether {@code chunkIndex} belongs to this range. | ||
| * | ||
| * @param chunkIndex a chunk index | ||
| * @return whether the chunk index belongs to this range | ||
| */ | ||
| public boolean contains(long chunkIndex) { | ||
| return chunkIndex >= begin && chunkIndex < end; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
| if (!(other instanceof ChunkRange)) { | ||
| return false; | ||
| } | ||
| ChunkRange that = (ChunkRange) other; | ||
| return begin == that.begin && end == that.end; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(begin, end); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ChunkRange[" + begin + ", " + end + ")"; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.