ibessonov commented on code in PR #787: URL: https://github.com/apache/ignite-3/pull/787#discussion_r857446839
########## modules/storage-api/src/main/java/org/apache/ignite/internal/storage/UuidIgniteRowId.java: ########## @@ -0,0 +1,98 @@ +/* + * 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.ignite.internal.storage; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.UUID; +import org.jetbrains.annotations.NotNull; + +/** + * UUID-based ignite row id implementation. + */ +public class UuidIgniteRowId implements IgniteRowId { + /** Backing uuid value. */ + private final UUID uuid; + + /** + * Constructor. + * + * @param uuid UUID. + */ + public UuidIgniteRowId(UUID uuid) { + this.uuid = uuid; + } + + /** + * Returns {@link UuidIgniteRowId} instance based on {@link UUID#randomUUID()}. + */ + public static IgniteRowId randomRowId() { + return new UuidIgniteRowId(UUID.randomUUID()); + } + + /** {@inheritDoc} */ + @Override + public void writeTo(ByteBuffer buf, boolean signedBytesCompare) { + assert buf.order() == ByteOrder.LITTLE_ENDIAN; + + long mask = signedBytesCompare ? 0x0080808080808080L : 0x8000000000000000L; + + buf.putLong(Long.reverseBytes(mask ^ uuid.getMostSignificantBits())); + buf.putLong(Long.reverseBytes(mask ^ uuid.getLeastSignificantBits())); + } + + /** {@inheritDoc} */ + @Override + public int compare(ByteBuffer buf, boolean signedBytesCompare) { + assert buf.order() == ByteOrder.LITTLE_ENDIAN; + + long mask = signedBytesCompare ? 0x0080808080808080L : 0x8000000000000000L; + + int cmp = Long.compare(uuid.getMostSignificantBits(), mask ^ Long.reverseBytes(buf.getLong())); + + if (cmp != 0) { + return cmp; + } + + return Long.compare(uuid.getLeastSignificantBits(), mask ^ Long.reverseBytes(buf.getLong())); + } + + /** {@inheritDoc} */ + @Override + public int compareTo(@NotNull IgniteRowId o) { + if (!(o instanceof UuidIgniteRowId)) { + throw new IllegalArgumentException(o.getClass().getName()); + } + + UuidIgniteRowId that = (UuidIgniteRowId) o; + + int cmp = Long.compare(uuid.getMostSignificantBits(), that.uuid.getMostSignificantBits()); Review Comment: I changed this code completely, there's no point in proving this at this point. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
