@fluidframework/id-compressor 2.0.0-dev.7.4.0.221926
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +27 -0
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +3 -0
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +12 -0
- package/api-report/id-compressor.api.md +143 -0
- package/dist/appendOnlySortedMap.d.ts +124 -0
- package/dist/appendOnlySortedMap.d.ts.map +1 -0
- package/dist/appendOnlySortedMap.js +318 -0
- package/dist/appendOnlySortedMap.js.map +1 -0
- package/dist/finalSpace.d.ts +29 -0
- package/dist/finalSpace.d.ts.map +1 -0
- package/dist/finalSpace.js +62 -0
- package/dist/finalSpace.js.map +1 -0
- package/dist/id-compressor-alpha.d.ts +311 -0
- package/dist/id-compressor-beta.d.ts +41 -0
- package/dist/id-compressor-public.d.ts +41 -0
- package/dist/id-compressor-untrimmed.d.ts +329 -0
- package/dist/idCompressor.d.ts +85 -0
- package/dist/idCompressor.d.ts.map +1 -0
- package/dist/idCompressor.js +509 -0
- package/dist/idCompressor.js.map +1 -0
- package/dist/identifiers.d.ts +32 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/identifiers.js +15 -0
- package/dist/identifiers.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/packageVersion.d.ts +9 -0
- package/dist/packageVersion.d.ts.map +1 -0
- package/dist/packageVersion.js +12 -0
- package/dist/packageVersion.js.map +1 -0
- package/dist/persistanceUtilities.d.ts +22 -0
- package/dist/persistanceUtilities.d.ts.map +1 -0
- package/dist/persistanceUtilities.js +43 -0
- package/dist/persistanceUtilities.js.map +1 -0
- package/dist/sessionSpaceNormalizer.d.ts +46 -0
- package/dist/sessionSpaceNormalizer.d.ts.map +1 -0
- package/dist/sessionSpaceNormalizer.js +80 -0
- package/dist/sessionSpaceNormalizer.js.map +1 -0
- package/dist/sessions.d.ts +115 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +305 -0
- package/dist/sessions.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/idCompressor.d.ts +139 -0
- package/dist/types/idCompressor.d.ts.map +1 -0
- package/dist/types/idCompressor.js +7 -0
- package/dist/types/idCompressor.js.map +1 -0
- package/dist/types/identifiers.d.ts +40 -0
- package/dist/types/identifiers.d.ts.map +1 -0
- package/dist/types/identifiers.js +7 -0
- package/dist/types/identifiers.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/persisted-types/0.0.1.d.ts +46 -0
- package/dist/types/persisted-types/0.0.1.d.ts.map +1 -0
- package/dist/types/persisted-types/0.0.1.js +14 -0
- package/dist/types/persisted-types/0.0.1.js.map +1 -0
- package/dist/types/persisted-types/index.d.ts +6 -0
- package/dist/types/persisted-types/index.d.ts.map +1 -0
- package/dist/types/persisted-types/index.js +10 -0
- package/dist/types/persisted-types/index.js.map +1 -0
- package/dist/utilities.d.ts +53 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +170 -0
- package/dist/utilities.js.map +1 -0
- package/lib/appendOnlySortedMap.d.ts +124 -0
- package/lib/appendOnlySortedMap.d.ts.map +1 -0
- package/lib/appendOnlySortedMap.js +314 -0
- package/lib/appendOnlySortedMap.js.map +1 -0
- package/lib/finalSpace.d.ts +29 -0
- package/lib/finalSpace.d.ts.map +1 -0
- package/lib/finalSpace.js +58 -0
- package/lib/finalSpace.js.map +1 -0
- package/lib/id-compressor-alpha.d.ts +311 -0
- package/lib/id-compressor-beta.d.ts +41 -0
- package/lib/id-compressor-public.d.ts +41 -0
- package/lib/id-compressor-untrimmed.d.ts +329 -0
- package/lib/idCompressor.d.ts +85 -0
- package/lib/idCompressor.d.ts.map +1 -0
- package/lib/idCompressor.js +503 -0
- package/lib/idCompressor.js.map +1 -0
- package/lib/identifiers.d.ts +32 -0
- package/lib/identifiers.d.ts.map +1 -0
- package/lib/identifiers.js +11 -0
- package/lib/identifiers.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/packageVersion.d.ts +9 -0
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/packageVersion.js +9 -0
- package/lib/packageVersion.js.map +1 -0
- package/lib/persistanceUtilities.d.ts +22 -0
- package/lib/persistanceUtilities.d.ts.map +1 -0
- package/lib/persistanceUtilities.js +34 -0
- package/lib/persistanceUtilities.js.map +1 -0
- package/lib/sessionSpaceNormalizer.d.ts +46 -0
- package/lib/sessionSpaceNormalizer.d.ts.map +1 -0
- package/lib/sessionSpaceNormalizer.js +76 -0
- package/lib/sessionSpaceNormalizer.js.map +1 -0
- package/lib/sessions.d.ts +115 -0
- package/lib/sessions.d.ts.map +1 -0
- package/lib/sessions.js +290 -0
- package/lib/sessions.js.map +1 -0
- package/lib/types/idCompressor.d.ts +139 -0
- package/lib/types/idCompressor.d.ts.map +1 -0
- package/lib/types/idCompressor.js +6 -0
- package/lib/types/idCompressor.js.map +1 -0
- package/lib/types/identifiers.d.ts +40 -0
- package/lib/types/identifiers.d.ts.map +1 -0
- package/lib/types/identifiers.js +6 -0
- package/lib/types/identifiers.js.map +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +6 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/persisted-types/0.0.1.d.ts +46 -0
- package/lib/types/persisted-types/0.0.1.d.ts.map +1 -0
- package/lib/types/persisted-types/0.0.1.js +11 -0
- package/lib/types/persisted-types/0.0.1.js.map +1 -0
- package/lib/types/persisted-types/index.d.ts +6 -0
- package/lib/types/persisted-types/index.d.ts.map +1 -0
- package/lib/types/persisted-types/index.js +6 -0
- package/lib/types/persisted-types/index.js.map +1 -0
- package/lib/utilities.d.ts +53 -0
- package/lib/utilities.d.ts.map +1 -0
- package/lib/utilities.js +152 -0
- package/lib/utilities.js.map +1 -0
- package/package.json +110 -0
- package/prettier.config.cjs +8 -0
- package/src/appendOnlySortedMap.ts +366 -0
- package/src/finalSpace.ts +67 -0
- package/src/idCompressor.ts +689 -0
- package/src/identifiers.ts +42 -0
- package/src/index.ts +24 -0
- package/src/packageVersion.ts +9 -0
- package/src/persistanceUtilities.ts +58 -0
- package/src/sessionSpaceNormalizer.ts +83 -0
- package/src/sessions.ts +405 -0
- package/src/types/idCompressor.ts +155 -0
- package/src/types/identifiers.ts +39 -0
- package/src/types/index.ts +16 -0
- package/src/types/persisted-types/0.0.1.ts +51 -0
- package/src/types/persisted-types/README.md +3 -0
- package/src/types/persisted-types/index.ts +12 -0
- package/src/utilities.ts +191 -0
- package/tsconfig.esnext.json +7 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { SessionId } from "../identifiers";
|
|
6
|
+
/**
|
|
7
|
+
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
export type SerializedIdCompressor = string & {
|
|
11
|
+
readonly _serializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {
|
|
18
|
+
readonly _noLocalState: "3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
export type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {
|
|
25
|
+
readonly _hasLocalState: "1281acae-6d14-47e7-bc92-71c8ee0819cb";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Data describing a range of session-local IDs (from a remote or local session).
|
|
29
|
+
*
|
|
30
|
+
* A range is composed of local IDs that were generated.
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
export interface IdCreationRange {
|
|
34
|
+
readonly sessionId: SessionId;
|
|
35
|
+
readonly ids?: {
|
|
36
|
+
readonly firstGenCount: number;
|
|
37
|
+
readonly count: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.
|
|
42
|
+
* This value must *NOT* change without careful consideration to compatibility.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare const initialClusterCapacity = 512;
|
|
46
|
+
//# sourceMappingURL=0.0.1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0.0.1.d.ts","sourceRoot":"","sources":["../../../src/types/persisted-types/0.0.1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG;IAC7C,QAAQ,CAAC,uBAAuB,EAAE,sCAAsC,CAAC;CACzE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IAC1E,QAAQ,CAAC,aAAa,EAAE,sCAAsC,CAAC;CAC/D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wCAAwC,GAAG,sBAAsB,GAAG;IAC/E,QAAQ,CAAC,cAAc,EAAE,sCAAsC,CAAC;CAChE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE;QACd,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACvB,CAAC;CACF;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.initialClusterCapacity = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.
|
|
10
|
+
* This value must *NOT* change without careful consideration to compatibility.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
exports.initialClusterCapacity = 512;
|
|
14
|
+
//# sourceMappingURL=0.0.1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0.0.1.js","sourceRoot":"","sources":["../../../src/types/persisted-types/0.0.1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA0CH;;;;GAIG;AACU,QAAA,sBAAsB,GAAG,GAAG,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { SessionId } from \"../identifiers\";\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressor = string & {\n\treadonly _serializedIdCompressor: \"8c73c57c-1cf4-4278-8915-6444cb4f6af5\";\n};\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {\n\treadonly _noLocalState: \"3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb\";\n};\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {\n\treadonly _hasLocalState: \"1281acae-6d14-47e7-bc92-71c8ee0819cb\";\n};\n\n/**\n * Data describing a range of session-local IDs (from a remote or local session).\n *\n * A range is composed of local IDs that were generated.\n * @alpha\n */\nexport interface IdCreationRange {\n\treadonly sessionId: SessionId;\n\treadonly ids?: {\n\t\treadonly firstGenCount: number;\n\t\treadonly count: number;\n\t};\n}\n\n/**\n * Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.\n * This value must *NOT* change without careful consideration to compatibility.\n * @internal\n */\nexport const initialClusterCapacity = 512;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, initialClusterCapacity, } from "./0.0.1";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/persisted-types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,mCAAmC,EACnC,wCAAwC,EACxC,sBAAsB,GACtB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.initialClusterCapacity = void 0;
|
|
8
|
+
var _0_0_1_1 = require("./0.0.1");
|
|
9
|
+
Object.defineProperty(exports, "initialClusterCapacity", { enumerable: true, get: function () { return _0_0_1_1.initialClusterCapacity; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/persisted-types/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kCAMiB;AADhB,gHAAA,sBAAsB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tIdCreationRange,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n\tinitialClusterCapacity,\n} from \"./0.0.1\";\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { SessionId, StableId } from "./types";
|
|
6
|
+
import { LocalCompressedId, NumericUuid } from "./identifiers";
|
|
7
|
+
/**
|
|
8
|
+
* Generate a random session ID
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSessionId(): SessionId;
|
|
12
|
+
/**
|
|
13
|
+
* Asserts that the given string is a stable ID.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertIsStableId(stableId: string): StableId;
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that the given string is a stable ID.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertIsSessionId(stableId: string): SessionId;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a random stable ID
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateStableId(): StableId;
|
|
26
|
+
/**
|
|
27
|
+
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
28
|
+
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare function isStableId(str: string): str is StableId;
|
|
32
|
+
/**
|
|
33
|
+
* A numeric comparator used for sorting in ascending order.
|
|
34
|
+
*
|
|
35
|
+
* Handles +/-0 like Map: -0 is equal to +0.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compareFiniteNumbers<T extends number>(a: T, b: T): number;
|
|
38
|
+
/**
|
|
39
|
+
* Compares strings lexically to form a strict partial ordering.
|
|
40
|
+
*/
|
|
41
|
+
export declare function compareStrings<T extends string>(a: T, b: T): number;
|
|
42
|
+
/**
|
|
43
|
+
* Compares bigints to form a strict partial ordering.
|
|
44
|
+
*/
|
|
45
|
+
export declare function compareBigints<T extends bigint>(a: T, b: T): number;
|
|
46
|
+
export declare function genCountFromLocalId(localId: LocalCompressedId): number;
|
|
47
|
+
export declare function localIdFromGenCount(genCount: number): LocalCompressedId;
|
|
48
|
+
export declare function numericUuidFromStableId(stableId: StableId): NumericUuid;
|
|
49
|
+
export declare function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId;
|
|
50
|
+
export declare function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid;
|
|
51
|
+
export declare function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
|
|
52
|
+
export declare function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
|
|
53
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE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,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAG3E"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.addNumericUuids = exports.subtractNumericUuids = exports.offsetNumericUuid = exports.stableIdFromNumericUuid = exports.numericUuidFromStableId = exports.localIdFromGenCount = exports.genCountFromLocalId = exports.compareBigints = exports.compareStrings = exports.compareFiniteNumbers = exports.isStableId = exports.generateStableId = exports.assertIsSessionId = exports.assertIsStableId = exports.createSessionId = void 0;
|
|
8
|
+
/* eslint-disable no-bitwise */
|
|
9
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const hexadecimalCharCodes = Array.from("09afAF").map((c) => c.charCodeAt(0));
|
|
12
|
+
function isHexadecimalCharacter(charCode) {
|
|
13
|
+
return ((charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||
|
|
14
|
+
(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||
|
|
15
|
+
(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5]));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a random session ID
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
function createSessionId() {
|
|
22
|
+
return assertIsStableId((0, uuid_1.v4)());
|
|
23
|
+
}
|
|
24
|
+
exports.createSessionId = createSessionId;
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that the given string is a stable ID.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function assertIsStableId(stableId) {
|
|
30
|
+
(0, core_utils_1.assert)(isStableId(stableId), 0x4a3 /* Expected a StableId */);
|
|
31
|
+
return stableId;
|
|
32
|
+
}
|
|
33
|
+
exports.assertIsStableId = assertIsStableId;
|
|
34
|
+
/**
|
|
35
|
+
* Asserts that the given string is a stable ID.
|
|
36
|
+
*/
|
|
37
|
+
function assertIsSessionId(stableId) {
|
|
38
|
+
assertIsStableId(stableId);
|
|
39
|
+
return stableId;
|
|
40
|
+
}
|
|
41
|
+
exports.assertIsSessionId = assertIsSessionId;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a random stable ID
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function generateStableId() {
|
|
47
|
+
return assertIsStableId((0, uuid_1.v4)());
|
|
48
|
+
}
|
|
49
|
+
exports.generateStableId = generateStableId;
|
|
50
|
+
/**
|
|
51
|
+
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
52
|
+
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
function isStableId(str) {
|
|
56
|
+
if (str.length !== 36) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
for (let i = 0; i < str.length; i++) {
|
|
60
|
+
switch (i) {
|
|
61
|
+
case 8:
|
|
62
|
+
case 13:
|
|
63
|
+
case 18:
|
|
64
|
+
case 23:
|
|
65
|
+
if (str.charAt(i) !== "-") {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 14:
|
|
70
|
+
if (str.charAt(i) !== "4") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case 19: {
|
|
75
|
+
const char = str.charAt(i);
|
|
76
|
+
if (char !== "8" && char !== "9" && char !== "a" && char !== "b") {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
default:
|
|
82
|
+
if (!isHexadecimalCharacter(str.charCodeAt(i))) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
exports.isStableId = isStableId;
|
|
91
|
+
/**
|
|
92
|
+
* A numeric comparator used for sorting in ascending order.
|
|
93
|
+
*
|
|
94
|
+
* Handles +/-0 like Map: -0 is equal to +0.
|
|
95
|
+
*/
|
|
96
|
+
function compareFiniteNumbers(a, b) {
|
|
97
|
+
return a - b;
|
|
98
|
+
}
|
|
99
|
+
exports.compareFiniteNumbers = compareFiniteNumbers;
|
|
100
|
+
/**
|
|
101
|
+
* Compares strings lexically to form a strict partial ordering.
|
|
102
|
+
*/
|
|
103
|
+
function compareStrings(a, b) {
|
|
104
|
+
return a > b ? 1 : a === b ? 0 : -1;
|
|
105
|
+
}
|
|
106
|
+
exports.compareStrings = compareStrings;
|
|
107
|
+
/**
|
|
108
|
+
* Compares bigints to form a strict partial ordering.
|
|
109
|
+
*/
|
|
110
|
+
function compareBigints(a, b) {
|
|
111
|
+
return a > b ? 1 : a === b ? 0 : -1;
|
|
112
|
+
}
|
|
113
|
+
exports.compareBigints = compareBigints;
|
|
114
|
+
function genCountFromLocalId(localId) {
|
|
115
|
+
return -localId;
|
|
116
|
+
}
|
|
117
|
+
exports.genCountFromLocalId = genCountFromLocalId;
|
|
118
|
+
function localIdFromGenCount(genCount) {
|
|
119
|
+
return -genCount;
|
|
120
|
+
}
|
|
121
|
+
exports.localIdFromGenCount = localIdFromGenCount;
|
|
122
|
+
// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
|
|
123
|
+
const versionMask = 0x4n << (19n * 4n); // Version 4
|
|
124
|
+
const variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)
|
|
125
|
+
const upperMask = 0xffffffffffffn << (20n * 4n);
|
|
126
|
+
// Upper mask when version/variant bits are removed
|
|
127
|
+
const strippedUpperMask = upperMask >> 6n;
|
|
128
|
+
const middieBittiesMask = 0xfffn << (16n * 4n);
|
|
129
|
+
// Middie mask when version/variant bits are removed
|
|
130
|
+
const strippedMiddieBittiesMask = middieBittiesMask >> 2n;
|
|
131
|
+
// Note: leading character should be 3 to mask at 0011
|
|
132
|
+
// The more-significant half of the N nibble is used to denote the variant (10xx)
|
|
133
|
+
const lowerMask = 0x3fffffffffffffffn;
|
|
134
|
+
function numericUuidFromStableId(stableId) {
|
|
135
|
+
const uuidU128 = BigInt(`0x${stableId.replace(/-/g, "")}`);
|
|
136
|
+
const upperMasked = uuidU128 & upperMask;
|
|
137
|
+
const middieBittiesMasked = uuidU128 & middieBittiesMask;
|
|
138
|
+
const lowerMasked = uuidU128 & lowerMask;
|
|
139
|
+
const upperMaskedPlaced = upperMasked >> 6n;
|
|
140
|
+
const middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;
|
|
141
|
+
const id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;
|
|
142
|
+
return id;
|
|
143
|
+
}
|
|
144
|
+
exports.numericUuidFromStableId = numericUuidFromStableId;
|
|
145
|
+
function stableIdFromNumericUuid(numericUuid) {
|
|
146
|
+
// bitwise reverse transform
|
|
147
|
+
const upperMasked = (numericUuid & strippedUpperMask) << 6n;
|
|
148
|
+
const middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;
|
|
149
|
+
const lowerMasked = numericUuid & lowerMask;
|
|
150
|
+
const uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;
|
|
151
|
+
// Pad to 32 characters, inserting leading zeroes if needed
|
|
152
|
+
const uuidString = uuidU128.toString(16).padStart(32, "0");
|
|
153
|
+
return `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(12, 16)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}`;
|
|
154
|
+
}
|
|
155
|
+
exports.stableIdFromNumericUuid = stableIdFromNumericUuid;
|
|
156
|
+
function offsetNumericUuid(numericUuid, offset) {
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
158
|
+
return (numericUuid + BigInt(offset));
|
|
159
|
+
}
|
|
160
|
+
exports.offsetNumericUuid = offsetNumericUuid;
|
|
161
|
+
function subtractNumericUuids(a, b) {
|
|
162
|
+
return (a - b);
|
|
163
|
+
}
|
|
164
|
+
exports.subtractNumericUuids = subtractNumericUuids;
|
|
165
|
+
function addNumericUuids(a, b) {
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
167
|
+
return (a + b);
|
|
168
|
+
}
|
|
169
|
+
exports.addNumericUuids = addNumericUuids;
|
|
170
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAC/B,2DAAoD;AACpD,+BAA0B;AAI1B,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAO3E,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC/C,OAAO,CACN,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC9B,OAAO,gBAAgB,CAAC,IAAA,SAAE,GAAE,CAAc,CAAC;AAC5C,CAAC;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AAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,SAAS,CAC1F,EAAE,EACF,EAAE,CACF,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,EAAc,CAAC;AACjF,CAAC;AAZD,0DAYC;AAED,SAAgB,iBAAiB,CAAC,WAAwB,EAAE,MAAc;IACzE,qEAAqE;IACrE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAgB,CAAC;AACtD,CAAC;AAHD,8CAGC;AAED,SAAgB,oBAAoB,CAAC,CAAc,EAAE,CAAc;IAClE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAFD,oDAEC;AAED,SAAgB,eAAe,CAAC,CAAc,EAAE,CAAc;IAC7D,qEAAqE;IACrE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAHD,0CAGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { v4 } from \"uuid\";\nimport { SessionId, StableId } from \"./types\";\nimport { LocalCompressedId, NumericUuid } from \"./identifiers\";\n\nconst hexadecimalCharCodes = Array.from(\"09afAF\").map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/**\n * Generate a random session ID\n * @alpha\n */\nexport function createSessionId(): SessionId {\n\treturn assertIsStableId(v4()) as SessionId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n * @internal\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassert(isStableId(stableId), 0x4a3 /* Expected a StableId */);\n\treturn stableId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsSessionId(stableId: string): SessionId {\n\tassertIsStableId(stableId);\n\treturn stableId as SessionId;\n}\n\n/**\n * Generate a random stable ID\n * @internal\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n * @internal\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== \"-\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== \"4\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== \"8\" && char !== \"9\" && char !== \"a\" && char !== \"b\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Compares bigints to form a strict partial ordering.\n */\nexport function compareBigints<T extends bigint>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\nexport function genCountFromLocalId(localId: LocalCompressedId): number {\n\treturn -localId;\n}\n\nexport function localIdFromGenCount(genCount: number): LocalCompressedId {\n\treturn -genCount as LocalCompressedId;\n}\n\n// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx\nconst versionMask = 0x4n << (19n * 4n); // Version 4\nconst variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)\nconst upperMask = 0xffffffffffffn << (20n * 4n);\n// Upper mask when version/variant bits are removed\nconst strippedUpperMask = upperMask >> 6n;\nconst middieBittiesMask = 0xfffn << (16n * 4n);\n// Middie mask when version/variant bits are removed\nconst strippedMiddieBittiesMask = middieBittiesMask >> 2n;\n// Note: leading character should be 3 to mask at 0011\n// The more-significant half of the N nibble is used to denote the variant (10xx)\nconst lowerMask = 0x3fffffffffffffffn;\n\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuidU128 = BigInt(`0x${stableId.replace(/-/g, \"\")}`);\n\tconst upperMasked = uuidU128 & upperMask;\n\tconst middieBittiesMasked = uuidU128 & middieBittiesMask;\n\tconst lowerMasked = uuidU128 & lowerMask;\n\n\tconst upperMaskedPlaced = upperMasked >> 6n;\n\tconst middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;\n\n\tconst id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;\n\treturn id as NumericUuid;\n}\n\nexport function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId {\n\t// bitwise reverse transform\n\tconst upperMasked = (numericUuid & strippedUpperMask) << 6n;\n\tconst middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;\n\tconst lowerMasked = numericUuid & lowerMask;\n\tconst uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;\n\t// Pad to 32 characters, inserting leading zeroes if needed\n\tconst uuidString = uuidU128.toString(16).padStart(32, \"0\");\n\treturn `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(\n\t\t12,\n\t\t16,\n\t)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}` as StableId;\n}\n\nexport function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (numericUuid + BigInt(offset)) as NumericUuid;\n}\n\nexport function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\treturn (a - b) as NumericUuid;\n}\n\nexport function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (a + b) as NumericUuid;\n}\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A map in which entries are always added in key-sorted order.
|
|
7
|
+
* Supports appending and searching.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AppendOnlySortedMap<K, V> {
|
|
10
|
+
protected readonly comparator: (a: K, b: K) => number;
|
|
11
|
+
protected readonly elements: (K | V)[];
|
|
12
|
+
/**
|
|
13
|
+
* @param comparator - a comparator for keys
|
|
14
|
+
*/
|
|
15
|
+
constructor(comparator: (a: K, b: K) => number);
|
|
16
|
+
/**
|
|
17
|
+
* @returns the number of entries in this map
|
|
18
|
+
*/
|
|
19
|
+
get size(): number;
|
|
20
|
+
/**
|
|
21
|
+
* @returns the min key in the map.
|
|
22
|
+
*/
|
|
23
|
+
minKey(): K | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* @returns the max key in the map.
|
|
26
|
+
*/
|
|
27
|
+
maxKey(): K | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @returns the min value in the map.
|
|
30
|
+
*/
|
|
31
|
+
minValue(): V | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* @returns the min value in the map.
|
|
34
|
+
*/
|
|
35
|
+
maxValue(): V | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* @returns the min key in the map.
|
|
38
|
+
*/
|
|
39
|
+
first(): [K, V] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* @returns the max key in the map.
|
|
42
|
+
*/
|
|
43
|
+
last(): [K, V] | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the element at the insertion index.
|
|
46
|
+
*/
|
|
47
|
+
getAtIndex(index: number): [K, V] | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @returns an iterable of the entries in the map.
|
|
50
|
+
*/
|
|
51
|
+
entries(): IterableIterator<readonly [K, V]>;
|
|
52
|
+
/**
|
|
53
|
+
* @returns an iterable of the keys in the map.
|
|
54
|
+
*/
|
|
55
|
+
keys(): IterableIterator<K>;
|
|
56
|
+
/**
|
|
57
|
+
* @returns an iterable of the values in the map.
|
|
58
|
+
*/
|
|
59
|
+
values(): IterableIterator<V>;
|
|
60
|
+
/**
|
|
61
|
+
* @returns an iterable of the entries in the map, reversed.
|
|
62
|
+
*/
|
|
63
|
+
entriesReversed(): IterableIterator<readonly [K, V]>;
|
|
64
|
+
/**
|
|
65
|
+
* Adds a new key/value pair to the map. `key` must be > to all keys in the map.
|
|
66
|
+
* @param key - the key to add.
|
|
67
|
+
* @param value - the value to add.
|
|
68
|
+
*/
|
|
69
|
+
append(key: K, value: V): void;
|
|
70
|
+
/**
|
|
71
|
+
* Replaces the last key/value pair with the given one. If the map is empty, it simply appends.
|
|
72
|
+
* `key` must be > to all keys in the map prior to the one replaced.
|
|
73
|
+
* @param key - the key to add.
|
|
74
|
+
* @param value - the value to add.
|
|
75
|
+
*/
|
|
76
|
+
replaceLast(key: K, value: V): void;
|
|
77
|
+
/**
|
|
78
|
+
* @param key - the key to lookup.
|
|
79
|
+
* @returns the value associated with `key` if such an entry exists, and undefined otherwise.
|
|
80
|
+
*/
|
|
81
|
+
get(key: K): V | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* @param key - the key to lookup.
|
|
84
|
+
* @returns the entry associated with `key` if such an entry exists, the entry associated with the next lower key if such an entry
|
|
85
|
+
* exists, and undefined otherwise.
|
|
86
|
+
*/
|
|
87
|
+
getPairOrNextLower(key: K): readonly [K, V] | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* @param key - the key to lookup.
|
|
90
|
+
* @returns the entry associated with `key` if such an entry exists, the entry associated with the next higher key if such an entry
|
|
91
|
+
* exists, and undefined otherwise.
|
|
92
|
+
*/
|
|
93
|
+
getPairOrNextHigher(key: K): readonly [K, V] | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Compares two `AppendOnlySortedMap`s.
|
|
96
|
+
*/
|
|
97
|
+
equals(other: AppendOnlySortedMap<K, V>, compareValues: (a: V, b: V) => boolean): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Test-only expensive assertions to check the internal validity of the data structure.
|
|
100
|
+
*/
|
|
101
|
+
assertValid(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Queries a range of entries.
|
|
104
|
+
* @param from - the key to start the range query at, inclusive.
|
|
105
|
+
* @param to - the key to end the range query at, inclusive.
|
|
106
|
+
* @returns the range of entries.
|
|
107
|
+
*/
|
|
108
|
+
getRange(from: K, to: K): IterableIterator<readonly [K, V]>;
|
|
109
|
+
protected getPairOrNextLowerBy<T>(search: T, comparator: (search: T, key: K, value: V) => number): readonly [K, V] | undefined;
|
|
110
|
+
private getKeyIndexOfOrNextLower;
|
|
111
|
+
protected getPairOrNextHigherBy<T>(search: T, comparator: (search: T, key: K, value: V) => number): readonly [K, V] | undefined;
|
|
112
|
+
private getKeyIndexOfOrNextHigher;
|
|
113
|
+
/**
|
|
114
|
+
* The value xor'd with the result index when a search fails.
|
|
115
|
+
*/
|
|
116
|
+
static readonly failureXor = -1;
|
|
117
|
+
/**
|
|
118
|
+
* Performs a binary search on the sorted array.
|
|
119
|
+
* @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd
|
|
120
|
+
* with `failureXor`. Note that negating is not an adequate solution as that could result in -0.
|
|
121
|
+
*/
|
|
122
|
+
static keyIndexOf<T, K, V>(elements: readonly (K | V)[], search: T, comparator: (search: T, key: K, value: V) => number): number;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=appendOnlySortedMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendOnlySortedMap.d.ts","sourceRoot":"","sources":["../src/appendOnlySortedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,CAAC,EAAE,CAAC;IAMjB,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IALxE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAM;IAE5C;;OAEG;gBACmC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAExE;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACI,MAAM,IAAI,CAAC,GAAG,SAAS;IAI9B;;OAEG;IACI,MAAM,IAAI,CAAC,GAAG,SAAS;IAI9B;;OAEG;IACI,QAAQ,IAAI,CAAC,GAAG,SAAS;IAIhC;;OAEG;IACI,QAA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