<commit_before>﻿namespace Persimmon.Dried

open System.Collections.Generic

// key type of underlying is obj because 'T avoid equality constraint
[<Sealed>]
type FreqMap<'T>(underlying: Dictionary<obj, int>, total: int) =
  
  member __.Total = total
  member internal __.Underlying = underlying

  override __.ToString() = sprintf "%A" underlying

module FreqMap =

  let empty<'T> = FreqMap<'T>(Dictionary<obj, int>(), 0)

  let add t (m: FreqMap<_>) =
    let n =
      match m.Underlying.TryGetValue(t) with
      | true, n -> n + 1
      | false, _ -> 1
    let d = Dictionary(m.Underlying)
    d.Add(t, n)
    FreqMap(d, m.Total + 1)

  let remove t (m: FreqMap<_>) =
    let u =
      match m.Underlying.TryGetValue(t) with
      | true, n ->
        let d = Dictionary(m.Underlying)
        d.Add(t, n - 1)
        d
      | false, _ -> Dictionary(m.Underlying)
    FreqMap(u, m.Total + 1)

  let tryFindCount t (m: FreqMap<_>) =
    match m.Underlying.TryGetValue(t) with
    | true, v -> Some v<commit_msg>fix duplicate error<commit_after>﻿namespace Persimmon.Dried

open System.Collections.Generic

// key type of underlying is obj because 'T avoid equality constraint
[<Sealed>]
type FreqMap<'T>(underlying: Dictionary<obj, int>, total: int) =
  
  member __.Total = total
  member internal __.Underlying = underlying

  override __.ToString() = sprintf "%A" underlying

module FreqMap =

  let empty<'T> = FreqMap<'T>(Dictionary<obj, int>(), 0)

  let add t (m: FreqMap<_>) =
    let d = Dictionary(m.Underlying)
    let n =
      match m.Underlying.TryGetValue(t) with
      | true, n ->
        d.Remove(t) |> ignore
        n + 1
      | false, _ -> 1
    d.Add(t, n)
    FreqMap(d, m.Total + 1)

  let remove t (m: FreqMap<_>) =
    let u =
      match m.Underlying.TryGetValue(t) with
      | true, n ->
        let d = Dictionary(m.Underlying)
        d.Remove(t) |> ignore
        d.Add(t, n - 1)
        d
      | false, _ -> Dictionary(m.Underlying)
    FreqMap(u, m.Total + 1)

  let tryFindCount t (m: FreqMap<_>) =
    match m.Underlying.TryGetValue(t) with
    | true, v -> Some v
{'fraction_non_alphanumeric': 0.1339031339031339, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 2.6140651801029158, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '7533290', 'n_tokens_mistral': 763, 'n_tokens_neox': 748, 'n_words': 207}