dschneider-pivotal commented on a change in pull request #6590:
URL: https://github.com/apache/geode/pull/6590#discussion_r650208396



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/collections/SizeableObject2ObjectOpenCustomHashMapWithCursor.java
##########
@@ -183,6 +192,50 @@ private int hash(K key) {
     return mix(strategy.hashCode(key)) & mask;
   }
 
+  @Override
+  public V put(K k, V v) {
+    V oldValue = super.put(k, v);
+    if (oldValue == null) {
+      // A create
+      arrayContentsOverhead += (int) (elementSizer.sizeof(k) + 
elementSizer.sizeof(v));
+    } else {
+      // An update
+      arrayContentsOverhead += (int) (elementSizer.sizeof(v) - 
elementSizer.sizeof(oldValue));
+    }
+    return oldValue;
+  }
+
+  @Override
+  public V remove(Object k) {
+    V oldValue = super.remove(k);
+    if (oldValue != null) {
+      arrayContentsOverhead -= (elementSizer.sizeof(k) + 
elementSizer.sizeof(oldValue));
+    }
+    return oldValue;
+  }
+
+  @Override
+  public int getSizeInBytes() {
+    return arrayContentsOverhead + calculateBackingArraysOverhead();
+  }
+
+  @VisibleForTesting
+  int calculateBackingArraysOverhead() {
+    // This formula determined experimentally using tests.
+    return BACKING_ARRAY_OVERHEAD_CONSTANT
+        + BACKING_ARRAY_LENGTH_COEFFICIENT * (key.length + value.length);

Review comment:
       you could use getTotalBackingArrayLength() here




-- 
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:
[email protected]


Reply via email to