source: trip-planner-front/node_modules/hdr-histogram-js/src/HistogramBuilder.ts@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[6a3a178]1import Histogram, { BitBucketSize } from "./Histogram";
2import { constructorFromBucketSize } from "./JsHistogramFactory";
3import { WasmHistogram, webAssemblyReady, webAssemblyAvailable } from "./wasm";
4
5export interface BuildRequest {
6 /**
7 * The size in bit of each count bucket
8 * Default value is 32
9 */
10 bitBucketSize?: BitBucketSize;
11 /**
12 * Control whether or not the histogram can auto-resize and auto-adjust it's
13 * highestTrackableValue
14 * Default value is true
15 */
16 autoResize?: boolean;
17 /**
18 * The lowest value that can be discerned (distinguished from 0) by the histogram.
19 * Must be a positive integer that is {@literal >=} 1. May be internally rounded
20 * down to nearest power of 2.
21 * Default value is 1
22 */
23 lowestDiscernibleValue?: number;
24 /**
25 * The highest value to be tracked by the histogram. Must be a positive
26 * integer that is {@literal >=} (2 * lowestDiscernibleValue).
27 * Default value is Number.MAX_SAFE_INTEGER
28 */
29 highestTrackableValue?: number;
30 /**
31 * The number of significant decimal digits to which the histogram will
32 * maintain value resolution and separation. Must be a non-negative
33 * integer between 0 and 5.
34 * Default value is 3
35 */
36 numberOfSignificantValueDigits?: 1 | 2 | 3 | 4 | 5;
37 /**
38 * Is WebAssembly used to speed up computations.
39 * Default value is false
40 */
41 useWebAssembly?: boolean;
42}
43
44export const defaultRequest: BuildRequest = {
45 bitBucketSize: 32,
46 autoResize: true,
47 lowestDiscernibleValue: 1,
48 highestTrackableValue: 2,
49 numberOfSignificantValueDigits: 3,
50 useWebAssembly: false,
51};
52
53export const build = (request = defaultRequest): Histogram => {
54 const parameters = Object.assign({}, defaultRequest, request);
55 if (request.useWebAssembly && webAssemblyAvailable) {
56 return WasmHistogram.build(parameters);
57 }
58
59 const histogramConstr = constructorFromBucketSize(
60 parameters.bitBucketSize as BitBucketSize
61 );
62
63 const histogram = new histogramConstr(
64 parameters.lowestDiscernibleValue as number,
65 parameters.highestTrackableValue as number,
66 parameters.numberOfSignificantValueDigits as number
67 );
68 histogram.autoResize = parameters.autoResize as boolean;
69 return histogram;
70};
Note: See TracBrowser for help on using the repository browser.