diff --git a/persistit/core/src/main/java/com/persistit/BufferPool.java b/persistit/core/src/main/java/com/persistit/BufferPool.java index 8af3ee0c4..ea94e0503 100644 --- a/persistit/core/src/main/java/com/persistit/BufferPool.java +++ b/persistit/core/src/main/java/com/persistit/BufferPool.java @@ -1338,6 +1338,22 @@ public int compareTo(final BufferHolder buffer) { } + /** + * Equality is defined by the same (volumeId, page) ordering key used by + * {@link #compareTo(BufferHolder)}, so that {@code equals} stays + * consistent with the natural ordering. + */ + @Override + public boolean equals(final Object object) { + return this == object + || (object instanceof BufferHolder && compareTo((BufferHolder) object) == 0); + } + + @Override + public int hashCode() { + return Long.hashCode(_volumeId) * 31 + Long.hashCode(_page); + } + @Override public String toString() { final Buffer buffer = _buffer; diff --git a/persistit/core/src/main/java/com/persistit/JournalManager.java b/persistit/core/src/main/java/com/persistit/JournalManager.java index 0ce109579..b1e3265fa 100644 --- a/persistit/core/src/main/java/com/persistit/JournalManager.java +++ b/persistit/core/src/main/java/com/persistit/JournalManager.java @@ -13,6 +13,7 @@ * 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. + * Portions Copyrighted 2026 3A Systems, LLC */ package com.persistit; @@ -2158,6 +2159,22 @@ public int compareTo(final TransactionMapItem ts) { } } + /** + * Equality is kept consistent with {@link #compareTo(TransactionMapItem)}: + * two items are equal exactly when they order equally (same commit + * timestamp for committed items, otherwise same start timestamp). + */ + @Override + public boolean equals(final Object object) { + return this == object + || (object instanceof TransactionMapItem && compareTo((TransactionMapItem) object) == 0); + } + + @Override + public int hashCode() { + return Long.hashCode(isCommitted() ? _commitTimestamp : _startTimestamp); + } + final static Comparator TRANSACTION_MAP_ITEM_COMPARATOR = new Comparator() { @Override diff --git a/persistit/core/src/main/java/com/persistit/TreeBuilder.java b/persistit/core/src/main/java/com/persistit/TreeBuilder.java index 6be1c27df..3a0c5fba1 100644 --- a/persistit/core/src/main/java/com/persistit/TreeBuilder.java +++ b/persistit/core/src/main/java/com/persistit/TreeBuilder.java @@ -247,6 +247,24 @@ public int compareTo(final Node node) { return _key.compareTo(node._key); } + /** + * Equality is kept consistent with {@link #compareTo(Node)}: two nodes + * are equal exactly when they order equally (same tree and key, or both + * with no tree). + */ + @Override + public boolean equals(final Object object) { + return this == object || (object instanceof Node && compareTo((Node) object) == 0); + } + + @Override + public int hashCode() { + // Consistent with compareTo: equal nodes share the same tree + // instance (or both have none), so the tree's identity hash yields + // equal hash codes for equal nodes. + return _tree == null ? 0 : System.identityHashCode(_tree); + } + @Override public String toString() { Node n = this;