<commit_before>// Copyright (c) 2014, VacuumLabs.
// Copyright (c) 2012, Google Inc. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

// Authors are listed in the AUTHORS file

part of persistent;

/**
 * The interface is defined mainly for documenting read-functions of PersistentMap
 * and TMap; the interface is not supposed to be actually used
 * (as you usually know, which Map you are using).
 *
 * [ReadMap] binds keys of type [K] to values of type [V]. Null
 * values are supported but null keys are not.
 *
 * There is no default implementation of [ReadMap], since it just
 * specifies common interface of [PMap] and [TMap].
 *
 * In all the examples below `{k1: v1, k2: v2, ...}` is a shorthand for
 * `new PersistentMap.fromMap({k1: v1, k2: v2, ...})`.
 */
abstract class ReadMap<K, V> implements Iterable<Pair<K, V>> {

  /**
   * Returns the value bound to [key].
   *
   * If [key] is not bound, [notFound] is returned; if [notFound] is not set, Exception
   * is thrown.
   */
  V get(K key, [V notFound]);

  /**
   * Returns the value bound to [key].
   *
   * Throws exception if [key] is not bound.
   */
  V operator [](K key);

  /**
   * Evaluates `f(key, value)` for each (`key`, `value`) pair in `this`.
   */
  void forEachKeyValue(f(K key, V value));

  /// Returns a mutable copy of `this`.
  Map<K, V> toMap();

  /// The keys of `this`.
  Iterable<K> get keys;

  /// Returns true if contains [key]
  bool containsKey(K key);

  /// Returns true if contains [key]
  bool hasKey(K key);

  /// The values of `this`.
  Iterable<V> get values;

  /// An iterator through the entries of `this`.
  Iterator<Pair<K, V>> get iterator;

  /// The number of entries of `this`.
  int get length;
}

/**
 * A persistent map, binding keys of type [K] to values of type [V]. Null
 * values are supported but null keys are not.
 *
 * Persistent data structure is an immutable structure, that provides effective
 * creation of slightly mutated copies.
 *
 * In all the examples below `{k1: v1, k2: v2, ...}` is a shorthand for
 * `new PersistentMap.fromMap({k1: v1, k2: v2, ...})`.
 */

abstract class PMap<K, V> implements ReadMap<K, V>, PersistentIndexedCollection {

  /** Creates an empty [PMap] using its default implementation. */
  factory PMap() => new _Leaf.empty(null);

  /**
   * Creates an immutable copy of [map] using the default implementation of
   * [PMap].
   */
  factory PMap.fromMap(Map<K, V> map) => new _Node.fromMap(map);

  /**
   * Creates a [PMap] from an [Iterable] of [Pair]s using the default
   * implementation of [PMap].
   */
  factory PMap.fromPairs(Iterable<Pair<K, V>> pairs) => new _Node.fromPairs(pairs);

  /**
   * The equality operator.
   *
   * Two persistent maps are equal if and only if their sets of keys are equal,
   * and the equal keys are bound to the equal values.
   *
   * Two sets of keys are equal if and only if for each key exists
   * an equal key in the other set.
   */
  bool operator== (other);

  /*
   * The documentation is inherited from the Object
   */<commit_msg>inteligent .from constructor added<commit_after>// Copyright (c) 2014, VacuumLabs.
// Copyright (c) 2012, Google Inc. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

// Authors are listed in the AUTHORS file

part of persistent;

/**
 * The interface is defined mainly for documenting read-functions of PersistentMap
 * and TMap; the interface is not supposed to be actually used
 * (as you usually know, which Map you are using).
 *
 * [ReadMap] binds keys of type [K] to values of type [V]. Null
 * values are supported but null keys are not.
 *
 * There is no default implementation of [ReadMap], since it just
 * specifies common interface of [PMap] and [TMap].
 *
 * In all the examples below `{k1: v1, k2: v2, ...}` is a shorthand for
 * `new PersistentMap.fromMap({k1: v1, k2: v2, ...})`.
 */
abstract class ReadMap<K, V> implements Iterable<Pair<K, V>> {

  /**
   * Returns the value bound to [key].
   *
   * If [key] is not bound, [notFound] is returned; if [notFound] is not set, Exception
   * is thrown.
   */
  V get(K key, [V notFound]);

  /**
   * Returns the value bound to [key].
   *
   * Throws exception if [key] is not bound.
   */
  V operator [](K key);

  /**
   * Evaluates `f(key, value)` for each (`key`, `value`) pair in `this`.
   */
  void forEachKeyValue(f(K key, V value));

  /// Returns a mutable copy of `this`.
  Map<K, V> toMap();

  /// The keys of `this`.
  Iterable<K> get keys;

  /// Returns true if contains [key]
  bool containsKey(K key);

  /// Returns true if contains [key]
  bool hasKey(K key);

  /// The values of `this`.
  Iterable<V> get values;

  /// An iterator through the entries of `this`.
  Iterator<Pair<K, V>> get iterator;

  /// The number of entries of `this`.
  int get length;
}

/**
 * A persistent map, binding keys of type [K] to values of type [V]. Null
 * values are supported but null keys are not.
 *
 * Persistent data structure is an immutable structure, that provides effective
 * creation of slightly mutated copies.
 *
 * In all the examples below `{k1: v1, k2: v2, ...}` is a shorthand for
 * `new PersistentMap.fromMap({k1: v1, k2: v2, ...})`.
 */

abstract class PMap<K, V> implements ReadMap<K, V>, PersistentIndexedCollection {

  /** Creates an empty [PMap] using its default implementation. */
  factory PMap() => new _Leaf.empty(null);

  /**
   * dispatches to either PMap.fromMap or PMap.fromPairs
   */
  factory PMap.from(dynamic source) {
    if (source is Map) {
      return new PMap.fromMap(source);
    } else {
      if (source is Iterable) {
        if (source.isEmpty) {
          return new PMap();
        } else {
          if (source.first is Pair) {
            return new PMap.fromPairs(source);
          }
        }
      }
    }
    throw new Exception('cannot construct PMap from ${source.runtimeType} ($source)');
  }

  /**
   * Creates an immutable copy of [map] using the default implementation of
   * [PMap].
   */
  factory PMap.fromMap(Map<K, V> map) => new _Node.fromMap(map);

  /**
   * Creates a [PMap] from an [Iterable] of [Pair]s using the default
   * implementation of [PMap].
   */
  factory PMap.fromPairs(Iterable<Pair<K, V>> pairs) => new _Node.fromPairs(pairs);

  /**
   * The equality operator.
   *
   * Two persistent maps are equal if and only if their sets of keys are equal,
   * and the equal keys are bound to the equal values.
   *
   * Two sets of keys are equal if and only if for each key exists
   * an equal key in the other set.
   */
  bool operator== (other);

  /*
   * The documentation is inherited from the Object
   */
{'fraction_non_alphanumeric': 0.12356067316209035, 'fraction_numerical': 0.0070859167404783, 'mean_word_length': 2.864803194523674, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, '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': '3899617', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2118, 'n_words': 893}