richardstartin commented on a change in pull request #8016: URL: https://github.com/apache/pinot/pull/8016#discussion_r785785733
########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/nativefst/mutablefst/MutableFSTImpl.java ########## @@ -0,0 +1,196 @@ +/** + * 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; + +import com.google.common.base.Preconditions; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Queue; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.pinot.segment.local.utils.nativefst.mutablefst.utils.MutableFSTUtils; + + +/** + * A mutable finite state transducer implementation that allows you to build mutable via the API. + * This is not thread safe; convert to an ImmutableFst if you need to share across multiple writer + * threads. + * + * Concurrently writing and reading to/from a mutable FST is supported. + */ +public class MutableFSTImpl implements MutableFST { + private MutableState _start; + + public MutableFSTImpl() { + _start = new MutableState(true); + } + + /** + * Get the initial states + */ + @Override + public MutableState getStartState() { + return _start; + } + + /** + * Set the initial state + * + * @param start the initial state + */ + @Override + public void setStartState(MutableState start) { + Preconditions.checkState(_start != null, "Cannot override a start state"); + _start = start; + } + + public MutableState newStartState() { + return newStartState(); + } + + public MutableArc addArc(MutableState startState, int outputSymbol, MutableState endState) { + MutableArc newArc = new MutableArc(outputSymbol, + endState); + startState.addArc(newArc); + endState.addIncomingState(startState); + return newArc; + } + + @Override + public void throwIfInvalid() { + Preconditions.checkNotNull(_start, "must have a start state"); + } + + @Override + public void addPath(String word, int outputSymbol) { Review comment: Formatting: this method should fit on a screen without scrolling, but contains 15 blank lines which make the code unreadable. -- 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