richardstartin commented on a change in pull request #8016: URL: https://github.com/apache/pinot/pull/8016#discussion_r784289254
########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/nativefst/mutablefst/utils/MutableFSTUtils.java ########## @@ -0,0 +1,117 @@ +/** + * 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.pinot.segment.local.utils.nativefst.mutablefst.utils; + +import org.apache.pinot.segment.local.utils.nativefst.mutablefst.MutableArc; +import org.apache.pinot.segment.local.utils.nativefst.mutablefst.MutableFST; +import org.apache.pinot.segment.local.utils.nativefst.mutablefst.MutableState; +import org.apache.pinot.segment.local.utils.nativefst.utils.RealTimeRegexpMatcher; +import org.roaringbitmap.RoaringBitmapWriter; +import org.roaringbitmap.buffer.MutableRoaringBitmap; + +public class MutableFSTUtils { + + private MutableFSTUtils() { + + } + + public static boolean fstEquals(Object thisFstObj, + Object thatFstObj) { + if (thisFstObj == thatFstObj) { + return true; + } + if (thisFstObj == null || thatFstObj == null) { + return false; + } + if (!MutableFST.class.isAssignableFrom(thisFstObj.getClass()) + || !MutableFST.class.isAssignableFrom(thatFstObj.getClass())) { + return false; + } + + MutableFST thisMutableFST = (MutableFST) thisFstObj; + MutableFST thatMutableFST = (MutableFST) thatFstObj; + + + if (thisMutableFST.getStartState() != null ? (thisMutableFST.getStartState().getLabel() + != thatMutableFST.getStartState().getLabel()) : thatMutableFST.getStartState() != null) { + return false; + } + + return true; + } + + public static boolean arcEquals(Object thisArcObj, Object thatArcObj) { + if (thisArcObj == thatArcObj) { + return true; + } + if (thisArcObj == null || thatArcObj == null) { + return false; + } + if (!MutableArc.class.isAssignableFrom(thisArcObj.getClass()) + || !MutableArc.class.isAssignableFrom(thatArcObj.getClass())) { + return false; + } + MutableArc thisArc = (MutableArc) thisArcObj; + MutableArc thatArc = (MutableArc) thatArcObj; + + if (thisArc.getNextState().getLabel() != thatArc.getNextState().getLabel()) { + return false; + } + + return true; + } + + public static boolean stateEquals( + Object thisStateObj, Object thatStateObj) { + if (thisStateObj == thatStateObj) { + return true; + } + if (thisStateObj == null || thatStateObj == null) { + return false; + } + if (!MutableState.class.isAssignableFrom(thisStateObj.getClass()) + || !MutableState.class.isAssignableFrom(thatStateObj.getClass())) { + return false; + } + + MutableState thisState = (MutableState) thisStateObj; + MutableState thatState = (MutableState) thatStateObj; + + if (thisState.getLabel() != thatState.getLabel()) { + return false; + } + + if (thisState.getArcs().size() != thatState.getArcs().size()) { + return false; + } + + return true; + } Review comment: (this applies to the methods above too. `instanceof` checks fail when references are null. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org