<commit_before>package com.jayantkrish.jklol.lisp;

import java.util.Arrays;
import java.util.List;

import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.jayantkrish.jklol.lisp.BranchingFactorGraph.ChildBfg;
import com.jayantkrish.jklol.models.Factor;
import com.jayantkrish.jklol.models.FactorGraph;
import com.jayantkrish.jklol.models.VariableNumMap;
import com.jayantkrish.jklol.models.VariableNumMap.VariableRelabeling;
import com.jayantkrish.jklol.models.parametric.ParametricFactor;
import com.jayantkrish.jklol.util.Assignment;

public class ParametricBfgBuilder {

  private VariableNumMap variables;
  private final boolean isRoot;
  private Assignment assignment;

  private final List<Factor> factors;
  private final List<String> factorNames;
  
  private final List<Factor> crossingFactors;
  private final List<ChildBuilder> children;

  private final List<MarkedVars> markedVars;
  
  // Mapping between factors and the variables they contain,
  // for the non-crossing factors.
  protected Multimap<Integer, Integer> variableFactorMap;
  protected Multimap<Integer, Integer> factorVariableMap;
  
  private static int nextVarNum;

  public ParametricBfgBuilder(boolean isRoot) {
    this.variables = VariableNumMap.EMPTY;
    this.markedVars = Lists.newArrayList();
    this.isRoot = isRoot;
    this.assignment = Assignment.EMPTY;

    this.factors = Lists.newArrayList();
    this.factorNames = Lists.newArrayList();

    this.crossingFactors = Lists.newArrayList();
    this.children = Lists.newArrayList();

    this.variableFactorMap = HashMultimap.create();
    this.factorVariableMap = HashMultimap.create();
  }

  public static int getUniqueVarNum() {
    return nextVarNum++;
  }

  public void addVariables(VariableNumMap newVariables) {<commit_msg>Made ParametricBfgBuilder.getUniqueVarNum thread-safe<commit_after>package com.jayantkrish.jklol.lisp;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.jayantkrish.jklol.lisp.BranchingFactorGraph.ChildBfg;
import com.jayantkrish.jklol.models.Factor;
import com.jayantkrish.jklol.models.FactorGraph;
import com.jayantkrish.jklol.models.VariableNumMap;
import com.jayantkrish.jklol.models.VariableNumMap.VariableRelabeling;
import com.jayantkrish.jklol.models.parametric.ParametricFactor;
import com.jayantkrish.jklol.util.Assignment;

public class ParametricBfgBuilder {

  private VariableNumMap variables;
  private final boolean isRoot;
  private Assignment assignment;

  private final List<Factor> factors;
  private final List<String> factorNames;
  
  private final List<Factor> crossingFactors;
  private final List<ChildBuilder> children;

  private final List<MarkedVars> markedVars;
  
  // Mapping between factors and the variables they contain,
  // for the non-crossing factors.
  protected Multimap<Integer, Integer> variableFactorMap;
  protected Multimap<Integer, Integer> factorVariableMap;
  
  private static AtomicInteger nextVarNum = new AtomicInteger(0);

  public ParametricBfgBuilder(boolean isRoot) {
    this.variables = VariableNumMap.EMPTY;
    this.markedVars = Lists.newArrayList();
    this.isRoot = isRoot;
    this.assignment = Assignment.EMPTY;

    this.factors = Lists.newArrayList();
    this.factorNames = Lists.newArrayList();

    this.crossingFactors = Lists.newArrayList();
    this.children = Lists.newArrayList();

    this.variableFactorMap = HashMultimap.create();
    this.factorVariableMap = HashMultimap.create();
  }

  public static int getUniqueVarNum() {
    return nextVarNum.incrementAndGet();
  }

  public void addVariables(VariableNumMap newVariables) {
{'fraction_non_alphanumeric': 0.09021986353297953, 'fraction_numerical': 0.00025271670457417233, 'mean_word_length': 5.136434108527132, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '253236', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1208, 'n_words': 242}