<commit_before>package org.batfish.common.autocomplete;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.RangeSet;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.batfish.datamodel.Ip;

/** Metadata about an Ip needed for autocomplete. */
@ParametersAreNonnullByDefault
public final class IpCompletionMetadata implements Serializable {
  @Nullable private final RangeSet<Ip> _ipSubset;

  @Nonnull private final List<IpCompletionRelevance> _relevances;

  public IpCompletionMetadata() {
    this(null, ImmutableList.of());
  }

  public IpCompletionMetadata(IpCompletionRelevance relevance) {
    this(null, ImmutableList.of(relevance));
  }

  public IpCompletionMetadata(List<IpCompletionRelevance> relevances) {
    this(null, relevances);
  }

  public IpCompletionMetadata(
      @Nullable RangeSet<Ip> ipSubset, List<IpCompletionRelevance> relevances) {
    _ipSubset = ipSubset == null ? null : ImmutableRangeSet.copyOf(ipSubset);
    _relevances = new LinkedList<>(relevances);
  }

  /** Add another relevance with the specified display and match tags. */
  public void addRelevance(IpCompletionRelevance relevance) {
    if (!_relevances.contains(relevance)) {
      _relevances.add(relevance);
    }
  }<commit_msg>IpCompletionMetadata: quadratic to linear (#8116)<commit_after>package org.batfish.common.autocomplete;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.RangeSet;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.batfish.datamodel.Ip;

/** Metadata about an Ip needed for autocomplete. */
@ParametersAreNonnullByDefault
public final class IpCompletionMetadata implements Serializable {
  @Nullable private final RangeSet<Ip> _ipSubset;

  // TODO: Why does insertion order matter?
  @SuppressWarnings("PMD.LooseCoupling") // insertion order matters
  @Nonnull
  private final LinkedHashSet<IpCompletionRelevance> _relevances;

  public IpCompletionMetadata() {
    this(null, ImmutableList.of());
  }

  public IpCompletionMetadata(IpCompletionRelevance relevance) {
    this(null, ImmutableList.of(relevance));
  }

  public IpCompletionMetadata(List<IpCompletionRelevance> relevances) {
    this(null, relevances);
  }

  public IpCompletionMetadata(
      @Nullable RangeSet<Ip> ipSubset, List<IpCompletionRelevance> relevances) {
    _ipSubset = ipSubset == null ? null : ImmutableRangeSet.copyOf(ipSubset);
    _relevances = new LinkedHashSet<>(relevances);
  }

  /** Add another relevance with the specified display and match tags. */
  public void addRelevance(IpCompletionRelevance relevance) {
    _relevances.add(relevance);
  }
{'fraction_non_alphanumeric': 0.09416900530090427, 'fraction_numerical': 0.0012472715933894605, 'mean_word_length': 5.560327198364008, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3639464', 'n_tokens_mistral': 976, 'n_tokens_neox': 936, 'n_words': 204}