@fluidframework/container-runtime 2.0.0-dev.7.4.0.217212 → 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.
Files changed (233) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/api-extractor.json +0 -3
  3. package/api-report/container-runtime.api.md +77 -73
  4. package/dist/blobManager.d.ts +4 -4
  5. package/dist/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager.js.map +1 -1
  7. package/dist/container-runtime-alpha.d.ts +1361 -132
  8. package/dist/container-runtime-beta.d.ts +40 -2
  9. package/dist/container-runtime-public.d.ts +40 -2
  10. package/dist/container-runtime-untrimmed.d.ts +106 -93
  11. package/dist/containerRuntime.d.ts +19 -17
  12. package/dist/containerRuntime.d.ts.map +1 -1
  13. package/dist/containerRuntime.js +44 -24
  14. package/dist/containerRuntime.js.map +1 -1
  15. package/dist/dataStores.d.ts +10 -15
  16. package/dist/dataStores.d.ts.map +1 -1
  17. package/dist/dataStores.js +63 -36
  18. package/dist/dataStores.js.map +1 -1
  19. package/dist/gc/garbageCollection.d.ts +29 -10
  20. package/dist/gc/garbageCollection.d.ts.map +1 -1
  21. package/dist/gc/garbageCollection.js +149 -67
  22. package/dist/gc/garbageCollection.js.map +1 -1
  23. package/dist/gc/gcConfigs.d.ts.map +1 -1
  24. package/dist/gc/gcConfigs.js +34 -37
  25. package/dist/gc/gcConfigs.js.map +1 -1
  26. package/dist/gc/gcDefinitions.d.ts +97 -44
  27. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  28. package/dist/gc/gcDefinitions.js +26 -16
  29. package/dist/gc/gcDefinitions.js.map +1 -1
  30. package/dist/gc/gcHelpers.d.ts +18 -25
  31. package/dist/gc/gcHelpers.d.ts.map +1 -1
  32. package/dist/gc/gcHelpers.js +29 -45
  33. package/dist/gc/gcHelpers.js.map +1 -1
  34. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  35. package/dist/gc/gcTelemetry.js +14 -3
  36. package/dist/gc/gcTelemetry.js.map +1 -1
  37. package/dist/gc/gcUnreferencedStateTracker.d.ts +11 -5
  38. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
  39. package/dist/gc/gcUnreferencedStateTracker.js +43 -19
  40. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
  41. package/dist/gc/index.d.ts +1 -1
  42. package/dist/gc/index.d.ts.map +1 -1
  43. package/dist/gc/index.js +4 -4
  44. package/dist/gc/index.js.map +1 -1
  45. package/dist/index.d.ts +13 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +16 -5
  48. package/dist/index.js.map +1 -1
  49. package/dist/messageTypes.d.ts +13 -5
  50. package/dist/messageTypes.d.ts.map +1 -1
  51. package/dist/messageTypes.js +5 -0
  52. package/dist/messageTypes.js.map +1 -1
  53. package/dist/packageVersion.d.ts +1 -1
  54. package/dist/packageVersion.js +1 -1
  55. package/dist/packageVersion.js.map +1 -1
  56. package/dist/pendingStateManager.d.ts +1 -0
  57. package/dist/pendingStateManager.d.ts.map +1 -1
  58. package/dist/pendingStateManager.js +1 -0
  59. package/dist/pendingStateManager.js.map +1 -1
  60. package/dist/summary/orderedClientElection.d.ts +1 -1
  61. package/dist/summary/orderedClientElection.js.map +1 -1
  62. package/dist/summary/summarizerTypes.d.ts +28 -28
  63. package/dist/summary/summarizerTypes.js.map +1 -1
  64. package/dist/summary/summaryCollection.d.ts +3 -3
  65. package/dist/summary/summaryCollection.js.map +1 -1
  66. package/dist/summary/summaryFormat.d.ts +3 -3
  67. package/dist/summary/summaryFormat.js.map +1 -1
  68. package/lib/blobManager.d.ts +4 -4
  69. package/lib/blobManager.d.ts.map +1 -1
  70. package/lib/blobManager.js.map +1 -1
  71. package/lib/container-runtime-alpha.d.ts +1361 -132
  72. package/lib/container-runtime-beta.d.ts +40 -2
  73. package/lib/container-runtime-public.d.ts +40 -2
  74. package/lib/container-runtime-untrimmed.d.ts +106 -93
  75. package/lib/containerRuntime.d.ts +19 -17
  76. package/lib/containerRuntime.d.ts.map +1 -1
  77. package/lib/containerRuntime.js +46 -26
  78. package/lib/containerRuntime.js.map +1 -1
  79. package/lib/dataStores.d.ts +10 -15
  80. package/lib/dataStores.d.ts.map +1 -1
  81. package/lib/dataStores.js +65 -38
  82. package/lib/dataStores.js.map +1 -1
  83. package/lib/gc/garbageCollection.d.ts +29 -10
  84. package/lib/gc/garbageCollection.d.ts.map +1 -1
  85. package/lib/gc/garbageCollection.js +151 -69
  86. package/lib/gc/garbageCollection.js.map +1 -1
  87. package/lib/gc/gcConfigs.d.ts.map +1 -1
  88. package/lib/gc/gcConfigs.js +37 -40
  89. package/lib/gc/gcConfigs.js.map +1 -1
  90. package/lib/gc/gcDefinitions.d.ts +97 -44
  91. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  92. package/lib/gc/gcDefinitions.js +25 -15
  93. package/lib/gc/gcDefinitions.js.map +1 -1
  94. package/lib/gc/gcHelpers.d.ts +18 -25
  95. package/lib/gc/gcHelpers.d.ts.map +1 -1
  96. package/lib/gc/gcHelpers.js +27 -43
  97. package/lib/gc/gcHelpers.js.map +1 -1
  98. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  99. package/lib/gc/gcTelemetry.js +14 -3
  100. package/lib/gc/gcTelemetry.js.map +1 -1
  101. package/lib/gc/gcUnreferencedStateTracker.d.ts +11 -5
  102. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
  103. package/lib/gc/gcUnreferencedStateTracker.js +43 -19
  104. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
  105. package/lib/gc/index.d.ts +1 -1
  106. package/lib/gc/index.d.ts.map +1 -1
  107. package/lib/gc/index.js +1 -1
  108. package/lib/gc/index.js.map +1 -1
  109. package/lib/index.d.ts +13 -1
  110. package/lib/index.d.ts.map +1 -1
  111. package/lib/index.js +15 -1
  112. package/lib/index.js.map +1 -1
  113. package/lib/messageTypes.d.ts +13 -5
  114. package/lib/messageTypes.d.ts.map +1 -1
  115. package/lib/messageTypes.js +5 -0
  116. package/lib/messageTypes.js.map +1 -1
  117. package/lib/packageVersion.d.ts +1 -1
  118. package/lib/packageVersion.js +1 -1
  119. package/lib/packageVersion.js.map +1 -1
  120. package/lib/pendingStateManager.d.ts +1 -0
  121. package/lib/pendingStateManager.d.ts.map +1 -1
  122. package/lib/pendingStateManager.js +1 -0
  123. package/lib/pendingStateManager.js.map +1 -1
  124. package/lib/summary/orderedClientElection.d.ts +1 -1
  125. package/lib/summary/orderedClientElection.js.map +1 -1
  126. package/lib/summary/summarizerTypes.d.ts +28 -28
  127. package/lib/summary/summarizerTypes.js.map +1 -1
  128. package/lib/summary/summaryCollection.d.ts +3 -3
  129. package/lib/summary/summaryCollection.js.map +1 -1
  130. package/lib/summary/summaryFormat.d.ts +3 -3
  131. package/lib/summary/summaryFormat.js.map +1 -1
  132. package/package.json +18 -15
  133. package/src/blobManager.ts +5 -5
  134. package/src/containerRuntime.ts +66 -40
  135. package/src/dataStores.ts +118 -59
  136. package/src/gc/garbageCollection.md +14 -15
  137. package/src/gc/garbageCollection.ts +182 -75
  138. package/src/gc/gcConfigs.ts +50 -52
  139. package/src/gc/gcDefinitions.ts +112 -50
  140. package/src/gc/gcHelpers.ts +31 -52
  141. package/src/gc/gcTelemetry.ts +16 -4
  142. package/src/gc/gcUnreferencedStateTracker.ts +61 -22
  143. package/src/gc/index.ts +4 -3
  144. package/src/index.ts +17 -1
  145. package/src/messageTypes.ts +16 -2
  146. package/src/packageVersion.ts +1 -1
  147. package/src/pendingStateManager.ts +1 -0
  148. package/src/summary/orderedClientElection.ts +1 -1
  149. package/src/summary/summarizerTypes.ts +28 -28
  150. package/src/summary/summaryCollection.ts +3 -3
  151. package/src/summary/summaryFormat.ts +3 -3
  152. package/dist/id-compressor/appendOnlySortedMap.d.ts +0 -124
  153. package/dist/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
  154. package/dist/id-compressor/appendOnlySortedMap.js +0 -318
  155. package/dist/id-compressor/appendOnlySortedMap.js.map +0 -1
  156. package/dist/id-compressor/finalSpace.d.ts +0 -29
  157. package/dist/id-compressor/finalSpace.d.ts.map +0 -1
  158. package/dist/id-compressor/finalSpace.js +0 -62
  159. package/dist/id-compressor/finalSpace.js.map +0 -1
  160. package/dist/id-compressor/idCompressor.d.ts +0 -54
  161. package/dist/id-compressor/idCompressor.d.ts.map +0 -1
  162. package/dist/id-compressor/idCompressor.js +0 -495
  163. package/dist/id-compressor/idCompressor.js.map +0 -1
  164. package/dist/id-compressor/identifiers.d.ts +0 -32
  165. package/dist/id-compressor/identifiers.d.ts.map +0 -1
  166. package/dist/id-compressor/identifiers.js +0 -15
  167. package/dist/id-compressor/identifiers.js.map +0 -1
  168. package/dist/id-compressor/index.d.ts +0 -13
  169. package/dist/id-compressor/index.d.ts.map +0 -1
  170. package/dist/id-compressor/index.js +0 -32
  171. package/dist/id-compressor/index.js.map +0 -1
  172. package/dist/id-compressor/persistanceUtilities.d.ts +0 -22
  173. package/dist/id-compressor/persistanceUtilities.d.ts.map +0 -1
  174. package/dist/id-compressor/persistanceUtilities.js +0 -43
  175. package/dist/id-compressor/persistanceUtilities.js.map +0 -1
  176. package/dist/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
  177. package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
  178. package/dist/id-compressor/sessionSpaceNormalizer.js +0 -80
  179. package/dist/id-compressor/sessionSpaceNormalizer.js.map +0 -1
  180. package/dist/id-compressor/sessions.d.ts +0 -115
  181. package/dist/id-compressor/sessions.d.ts.map +0 -1
  182. package/dist/id-compressor/sessions.js +0 -305
  183. package/dist/id-compressor/sessions.js.map +0 -1
  184. package/dist/id-compressor/utilities.d.ts +0 -52
  185. package/dist/id-compressor/utilities.d.ts.map +0 -1
  186. package/dist/id-compressor/utilities.js +0 -169
  187. package/dist/id-compressor/utilities.js.map +0 -1
  188. package/lib/id-compressor/appendOnlySortedMap.d.ts +0 -124
  189. package/lib/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
  190. package/lib/id-compressor/appendOnlySortedMap.js +0 -314
  191. package/lib/id-compressor/appendOnlySortedMap.js.map +0 -1
  192. package/lib/id-compressor/finalSpace.d.ts +0 -29
  193. package/lib/id-compressor/finalSpace.d.ts.map +0 -1
  194. package/lib/id-compressor/finalSpace.js +0 -58
  195. package/lib/id-compressor/finalSpace.js.map +0 -1
  196. package/lib/id-compressor/idCompressor.d.ts +0 -54
  197. package/lib/id-compressor/idCompressor.d.ts.map +0 -1
  198. package/lib/id-compressor/idCompressor.js +0 -491
  199. package/lib/id-compressor/idCompressor.js.map +0 -1
  200. package/lib/id-compressor/identifiers.d.ts +0 -32
  201. package/lib/id-compressor/identifiers.d.ts.map +0 -1
  202. package/lib/id-compressor/identifiers.js +0 -11
  203. package/lib/id-compressor/identifiers.js.map +0 -1
  204. package/lib/id-compressor/index.d.ts +0 -13
  205. package/lib/id-compressor/index.d.ts.map +0 -1
  206. package/lib/id-compressor/index.js +0 -13
  207. package/lib/id-compressor/index.js.map +0 -1
  208. package/lib/id-compressor/persistanceUtilities.d.ts +0 -22
  209. package/lib/id-compressor/persistanceUtilities.d.ts.map +0 -1
  210. package/lib/id-compressor/persistanceUtilities.js +0 -34
  211. package/lib/id-compressor/persistanceUtilities.js.map +0 -1
  212. package/lib/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
  213. package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
  214. package/lib/id-compressor/sessionSpaceNormalizer.js +0 -76
  215. package/lib/id-compressor/sessionSpaceNormalizer.js.map +0 -1
  216. package/lib/id-compressor/sessions.d.ts +0 -115
  217. package/lib/id-compressor/sessions.d.ts.map +0 -1
  218. package/lib/id-compressor/sessions.js +0 -290
  219. package/lib/id-compressor/sessions.js.map +0 -1
  220. package/lib/id-compressor/utilities.d.ts +0 -52
  221. package/lib/id-compressor/utilities.d.ts.map +0 -1
  222. package/lib/id-compressor/utilities.js +0 -151
  223. package/lib/id-compressor/utilities.js.map +0 -1
  224. package/src/id-compressor/README.md +0 -69
  225. package/src/id-compressor/appendOnlySortedMap.ts +0 -366
  226. package/src/id-compressor/finalSpace.ts +0 -67
  227. package/src/id-compressor/idCompressor.ts +0 -630
  228. package/src/id-compressor/identifiers.ts +0 -42
  229. package/src/id-compressor/index.ts +0 -26
  230. package/src/id-compressor/persistanceUtilities.ts +0 -58
  231. package/src/id-compressor/sessionSpaceNormalizer.ts +0 -83
  232. package/src/id-compressor/sessions.ts +0 -405
  233. package/src/id-compressor/utilities.ts +0 -190
@@ -1,366 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- /* eslint-disable tsdoc/syntax */
7
- /* eslint-disable no-bitwise */
8
- import { assert } from "@fluidframework/core-utils";
9
-
10
- /**
11
- * A map in which entries are always added in key-sorted order.
12
- * Supports appending and searching.
13
- */
14
- export class AppendOnlySortedMap<K, V> {
15
- protected readonly elements: (K | V)[] = [];
16
-
17
- /**
18
- * @param comparator - a comparator for keys
19
- */
20
- public constructor(protected readonly comparator: (a: K, b: K) => number) {}
21
-
22
- /**
23
- * @returns the number of entries in this map
24
- */
25
- public get size(): number {
26
- return this.elements.length / 2;
27
- }
28
-
29
- /**
30
- * @returns the min key in the map.
31
- */
32
- public minKey(): K | undefined {
33
- return this.elements[0] as K | undefined;
34
- }
35
-
36
- /**
37
- * @returns the max key in the map.
38
- */
39
- public maxKey(): K | undefined {
40
- return this.elements[this.elements.length - 2] as K | undefined;
41
- }
42
-
43
- /**
44
- * @returns the min value in the map.
45
- */
46
- public minValue(): V | undefined {
47
- return this.elements[1] as V | undefined;
48
- }
49
-
50
- /**
51
- * @returns the min value in the map.
52
- */
53
- public maxValue(): V | undefined {
54
- return this.elements[this.elements.length - 1] as V | undefined;
55
- }
56
-
57
- /**
58
- * @returns the min key in the map.
59
- */
60
- public first(): [K, V] | undefined {
61
- const { elements } = this;
62
- const { length } = elements;
63
- if (length === 0) {
64
- return undefined;
65
- }
66
- return [elements[0] as K, elements[1] as V];
67
- }
68
-
69
- /**
70
- * @returns the max key in the map.
71
- */
72
- public last(): [K, V] | undefined {
73
- const { elements } = this;
74
- const { length } = elements;
75
- if (length === 0) {
76
- return undefined;
77
- }
78
- const lastKeyIndex = length - 2;
79
- return [elements[lastKeyIndex] as K, elements[lastKeyIndex + 1] as V];
80
- }
81
-
82
- /**
83
- * Returns the element at the insertion index.
84
- */
85
- public getAtIndex(index: number): [K, V] | undefined {
86
- const realIndex = index * 2;
87
- const { elements } = this;
88
- if (realIndex < 0 || realIndex > elements.length - 1) {
89
- return undefined;
90
- }
91
- return [elements[realIndex] as K, elements[realIndex + 1] as V];
92
- }
93
-
94
- /**
95
- * @returns an iterable of the entries in the map.
96
- */
97
- public *entries(): IterableIterator<readonly [K, V]> {
98
- const { elements } = this;
99
- for (let i = 0; i < elements.length; i += 2) {
100
- yield [elements[i] as K, elements[i + 1] as V];
101
- }
102
- }
103
-
104
- /**
105
- * @returns an iterable of the keys in the map.
106
- */
107
- public *keys(): IterableIterator<K> {
108
- const { elements } = this;
109
- for (let i = 0; i < elements.length; i += 2) {
110
- yield elements[i] as K;
111
- }
112
- }
113
-
114
- /**
115
- * @returns an iterable of the values in the map.
116
- */
117
- public *values(): IterableIterator<V> {
118
- const { elements } = this;
119
- for (let i = 0; i < elements.length; i += 2) {
120
- yield elements[i + 1] as V;
121
- }
122
- }
123
-
124
- /**
125
- * @returns an iterable of the entries in the map, reversed.
126
- */
127
- public *entriesReversed(): IterableIterator<readonly [K, V]> {
128
- const { elements } = this;
129
- for (let i = elements.length - 2; i >= 0; i -= 2) {
130
- yield [elements[i] as K, elements[i + 1] as V];
131
- }
132
- }
133
-
134
- /**
135
- * Adds a new key/value pair to the map. `key` must be > to all keys in the map.
136
- * @param key - the key to add.
137
- * @param value - the value to add.
138
- */
139
- public append(key: K, value: V): void {
140
- const { elements } = this;
141
- const { length } = elements;
142
- if (length !== 0 && this.comparator(key, this.maxKey() as K) <= 0) {
143
- throw new Error("Inserted key must be > all others in the map.");
144
- }
145
- elements.push(key);
146
- elements.push(value);
147
- }
148
-
149
- /**
150
- * Replaces the last key/value pair with the given one. If the map is empty, it simply appends.
151
- * `key` must be > to all keys in the map prior to the one replaced.
152
- * @param key - the key to add.
153
- * @param value - the value to add.
154
- */
155
- public replaceLast(key: K, value: V): void {
156
- const { elements, comparator } = this;
157
- const { length } = elements;
158
- if (length !== 0) {
159
- elements.pop();
160
- elements.pop();
161
- if (comparator(key, this.maxKey() as K) <= 0) {
162
- throw new Error("Inserted key must be > all others in the map.");
163
- }
164
- }
165
- elements.push(key);
166
- elements.push(value);
167
- }
168
-
169
- /**
170
- * @param key - the key to lookup.
171
- * @returns the value associated with `key` if such an entry exists, and undefined otherwise.
172
- */
173
- public get(key: K): V | undefined {
174
- const index = AppendOnlySortedMap.keyIndexOf(this.elements, key, this.comparator);
175
- if (index < 0) {
176
- return undefined;
177
- }
178
- return this.elements[index + 1] as V;
179
- }
180
-
181
- /**
182
- * @param key - the key to lookup.
183
- * @returns the entry associated with `key` if such an entry exists, the entry associated with the next lower key if such an entry
184
- * exists, and undefined otherwise.
185
- */
186
- public getPairOrNextLower(key: K): readonly [K, V] | undefined {
187
- return this.getPairOrNextLowerBy(key, this.comparator);
188
- }
189
-
190
- /**
191
- * @param key - the key to lookup.
192
- * @returns the entry associated with `key` if such an entry exists, the entry associated with the next higher key if such an entry
193
- * exists, and undefined otherwise.
194
- */
195
- public getPairOrNextHigher(key: K): readonly [K, V] | undefined {
196
- return this.getPairOrNextHigherBy(key, this.comparator);
197
- }
198
-
199
- /**
200
- * Compares two `AppendOnlySortedMap`s.
201
- */
202
- public equals(
203
- other: AppendOnlySortedMap<K, V>,
204
- compareValues: (a: V, b: V) => boolean,
205
- ): boolean {
206
- if (other === this) {
207
- return true;
208
- }
209
-
210
- if (this.elements.length !== other.elements.length) {
211
- return false;
212
- }
213
-
214
- for (let i = this.elements.length - 2; i >= 0; i -= 2) {
215
- const keyThis = this.elements[i] as K;
216
- const valueThis = this.elements[i + 1] as V;
217
- const keyOther = other.elements[i] as K;
218
- const valueOther = other.elements[i + 1] as V;
219
- if (this.comparator(keyThis, keyOther) !== 0) {
220
- return false;
221
- }
222
- if (!compareValues(valueThis, valueOther)) {
223
- return false;
224
- }
225
- }
226
-
227
- return true;
228
- }
229
-
230
- /**
231
- * Test-only expensive assertions to check the internal validity of the data structure.
232
- */
233
- public assertValid(): void {
234
- let prev: readonly [K, unknown] | undefined;
235
- for (const kv of this.entries()) {
236
- if (prev !== undefined) {
237
- assert(
238
- this.comparator(kv[0], prev[0]) > 0,
239
- 0x752 /* Keys in map must be sorted. */,
240
- );
241
- }
242
- prev = kv;
243
- }
244
- }
245
-
246
- /**
247
- * Queries a range of entries.
248
- * @param from - the key to start the range query at, inclusive.
249
- * @param to - the key to end the range query at, inclusive.
250
- * @returns the range of entries.
251
- */
252
- public *getRange(from: K, to: K): IterableIterator<readonly [K, V]> {
253
- const keyIndexFrom = this.getKeyIndexOfOrNextHigher(from, this.comparator);
254
- if (keyIndexFrom === undefined) {
255
- return;
256
- }
257
-
258
- const keyIndexTo = this.getKeyIndexOfOrNextLower(to, this.comparator);
259
- if (keyIndexTo === undefined) {
260
- return;
261
- }
262
-
263
- for (let i = keyIndexFrom; i <= keyIndexTo; i += 2) {
264
- yield [this.elements[i] as K, this.elements[i + 1] as V];
265
- }
266
- }
267
-
268
- protected getPairOrNextLowerBy<T>(
269
- search: T,
270
- comparator: (search: T, key: K, value: V) => number,
271
- ): readonly [K, V] | undefined {
272
- const keyIndex = this.getKeyIndexOfOrNextLower(search, comparator);
273
- if (keyIndex === undefined) {
274
- return undefined;
275
- }
276
-
277
- return [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];
278
- }
279
-
280
- private getKeyIndexOfOrNextLower<T>(
281
- search: T,
282
- comparator: (search: T, key: K, value: V) => number,
283
- ): number | undefined {
284
- const { elements } = this;
285
- if (elements.length === 0) {
286
- return undefined;
287
- }
288
- let keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);
289
- if (keyIndex < 0) {
290
- keyIndex ^= AppendOnlySortedMap.failureXor;
291
- if (keyIndex > 0) {
292
- return keyIndex - 2;
293
- }
294
- return undefined;
295
- }
296
- return keyIndex;
297
- }
298
-
299
- protected getPairOrNextHigherBy<T>(
300
- search: T,
301
- comparator: (search: T, key: K, value: V) => number,
302
- ): readonly [K, V] | undefined {
303
- const keyIndex = this.getKeyIndexOfOrNextHigher(search, comparator);
304
- if (keyIndex === undefined) {
305
- return undefined;
306
- }
307
-
308
- return [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];
309
- }
310
-
311
- private getKeyIndexOfOrNextHigher<T>(
312
- search: T,
313
- comparator: (search: T, key: K, value: V) => number,
314
- ): number | undefined {
315
- const { elements } = this;
316
- const { length } = elements;
317
- if (length === 0) {
318
- return undefined;
319
- }
320
- let keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);
321
- if (keyIndex < 0) {
322
- keyIndex ^= AppendOnlySortedMap.failureXor;
323
- if (keyIndex < length) {
324
- return keyIndex;
325
- }
326
- return undefined;
327
- }
328
- return keyIndex;
329
- }
330
-
331
- /**
332
- * The value xor'd with the result index when a search fails.
333
- */
334
- public static readonly failureXor = -1;
335
-
336
- /**
337
- * Performs a binary search on the sorted array.
338
- * @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd
339
- * with `failureXor`. Note that negating is not an adequate solution as that could result in -0.
340
- */
341
- public static keyIndexOf<T, K, V>(
342
- elements: readonly (K | V)[],
343
- search: T,
344
- comparator: (search: T, key: K, value: V) => number,
345
- ): number {
346
- // Low, high, and mid are addresses of [K,V] pairs and *not* key indices
347
- let low = 0;
348
- let high = elements.length / 2;
349
- let mid = high >> 1;
350
- while (low < high) {
351
- const keyIndex = mid * 2;
352
- const c = comparator(search, elements[keyIndex] as K, elements[keyIndex + 1] as V);
353
- if (c > 0) {
354
- low = mid + 1;
355
- } else if (c < 0) {
356
- high = mid;
357
- } else if (c === 0) {
358
- return keyIndex;
359
- } else {
360
- throw new Error("Invalid comparator.");
361
- }
362
- mid = (low + high) >> 1;
363
- }
364
- return (mid * 2) ^ AppendOnlySortedMap.failureXor;
365
- }
366
- }
@@ -1,67 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { assert } from "@fluidframework/core-utils";
7
- import { IdCluster, clustersEqual, lastAllocatedFinal, lastFinalizedFinal } from "./sessions";
8
- import { FinalCompressedId } from "./identifiers";
9
-
10
- /**
11
- * All IDs that have been finalized (acked), grouped into clusters sorted by their base final IDs.
12
- * These clusters span the positive integer space and are not sparse, meaning a cluster's base final
13
- * ID will always be one greater than the last final ID in the previous cluster (or 0 if there is not one).
14
- */
15
- export class FinalSpace {
16
- private readonly clusterList: IdCluster[] = [];
17
-
18
- public get clusters(): readonly IdCluster[] {
19
- return this.clusterList;
20
- }
21
-
22
- public getLastCluster(): IdCluster | undefined {
23
- return this.clusterList[this.clusterList.length - 1];
24
- }
25
-
26
- public addCluster(newCluster: IdCluster) {
27
- const lastCluster = this.getLastCluster();
28
- assert(
29
- lastCluster === undefined ||
30
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
31
- newCluster.baseFinalId === lastCluster.baseFinalId + lastCluster.capacity,
32
- 0x753 /* Cluster insert to final_space is out of order. */,
33
- );
34
- this.clusterList.push(newCluster);
35
- }
36
-
37
- /**
38
- * @returns the upper bound (exclusive) of finalized IDs in final space, i.e. one greater than the last final ID in the last cluster.
39
- * Note: this does not include allocated but unfinalized space in clusters.
40
- */
41
- public getFinalizedIdLimit(): FinalCompressedId {
42
- const lastCluster = this.getLastCluster();
43
- return lastCluster === undefined
44
- ? (0 as FinalCompressedId)
45
- : (((lastFinalizedFinal(lastCluster) as number) + 1) as FinalCompressedId);
46
- }
47
-
48
- /**
49
- * @returns the upper bound (exclusive) of allocated IDs in final space, i.e. one greater than the last final ID in the last cluster.
50
- * Note: this does includes all allocated IDs in clusters.
51
- */
52
- public getAllocatedIdLimit(): FinalCompressedId {
53
- const lastCluster = this.getLastCluster();
54
- return lastCluster === undefined
55
- ? (0 as FinalCompressedId)
56
- : (((lastAllocatedFinal(lastCluster) as number) + 1) as FinalCompressedId);
57
- }
58
-
59
- public equals(other: FinalSpace): boolean {
60
- for (let i = 0; i < this.clusterList.length; i++) {
61
- if (!clustersEqual(this.clusterList[i], other.clusterList[i])) {
62
- return false;
63
- }
64
- }
65
- return this.clusterList.length === other.clusterList.length;
66
- }
67
- }