mayya-sharipova commented on code in PR #16261:
URL: https://github.com/apache/lucene/pull/16261#discussion_r3432583371
##########
lucene/core/src/java/org/apache/lucene/analysis/CharArraySet.java:
##########
@@ -166,6 +167,31 @@ public Iterator<Object> iterator() {
return map.originalKeySet().iterator();
}
+ /** Returns {@code true} if this set matches entries case-insensitively. */
+ public boolean isIgnoreCase() {
+ return map.isIgnoreCase();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof CharArraySet other)) return false;
+ if (isIgnoreCase() != other.isIgnoreCase()) return false;
+ if (size() != other.size()) return false;
+ return containsAll(other);
+ }
+
+ @Override
+ public int hashCode() {
+ int h = Boolean.hashCode(isIgnoreCase());
+ for (char[] key : map.keys) {
+ if (key != null) {
+ h += Arrays.hashCode(key);
+ }
+ }
+ return h;
+ }
Review Comment:
Not valid. CharArrayMap.put() lowercases keys in-place before storing them
when ignoreCase=true (line 196–197 in CharArrayMap.java). So map.keys already
holds ['t','e','s','t'] regardless of whether "Test" or "test" was inserted.
Arrays.hashCode on already-lowercased keys is fully consistent with the
case-insensitive equals.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]