sabbey37 commented on a change in pull request #6489: URL: https://github.com/apache/geode/pull/6489#discussion_r636838128
########## File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java ########## @@ -0,0 +1,268 @@ +/* + * 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.geode.redis.internal.data; + +import static org.apache.geode.redis.internal.data.RedisDataType.REDIS_SORTED_SET; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import it.unimi.dsi.fastutil.bytes.ByteArrays; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap; + +import org.apache.geode.cache.Region; +import org.apache.geode.internal.InternalDataSerializer; +import org.apache.geode.internal.serialization.DeserializationContext; +import org.apache.geode.internal.serialization.KnownVersion; +import org.apache.geode.internal.serialization.SerializationContext; +import org.apache.geode.redis.internal.delta.AddsDeltaInfo; +import org.apache.geode.redis.internal.delta.DeltaInfo; +import org.apache.geode.redis.internal.delta.RemsDeltaInfo; +import org.apache.geode.redis.internal.executor.sortedset.SortedSetOptions; + +public class RedisSortedSet extends AbstractRedisData { + private Object2ObjectOpenCustomHashMap<byte[], byte[]> members; + + protected static final int BASE_REDIS_SORTED_SET_OVERHEAD = 184; + protected static final int PER_PAIR_OVERHEAD = 48; + + private int sizeInBytes = BASE_REDIS_SORTED_SET_OVERHEAD; + + @Override + public int getSizeInBytes() { + return sizeInBytes; + } + + private enum AddOrChange { + ADDED, CHANGED, NOOP + } + + private int calculateSizeOfFieldValuePair(byte[] member, byte[] score) { + return PER_PAIR_OVERHEAD + member.length + score.length; + } + + RedisSortedSet(List<byte[]> members) { + this.members = new Object2ObjectOpenCustomHashMap<>(members.size(), ByteArrays.HASH_STRATEGY); + Iterator<byte[]> iterator = members.iterator(); + + while (iterator.hasNext()) { + byte[] score = iterator.next(); + byte[] member = iterator.next(); Review comment: It should never be odd at this point because the parameters have been checked beforehand in `ZAddParameters` and a syntax error is thrown if they are odd. Really that case would never be hit in `RedisHash` either since those parameters are always checked beforehand. Does it make sense to check for these scenarios even though they are caught and an error is thrown earlier in the code? I guess it doesn't hurt to add them, but I would consider throwing this error instead: ` IllegalArgumentException(ERROR_SYNTAX);` It kind of goes back to our testing strategy and if we look at this class as an individual unit or from the integration perspective. It would be good to have a team discussion about this and decide on a strategy moving forward so we're all on the same page. -- 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: us...@infra.apache.org