<commit_before>/*
 * Copyright (C) 2012 The Guava Authors
 *
 * Licensed 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 com.google.common.collect;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * Helper classes for various benchmarks.
 *
 * @author <NAME>
 */
final class BenchmarkHelpers {
  /**
   * So far, this is the best way to test various implementations of {@link Set} subclasses.
   */
  public enum SetImpl {
    Hash {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new HashSet<E>(contents);
      }
    },
    LinkedHash {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new LinkedHashSet<E>(contents);
      }
    },
    Tree {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new TreeSet<E>(contents);
      }
    },
    Unmodifiable {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return Collections.unmodifiableSet(new HashSet<E>(contents));
      }
    },
    Synchronized {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return Collections.synchronizedSet(new HashSet<E>(contents));
      }
    },
    Immutable {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return ImmutableSet.copyOf(contents);
      }
    },
    ImmutableSorted {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return ImmutableSortedSet.copyOf(contents);
      }
    },
    ;

    abstract <E extends Comparable<E>> Set<E> create(Collection<E> contents);
  }

  public enum ListMultimapImpl {
    ArrayList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return ArrayListMultimap.create(contents);
      }
    },
    LinkedList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return LinkedListMultimap.create(contents);
      }
    },
    ImmutableList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return ImmutableListMultimap.copyOf(contents);
      }
    };

    abstract <K, V> ListMultimap<K, V> create(Multimap<K, V> contents);
  }

  public enum SetMultimapImpl {
    Hash {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return HashMultimap.create(contents);
      }
    },
    LinkedHash {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return LinkedHashMultimap.create(contents);
      }
    },
    Tree {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return TreeMultimap.create(contents);
      }
    },
    ImmutableSet {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return ImmutableSetMultimap.copyOf(contents);
      }
    };

    abstract <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
        Multimap<K, V> contents);
  }

  public enum MapImpl {
    Hash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return Maps.newHashMap(map);
      }
    },
    LinkedHash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return Maps.newLinkedHashMap(map);
      }
    },
    ConcurrentHash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return new ConcurrentHashMap<K, V>(map);
      }
    },
    Immutable {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return ImmutableMap.copyOf(map);
      }
    };

    abstract <K, V> Map<K, V> create(Map<K, V> map);
  }

  enum SortedMapImpl {
    Tree {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        SortedMap<K, V> result = Maps.newTreeMap();
        result.putAll(map);
        return result;
      }
    },
    ConcurrentSkipList {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        return new ConcurrentSkipListMap<K, V>(map);
      }
    },
    ImmutableSorted {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        return ImmutableSortedMap.copyOf(map);
      }
    };

    abstract <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map);
  }
<commit_msg>Add BiMapMemoryBenchmark ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=40154710<commit_after>/*
 * Copyright (C) 2012 The Guava Authors
 *
 * Licensed 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 com.google.common.collect;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * Helper classes for various benchmarks.
 *
 * @author <NAME>
 */
final class BenchmarkHelpers {
  /**
   * So far, this is the best way to test various implementations of {@link Set} subclasses.
   */
  public enum SetImpl {
    Hash {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new HashSet<E>(contents);
      }
    },
    LinkedHash {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new LinkedHashSet<E>(contents);
      }
    },
    Tree {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return new TreeSet<E>(contents);
      }
    },
    Unmodifiable {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return Collections.unmodifiableSet(new HashSet<E>(contents));
      }
    },
    Synchronized {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return Collections.synchronizedSet(new HashSet<E>(contents));
      }
    },
    Immutable {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return ImmutableSet.copyOf(contents);
      }
    },
    ImmutableSorted {
      @Override <E extends Comparable<E>> Set<E> create(Collection<E> contents) {
        return ImmutableSortedSet.copyOf(contents);
      }
    },
    ;

    abstract <E extends Comparable<E>> Set<E> create(Collection<E> contents);
  }

  public enum ListMultimapImpl {
    ArrayList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return ArrayListMultimap.create(contents);
      }
    },
    LinkedList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return LinkedListMultimap.create(contents);
      }
    },
    ImmutableList {
      @Override
      <K, V> ListMultimap<K, V> create(Multimap<K, V> contents) {
        return ImmutableListMultimap.copyOf(contents);
      }
    };

    abstract <K, V> ListMultimap<K, V> create(Multimap<K, V> contents);
  }

  public enum SetMultimapImpl {
    Hash {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return HashMultimap.create(contents);
      }
    },
    LinkedHash {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return LinkedHashMultimap.create(contents);
      }
    },
    Tree {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return TreeMultimap.create(contents);
      }
    },
    ImmutableSet {
      @Override
      <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
          Multimap<K, V> contents) {
        return ImmutableSetMultimap.copyOf(contents);
      }
    };

    abstract <K extends Comparable<K>, V extends Comparable<V>> SetMultimap<K, V> create(
        Multimap<K, V> contents);
  }

  public enum MapImpl {
    Hash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return Maps.newHashMap(map);
      }
    },
    LinkedHash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return Maps.newLinkedHashMap(map);
      }
    },
    ConcurrentHash {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return new ConcurrentHashMap<K, V>(map);
      }
    },
    Immutable {
      @Override
      <K, V> Map<K, V> create(Map<K, V> map) {
        return ImmutableMap.copyOf(map);
      }
    };

    abstract <K, V> Map<K, V> create(Map<K, V> map);
  }

  enum SortedMapImpl {
    Tree {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        SortedMap<K, V> result = Maps.newTreeMap();
        result.putAll(map);
        return result;
      }
    },
    ConcurrentSkipList {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        return new ConcurrentSkipListMap<K, V>(map);
      }
    },
    ImmutableSorted {
      @Override
      <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map) {
        return ImmutableSortedMap.copyOf(map);
      }
    };

    abstract <K extends Comparable<K>, V> SortedMap<K, V> create(Map<K, V> map);
  }

  enum BiMapImpl {
    Hash{
      @Override
      <K, V> BiMap<K, V> create(BiMap<K, V> map) {
        return HashBiMap.create(map);
      }
    },
    Immutable {
      @Override
      <K, V> BiMap<K, V> create(BiMap<K, V> map) {
        return ImmutableBiMap.copyOf(map);
      }
    };

    abstract <K, V> BiMap<K, V> create(BiMap<K, V> map);
  }

{'fraction_non_alphanumeric': 0.12433534207727756, 'fraction_numerical': 0.0021269053527118043, 'mean_word_length': 2.6891140895717554, 'pattern_counts': {'":': 0, '<': 230, '<?xml version=': 0, '>': 230, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1889569', 'n_tokens_mistral': 3691, 'n_tokens_neox': 3655, 'n_words': 950}