Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

99 wiersze
2.8 KiB

  1. /* The MIT License
  2. Copyright (c) 2016-2020 Genome Research Ltd.
  3. Author: Petr Danecek <pd3@sanger.ac.uk>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. /*
  21. Logarithmic binning
  22. Example of usage:
  23. // Initialize, make the binning exact up to 10^4, then add a log-step
  24. dist_t *dist = dist_init(4);
  25. // Insert values
  26. int i;
  27. for (i=0; i<1e6; i++)
  28. dist_insert(dist, i);
  29. // Number of bins used
  30. int n = dist_n(dist);
  31. // Now print the distribution
  32. uint32_t beg, end;
  33. for (i=0; i<n; i++)
  34. {
  35. // Raw count in the bin. The boundaries beg,end are optional,
  36. // and can be used to plot correctly the density
  37. uint64_t cnt = dist_get(dist, i, &beg, &end);
  38. if ( !cnt ) continue;
  39. // Print the interval, count and density
  40. printf("%u\t%u\t%"PRIu64"\t%f\n", beg, end, cnt, (double)cnt/(end-beg));
  41. }
  42. // Clean up
  43. dist_destroy(dist);
  44. */
  45. #ifndef __DIST_H__
  46. #define __DIST_H__
  47. #include <stdio.h>
  48. #include <inttypes.h>
  49. typedef struct _dist_t dist_t;
  50. /*
  51. * dist_init() - init bins
  52. */
  53. dist_t *dist_init(int npow);
  54. void dist_destroy(dist_t *dist);
  55. /*
  56. dist_nbins() - get the number of bins
  57. */
  58. int dist_nbins(dist_t *dist);
  59. /*
  60. dist_nvalues() - get the total number of values inserted
  61. */
  62. int dist_nvalues(dist_t *dist);
  63. /*
  64. dist_insert() - insert new value
  65. dist_insert_n() - insert new value n times
  66. */
  67. uint32_t dist_insert(dist_t *dist, uint32_t value);
  68. uint32_t dist_insert_n(dist_t *dist, uint32_t value, uint32_t cnt);
  69. /*
  70. dist_get()
  71. @idx: from the interval [0,dist_n-1]
  72. @beg,end: [beg,end)
  73. */
  74. uint64_t dist_get(dist_t *dist, uint32_t idx, uint32_t *beg, uint32_t *end);
  75. #endif