ProbVector.cs 721 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. namespace NLangDetect.Core
  4. {
  5. public class ProbVector
  6. {
  7. private readonly Dictionary<int, double> _dict = new Dictionary<int, double>();
  8. public double this[int key]
  9. {
  10. get
  11. {
  12. return _dict.TryGetValue(key, out var value) ? value : 0.0;
  13. }
  14. set
  15. {
  16. if (Math.Abs(value) < double.Epsilon)
  17. {
  18. if (_dict.ContainsKey(key))
  19. {
  20. _dict.Remove(key);
  21. }
  22. return;
  23. }
  24. _dict[key] = value;
  25. }
  26. }
  27. }
  28. }