ProbVector.cs 593 B

1234567891011121314151617181920212223242526272829303132333435
  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. double value;
  13. return _dict.TryGetValue(key, out value) ? value : 0.0;
  14. }
  15. set
  16. {
  17. if (Math.Abs(value) < double.Epsilon)
  18. {
  19. if (_dict.ContainsKey(key))
  20. {
  21. _dict.Remove(key);
  22. }
  23. return;
  24. }
  25. _dict[key] = value;
  26. }
  27. }
  28. }
  29. }