@firebase/database 0.8.3-canary.fb90580e5 → 0.8.3
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/dist/index.d.ts +0 -16
- package/dist/index.esm.js +34 -163
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm2017.js +34 -161
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.node.cjs.js +34 -163
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/api/Query.d.ts +0 -2
- package/dist/src/core/AuthTokenProvider.d.ts +2 -2
- package/dist/src/core/Repo.d.ts +21 -10
- package/dist/src/core/RepoManager.d.ts +2 -8
- package/dist/src/core/util/NextPushId.d.ts +0 -2
- package/dist/src/core/util/util.d.ts +0 -8
- package/dist/src/core/view/QueryParams.d.ts +0 -6
- package/package.json +13 -16
- package/dist/exp/exp/index.d.ts +0 -29
- package/dist/exp/index.d.ts +0 -49
- package/dist/exp/index.esm.js +0 -15735
- package/dist/exp/index.esm.js.map +0 -1
- package/dist/exp/index.esm2017.js +0 -15139
- package/dist/exp/index.esm2017.js.map +0 -1
- package/dist/exp/index.node.cjs.js +0 -15746
- package/dist/exp/index.node.cjs.js.map +0 -1
- package/dist/exp/index.node.d.ts +0 -83
- package/dist/exp/src/api/DataSnapshot.d.ts +0 -99
- package/dist/exp/src/api/Database.d.ts +0 -87
- package/dist/exp/src/api/Query.d.ts +0 -193
- package/dist/exp/src/api/Reference.d.ts +0 -106
- package/dist/exp/src/api/TransactionResult.d.ts +0 -30
- package/dist/exp/src/api/internal.d.ts +0 -55
- package/dist/exp/src/api/onDisconnect.d.ts +0 -60
- package/dist/exp/src/api/test_access.d.ts +0 -42
- package/dist/exp/src/core/AuthTokenProvider.d.ts +0 -50
- package/dist/exp/src/core/CompoundWrite.d.ts +0 -77
- package/dist/exp/src/core/PersistentConnection.d.ts +0 -148
- package/dist/exp/src/core/ReadonlyRestClient.d.ts +0 -73
- package/dist/exp/src/core/Repo.d.ts +0 -121
- package/dist/exp/src/core/RepoInfo.d.ts +0 -59
- package/dist/exp/src/core/RepoManager.d.ts +0 -78
- package/dist/exp/src/core/Repo_transaction.d.ts +0 -33
- package/dist/exp/src/core/ServerActions.d.ts +0 -85
- package/dist/exp/src/core/SnapshotHolder.d.ts +0 -28
- package/dist/exp/src/core/SparseSnapshotTree.d.ts +0 -61
- package/dist/exp/src/core/SyncPoint.d.ts +0 -84
- package/dist/exp/src/core/SyncTree.d.ts +0 -236
- package/dist/exp/src/core/WriteTree.d.ts +0 -295
- package/dist/exp/src/core/operation/AckUserWrite.d.ts +0 -42
- package/dist/exp/src/core/operation/ListenComplete.d.ts +0 -32
- package/dist/exp/src/core/operation/Merge.d.ts +0 -46
- package/dist/exp/src/core/operation/Operation.d.ts +0 -78
- package/dist/exp/src/core/operation/Overwrite.d.ts +0 -35
- package/dist/exp/src/core/snap/ChildrenNode.d.ts +0 -180
- package/dist/exp/src/core/snap/IndexMap.d.ts +0 -43
- package/dist/exp/src/core/snap/LeafNode.d.ts +0 -107
- package/dist/exp/src/core/snap/Node.d.ts +0 -148
- package/dist/exp/src/core/snap/childSet.d.ts +0 -34
- package/dist/exp/src/core/snap/comparators.d.ts +0 -19
- package/dist/exp/src/core/snap/indexes/Index.d.ts +0 -69
- package/dist/exp/src/core/snap/indexes/KeyIndex.d.ts +0 -54
- package/dist/exp/src/core/snap/indexes/PathIndex.d.ts +0 -54
- package/dist/exp/src/core/snap/indexes/PriorityIndex.d.ts +0 -58
- package/dist/exp/src/core/snap/indexes/ValueIndex.d.ts +0 -56
- package/dist/exp/src/core/snap/nodeFromJSON.d.ts +0 -25
- package/dist/exp/src/core/snap/snap.d.ts +0 -29
- package/dist/exp/src/core/stats/StatsCollection.d.ts +0 -28
- package/dist/exp/src/core/stats/StatsListener.d.ts +0 -31
- package/dist/exp/src/core/stats/StatsManager.d.ts +0 -24
- package/dist/exp/src/core/stats/StatsReporter.d.ts +0 -33
- package/dist/exp/src/core/storage/DOMStorageWrapper.d.ts +0 -55
- package/dist/exp/src/core/storage/MemoryStorage.d.ts +0 -29
- package/dist/exp/src/core/storage/storage.d.ts +0 -22
- package/dist/exp/src/core/util/EventEmitter.d.ts +0 -45
- package/dist/exp/src/core/util/ImmutableTree.d.ts +0 -157
- package/dist/exp/src/core/util/NextPushId.d.ts +0 -33
- package/dist/exp/src/core/util/OnlineMonitor.d.ts +0 -40
- package/dist/exp/src/core/util/Path.d.ts +0 -132
- package/dist/exp/src/core/util/ServerValues.d.ts +0 -66
- package/dist/exp/src/core/util/SortedMap.d.ts +0 -362
- package/dist/exp/src/core/util/Tree.d.ts +0 -134
- package/dist/exp/src/core/util/VisibilityMonitor.d.ts +0 -30
- package/dist/exp/src/core/util/libs/parser.d.ts +0 -37
- package/dist/exp/src/core/util/misc.d.ts +0 -19
- package/dist/exp/src/core/util/util.d.ts +0 -232
- package/dist/exp/src/core/util/validation.d.ts +0 -108
- package/dist/exp/src/core/version.d.ts +0 -19
- package/dist/exp/src/core/view/CacheNode.d.ts +0 -59
- package/dist/exp/src/core/view/Change.d.ts +0 -74
- package/dist/exp/src/core/view/ChildChangeAccumulator.d.ts +0 -22
- package/dist/exp/src/core/view/CompleteChildSource.d.ts +0 -91
- package/dist/exp/src/core/view/Event.d.ts +0 -102
- package/dist/exp/src/core/view/EventGenerator.d.ts +0 -77
- package/dist/exp/src/core/view/EventQueue.d.ts +0 -99
- package/dist/exp/src/core/view/EventRegistration.d.ts +0 -154
- package/dist/exp/src/core/view/QueryParams.d.ts +0 -176
- package/dist/exp/src/core/view/View.d.ts +0 -97
- package/dist/exp/src/core/view/ViewCache.d.ts +0 -70
- package/dist/exp/src/core/view/ViewProcessor.d.ts +0 -166
- package/dist/exp/src/core/view/filter/IndexedFilter.d.ts +0 -54
- package/dist/exp/src/core/view/filter/LimitedFilter.d.ts +0 -94
- package/dist/exp/src/core/view/filter/NodeFilter.d.ts +0 -75
- package/dist/exp/src/core/view/filter/RangedFilter.d.ts +0 -109
- package/dist/exp/src/exp/Database.d.ts +0 -95
- package/dist/exp/src/realtime/BrowserPollConnection.d.ts +0 -208
- package/dist/exp/src/realtime/Connection.d.ts +0 -119
- package/dist/exp/src/realtime/Constants.d.ts +0 -26
- package/dist/exp/src/realtime/Transport.d.ts +0 -62
- package/dist/exp/src/realtime/TransportManager.d.ts +0 -55
- package/dist/exp/src/realtime/WebSocketConnection.d.ts +0 -133
- package/dist/exp/src/realtime/polling/PacketReceiver.d.ts +0 -41
- package/dist/exp/test/browser/crawler_support.test.d.ts +0 -17
- package/dist/exp/test/compound_write.test.d.ts +0 -17
- package/dist/exp/test/connection.test.d.ts +0 -17
- package/dist/exp/test/database.test.d.ts +0 -17
- package/dist/exp/test/datasnapshot.test.d.ts +0 -17
- package/dist/exp/test/exp/integration.test.d.ts +0 -17
- package/dist/exp/test/helpers/EventAccumulator.d.ts +0 -34
- package/dist/exp/test/helpers/events.d.ts +0 -37
- package/dist/exp/test/helpers/util.d.ts +0 -50
- package/dist/exp/test/info.test.d.ts +0 -17
- package/dist/exp/test/node.test.d.ts +0 -17
- package/dist/exp/test/order.test.d.ts +0 -17
- package/dist/exp/test/order_by.test.d.ts +0 -17
- package/dist/exp/test/path.test.d.ts +0 -17
- package/dist/exp/test/promise.test.d.ts +0 -17
- package/dist/exp/test/pushid.test.d.ts +0 -17
- package/dist/exp/test/query.test.d.ts +0 -17
- package/dist/exp/test/repoinfo.test.d.ts +0 -17
- package/dist/exp/test/servervalues.test.d.ts +0 -17
- package/dist/exp/test/sortedmap.test.d.ts +0 -17
- package/dist/exp/test/sparsesnapshottree.test.d.ts +0 -17
- package/dist/exp/test/transaction.test.d.ts +0 -17
- package/dist/src/exp/Database.d.ts +0 -95
- package/dist/test/exp/integration.test.d.ts +0 -17
- package/dist/test/pushid.test.d.ts +0 -17
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Fancy ID generator that creates 20-character string identifiers with the
|
|
19
|
-
* following properties:
|
|
20
|
-
*
|
|
21
|
-
* 1. They're based on timestamp so that they sort *after* any existing ids.
|
|
22
|
-
* 2. They contain 72-bits of random data after the timestamp so that IDs won't
|
|
23
|
-
* collide with other clients' IDs.
|
|
24
|
-
* 3. They sort *lexicographically* (so the timestamp is converted to characters
|
|
25
|
-
* that will sort properly).
|
|
26
|
-
* 4. They're monotonically increasing. Even if you generate more than one in
|
|
27
|
-
* the same timestamp, the latter ones will sort after the former ones. We do
|
|
28
|
-
* this by using the previous random bits but "incrementing" them by 1 (only
|
|
29
|
-
* in the case of a timestamp collision).
|
|
30
|
-
*/
|
|
31
|
-
export declare const nextPushId: (now: number) => string;
|
|
32
|
-
export declare const successor: (key: string) => string;
|
|
33
|
-
export declare const predecessor: (key: string) => string;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { EventEmitter } from './EventEmitter';
|
|
18
|
-
/**
|
|
19
|
-
* Monitors online state (as reported by window.online/offline events).
|
|
20
|
-
*
|
|
21
|
-
* The expectation is that this could have many false positives (thinks we are online
|
|
22
|
-
* when we're not), but no false negatives. So we can safely use it to determine when
|
|
23
|
-
* we definitely cannot reach the internet.
|
|
24
|
-
*
|
|
25
|
-
* @extends {EventEmitter}
|
|
26
|
-
*/
|
|
27
|
-
export declare class OnlineMonitor extends EventEmitter {
|
|
28
|
-
private online_;
|
|
29
|
-
static getInstance(): OnlineMonitor;
|
|
30
|
-
constructor();
|
|
31
|
-
/**
|
|
32
|
-
* @param {!string} eventType
|
|
33
|
-
* @return {Array.<boolean>}
|
|
34
|
-
*/
|
|
35
|
-
getInitialEvent(eventType: string): boolean[];
|
|
36
|
-
/**
|
|
37
|
-
* @return {boolean}
|
|
38
|
-
*/
|
|
39
|
-
currentlyOnline(): boolean;
|
|
40
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* An immutable object representing a parsed path. It's immutable so that you
|
|
19
|
-
* can pass them around to other functions without worrying about them changing
|
|
20
|
-
* it.
|
|
21
|
-
*/
|
|
22
|
-
export declare class Path {
|
|
23
|
-
private pieces_;
|
|
24
|
-
private pieceNum_;
|
|
25
|
-
/**
|
|
26
|
-
* Singleton to represent an empty path
|
|
27
|
-
*
|
|
28
|
-
* @const
|
|
29
|
-
*/
|
|
30
|
-
static get Empty(): Path;
|
|
31
|
-
/**
|
|
32
|
-
* @param {string|Array.<string>} pathOrString Path string to parse,
|
|
33
|
-
* or another path, or the raw tokens array
|
|
34
|
-
* @param {number=} pieceNum
|
|
35
|
-
*/
|
|
36
|
-
constructor(pathOrString: string | string[], pieceNum?: number);
|
|
37
|
-
getFront(): string | null;
|
|
38
|
-
/**
|
|
39
|
-
* @return {number} The number of segments in this path
|
|
40
|
-
*/
|
|
41
|
-
getLength(): number;
|
|
42
|
-
/**
|
|
43
|
-
* @return {!Path}
|
|
44
|
-
*/
|
|
45
|
-
popFront(): Path;
|
|
46
|
-
/**
|
|
47
|
-
* @return {?string}
|
|
48
|
-
*/
|
|
49
|
-
getBack(): string | null;
|
|
50
|
-
toString(): string;
|
|
51
|
-
toUrlEncodedString(): string;
|
|
52
|
-
/**
|
|
53
|
-
* Shallow copy of the parts of the path.
|
|
54
|
-
*
|
|
55
|
-
* @param {number=} begin
|
|
56
|
-
* @return {!Array<string>}
|
|
57
|
-
*/
|
|
58
|
-
slice(begin?: number): string[];
|
|
59
|
-
/**
|
|
60
|
-
* @return {?Path}
|
|
61
|
-
*/
|
|
62
|
-
parent(): Path | null;
|
|
63
|
-
/**
|
|
64
|
-
* @param {string|!Path} childPathObj
|
|
65
|
-
* @return {!Path}
|
|
66
|
-
*/
|
|
67
|
-
child(childPathObj: string | Path): Path;
|
|
68
|
-
/**
|
|
69
|
-
* @return {boolean} True if there are no segments in this path
|
|
70
|
-
*/
|
|
71
|
-
isEmpty(): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* @param {!Path} outerPath
|
|
74
|
-
* @param {!Path} innerPath
|
|
75
|
-
* @return {!Path} The path from outerPath to innerPath
|
|
76
|
-
*/
|
|
77
|
-
static relativePath(outerPath: Path, innerPath: Path): Path;
|
|
78
|
-
/**
|
|
79
|
-
* @param {!Path} left
|
|
80
|
-
* @param {!Path} right
|
|
81
|
-
* @return {number} -1, 0, 1 if left is less, equal, or greater than the right.
|
|
82
|
-
*/
|
|
83
|
-
static comparePaths(left: Path, right: Path): number;
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
* @param {Path} other
|
|
87
|
-
* @return {boolean} true if paths are the same.
|
|
88
|
-
*/
|
|
89
|
-
equals(other: Path): boolean;
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @param {!Path} other
|
|
93
|
-
* @return {boolean} True if this path is a parent (or the same as) other
|
|
94
|
-
*/
|
|
95
|
-
contains(other: Path): boolean;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Dynamic (mutable) path used to count path lengths.
|
|
99
|
-
*
|
|
100
|
-
* This class is used to efficiently check paths for valid
|
|
101
|
-
* length (in UTF8 bytes) and depth (used in path validation).
|
|
102
|
-
*
|
|
103
|
-
* Throws Error exception if path is ever invalid.
|
|
104
|
-
*
|
|
105
|
-
* The definition of a path always begins with '/'.
|
|
106
|
-
*/
|
|
107
|
-
export declare class ValidationPath {
|
|
108
|
-
private errorPrefix_;
|
|
109
|
-
/** @type {!Array<string>} */
|
|
110
|
-
private parts_;
|
|
111
|
-
/** @type {number} Initialize to number of '/' chars needed in path. */
|
|
112
|
-
private byteLength_;
|
|
113
|
-
/**
|
|
114
|
-
* @param {!Path} path Initial Path.
|
|
115
|
-
* @param {string} errorPrefix_ Prefix for any error messages.
|
|
116
|
-
*/
|
|
117
|
-
constructor(path: Path, errorPrefix_: string);
|
|
118
|
-
/** @const {number} Maximum key depth. */
|
|
119
|
-
static get MAX_PATH_DEPTH(): number;
|
|
120
|
-
/** @const {number} Maximum number of (UTF8) bytes in a Firebase path. */
|
|
121
|
-
static get MAX_PATH_LENGTH_BYTES(): number;
|
|
122
|
-
/** @param {string} child */
|
|
123
|
-
push(child: string): void;
|
|
124
|
-
pop(): void;
|
|
125
|
-
private checkValid_;
|
|
126
|
-
/**
|
|
127
|
-
* String for use in error messages - uses '.' notation for path.
|
|
128
|
-
*
|
|
129
|
-
* @return {string}
|
|
130
|
-
*/
|
|
131
|
-
toErrorString(): string;
|
|
132
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { Path } from './Path';
|
|
18
|
-
import { Node } from '../snap/Node';
|
|
19
|
-
import { SyncTree } from '../SyncTree';
|
|
20
|
-
import { Indexable } from './misc';
|
|
21
|
-
interface ValueProvider {
|
|
22
|
-
getImmediateChild(childName: string): ValueProvider;
|
|
23
|
-
node(): Node;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Generate placeholders for deferred values.
|
|
27
|
-
* @param {?Object} values
|
|
28
|
-
* @return {!Object}
|
|
29
|
-
*/
|
|
30
|
-
export declare const generateWithValues: (values: {
|
|
31
|
-
[k: string]: unknown;
|
|
32
|
-
}) => {
|
|
33
|
-
[k: string]: unknown;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Value to use when firing local events. When writing server values, fire
|
|
37
|
-
* local events with an approximate value, otherwise return value as-is.
|
|
38
|
-
* @param {(Object|string|number|boolean)} value
|
|
39
|
-
* @param {!Object} serverValues
|
|
40
|
-
* @return {!(string|number|boolean)}
|
|
41
|
-
*/
|
|
42
|
-
export declare const resolveDeferredLeafValue: (value: string | number | boolean | {
|
|
43
|
-
[k: string]: unknown;
|
|
44
|
-
}, existingVal: ValueProvider, serverValues: {
|
|
45
|
-
[k: string]: unknown;
|
|
46
|
-
}) => string | number | boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Recursively replace all deferred values and priorities in the tree with the
|
|
49
|
-
* specified generated replacement values.
|
|
50
|
-
* @param {!Path} path path to which write is relative
|
|
51
|
-
* @param {!Node} node new data written at path
|
|
52
|
-
* @param {!SyncTree} syncTree current data
|
|
53
|
-
* @param {!Object} serverValues
|
|
54
|
-
* @return {!SparseSnapshotTree}
|
|
55
|
-
*/
|
|
56
|
-
export declare const resolveDeferredValueTree: (path: Path, node: Node, syncTree: SyncTree, serverValues: Indexable) => Node;
|
|
57
|
-
/**
|
|
58
|
-
* Recursively replace all deferred values and priorities in the node with the
|
|
59
|
-
* specified generated replacement values. If there are no server values in the node,
|
|
60
|
-
* it'll be returned as-is.
|
|
61
|
-
* @param {!Node} node
|
|
62
|
-
* @param {!Object} serverValues
|
|
63
|
-
* @return {!Node}
|
|
64
|
-
*/
|
|
65
|
-
export declare const resolveDeferredValueSnapshot: (node: Node, existing: Node, serverValues: Indexable) => Node;
|
|
66
|
-
export {};
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* @fileoverview Implementation of an immutable SortedMap using a Left-leaning
|
|
19
|
-
* Red-Black Tree, adapted from the implementation in Mugs
|
|
20
|
-
* (http://mads379.github.com/mugs/) by Mads Hartmann Jensen
|
|
21
|
-
* (mads379@gmail.com).
|
|
22
|
-
*
|
|
23
|
-
* Original paper on Left-leaning Red-Black Trees:
|
|
24
|
-
* http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf
|
|
25
|
-
*
|
|
26
|
-
* Invariant 1: No red node has a red child
|
|
27
|
-
* Invariant 2: Every leaf path has the same number of black nodes
|
|
28
|
-
* Invariant 3: Only the left child can be red (left leaning)
|
|
29
|
-
*/
|
|
30
|
-
export declare type Comparator<K> = (key1: K, key2: K) => number;
|
|
31
|
-
/**
|
|
32
|
-
* An iterator over an LLRBNode.
|
|
33
|
-
*/
|
|
34
|
-
export declare class SortedMapIterator<K, V, T> {
|
|
35
|
-
private isReverse_;
|
|
36
|
-
private resultGenerator_;
|
|
37
|
-
/** @private
|
|
38
|
-
* @type {Array.<!LLRBNode>}
|
|
39
|
-
*/
|
|
40
|
-
private nodeStack_;
|
|
41
|
-
/**
|
|
42
|
-
* @template K, V, T
|
|
43
|
-
* @param {LLRBNode|LLRBEmptyNode} node Node to iterate.
|
|
44
|
-
* @param {?K} startKey
|
|
45
|
-
* @param {function(K, K): number} comparator
|
|
46
|
-
* @param {boolean} isReverse_ Whether or not to iterate in reverse
|
|
47
|
-
* @param {(function(K, V):T)=} resultGenerator_
|
|
48
|
-
*/
|
|
49
|
-
constructor(node: LLRBNode<K, V> | LLRBEmptyNode<K, V>, startKey: K | null, comparator: Comparator<K>, isReverse_: boolean, resultGenerator_?: ((k: K, v: V) => T) | null);
|
|
50
|
-
getNext(): T;
|
|
51
|
-
hasNext(): boolean;
|
|
52
|
-
peek(): T;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Represents a node in a Left-leaning Red-Black tree.
|
|
56
|
-
*/
|
|
57
|
-
export declare class LLRBNode<K, V> {
|
|
58
|
-
key: K;
|
|
59
|
-
value: V;
|
|
60
|
-
color: boolean;
|
|
61
|
-
left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
|
|
62
|
-
right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
|
|
63
|
-
/**
|
|
64
|
-
* @template K, V
|
|
65
|
-
* @param {!K} key Key associated with this node.
|
|
66
|
-
* @param {!V} value Value associated with this node.
|
|
67
|
-
* @param {?boolean} color Whether this node is red.
|
|
68
|
-
* @param {?(LLRBNode|LLRBEmptyNode)=} left Left child.
|
|
69
|
-
* @param {?(LLRBNode|LLRBEmptyNode)=} right Right child.
|
|
70
|
-
*/
|
|
71
|
-
constructor(key: K, value: V, color: boolean | null, left?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right?: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null);
|
|
72
|
-
static RED: boolean;
|
|
73
|
-
static BLACK: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Returns a copy of the current node, optionally replacing pieces of it.
|
|
76
|
-
*
|
|
77
|
-
* @param {?K} key New key for the node, or null.
|
|
78
|
-
* @param {?V} value New value for the node, or null.
|
|
79
|
-
* @param {?boolean} color New color for the node, or null.
|
|
80
|
-
* @param {?LLRBNode|LLRBEmptyNode} left New left child for the node, or null.
|
|
81
|
-
* @param {?LLRBNode|LLRBEmptyNode} right New right child for the node, or null.
|
|
82
|
-
* @return {!LLRBNode} The node copy.
|
|
83
|
-
*/
|
|
84
|
-
copy(key: K | null, value: V | null, color: boolean | null, left: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null): LLRBNode<K, V>;
|
|
85
|
-
/**
|
|
86
|
-
* @return {number} The total number of nodes in the tree.
|
|
87
|
-
*/
|
|
88
|
-
count(): number;
|
|
89
|
-
/**
|
|
90
|
-
* @return {boolean} True if the tree is empty.
|
|
91
|
-
*/
|
|
92
|
-
isEmpty(): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Traverses the tree in key order and calls the specified action function
|
|
95
|
-
* for each node.
|
|
96
|
-
*
|
|
97
|
-
* @param {function(!K, !V):*} action Callback function to be called for each
|
|
98
|
-
* node. If it returns true, traversal is aborted.
|
|
99
|
-
* @return {*} The first truthy value returned by action, or the last falsey
|
|
100
|
-
* value returned by action
|
|
101
|
-
*/
|
|
102
|
-
inorderTraversal(action: (k: K, v: V) => unknown): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Traverses the tree in reverse key order and calls the specified action function
|
|
105
|
-
* for each node.
|
|
106
|
-
*
|
|
107
|
-
* @param {function(!Object, !Object)} action Callback function to be called for each
|
|
108
|
-
* node. If it returns true, traversal is aborted.
|
|
109
|
-
* @return {*} True if traversal was aborted.
|
|
110
|
-
*/
|
|
111
|
-
reverseTraversal(action: (k: K, v: V) => void): boolean;
|
|
112
|
-
/**
|
|
113
|
-
* @return {!Object} The minimum node in the tree.
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
private min_;
|
|
117
|
-
/**
|
|
118
|
-
* @return {!K} The maximum key in the tree.
|
|
119
|
-
*/
|
|
120
|
-
minKey(): K;
|
|
121
|
-
/**
|
|
122
|
-
* @return {!K} The maximum key in the tree.
|
|
123
|
-
*/
|
|
124
|
-
maxKey(): K;
|
|
125
|
-
/**
|
|
126
|
-
*
|
|
127
|
-
* @param {!Object} key Key to insert.
|
|
128
|
-
* @param {!Object} value Value to insert.
|
|
129
|
-
* @param {Comparator} comparator Comparator.
|
|
130
|
-
* @return {!LLRBNode} New tree, with the key/value added.
|
|
131
|
-
*/
|
|
132
|
-
insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
|
|
133
|
-
/**
|
|
134
|
-
* @private
|
|
135
|
-
* @return {!LLRBNode|LLRBEmptyNode} New tree, with the minimum key removed.
|
|
136
|
-
*/
|
|
137
|
-
private removeMin_;
|
|
138
|
-
/**
|
|
139
|
-
* @param {!Object} key The key of the item to remove.
|
|
140
|
-
* @param {Comparator} comparator Comparator.
|
|
141
|
-
* @return {!LLRBNode|LLRBEmptyNode} New tree, with the specified item removed.
|
|
142
|
-
*/
|
|
143
|
-
remove(key: K, comparator: Comparator<K>): LLRBNode<K, V> | LLRBEmptyNode<K, V>;
|
|
144
|
-
/**
|
|
145
|
-
* @private
|
|
146
|
-
* @return {boolean} Whether this is a RED node.
|
|
147
|
-
*/
|
|
148
|
-
isRed_(): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* @private
|
|
151
|
-
* @return {!LLRBNode} New tree after performing any needed rotations.
|
|
152
|
-
*/
|
|
153
|
-
private fixUp_;
|
|
154
|
-
/**
|
|
155
|
-
* @private
|
|
156
|
-
* @return {!LLRBNode} New tree, after moveRedLeft.
|
|
157
|
-
*/
|
|
158
|
-
private moveRedLeft_;
|
|
159
|
-
/**
|
|
160
|
-
* @private
|
|
161
|
-
* @return {!LLRBNode} New tree, after moveRedRight.
|
|
162
|
-
*/
|
|
163
|
-
private moveRedRight_;
|
|
164
|
-
/**
|
|
165
|
-
* @private
|
|
166
|
-
* @return {!LLRBNode} New tree, after rotateLeft.
|
|
167
|
-
*/
|
|
168
|
-
private rotateLeft_;
|
|
169
|
-
/**
|
|
170
|
-
* @private
|
|
171
|
-
* @return {!LLRBNode} New tree, after rotateRight.
|
|
172
|
-
*/
|
|
173
|
-
private rotateRight_;
|
|
174
|
-
/**
|
|
175
|
-
* @private
|
|
176
|
-
* @return {!LLRBNode} New tree, after colorFlip.
|
|
177
|
-
*/
|
|
178
|
-
private colorFlip_;
|
|
179
|
-
/**
|
|
180
|
-
* For testing.
|
|
181
|
-
*
|
|
182
|
-
* @private
|
|
183
|
-
* @return {boolean} True if all is well.
|
|
184
|
-
*/
|
|
185
|
-
private checkMaxDepth_;
|
|
186
|
-
/**
|
|
187
|
-
* @private
|
|
188
|
-
* @return {number} Not sure what this returns exactly. :-).
|
|
189
|
-
*/
|
|
190
|
-
check_(): number;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Represents an empty node (a leaf node in the Red-Black Tree).
|
|
194
|
-
*/
|
|
195
|
-
export declare class LLRBEmptyNode<K, V> {
|
|
196
|
-
key: K;
|
|
197
|
-
value: V;
|
|
198
|
-
left: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
|
|
199
|
-
right: LLRBNode<K, V> | LLRBEmptyNode<K, V>;
|
|
200
|
-
color: boolean;
|
|
201
|
-
/**
|
|
202
|
-
* Returns a copy of the current node.
|
|
203
|
-
*
|
|
204
|
-
* @return {!LLRBEmptyNode} The node copy.
|
|
205
|
-
*/
|
|
206
|
-
copy(key: K | null, value: V | null, color: boolean | null, left: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null, right: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null): LLRBEmptyNode<K, V>;
|
|
207
|
-
/**
|
|
208
|
-
* Returns a copy of the tree, with the specified key/value added.
|
|
209
|
-
*
|
|
210
|
-
* @param {!K} key Key to be added.
|
|
211
|
-
* @param {!V} value Value to be added.
|
|
212
|
-
* @param {Comparator} comparator Comparator.
|
|
213
|
-
* @return {!LLRBNode} New tree, with item added.
|
|
214
|
-
*/
|
|
215
|
-
insert(key: K, value: V, comparator: Comparator<K>): LLRBNode<K, V>;
|
|
216
|
-
/**
|
|
217
|
-
* Returns a copy of the tree, with the specified key removed.
|
|
218
|
-
*
|
|
219
|
-
* @param {!K} key The key to remove.
|
|
220
|
-
* @param {Comparator} comparator Comparator.
|
|
221
|
-
* @return {!LLRBEmptyNode} New tree, with item removed.
|
|
222
|
-
*/
|
|
223
|
-
remove(key: K, comparator: Comparator<K>): LLRBEmptyNode<K, V>;
|
|
224
|
-
/**
|
|
225
|
-
* @return {number} The total number of nodes in the tree.
|
|
226
|
-
*/
|
|
227
|
-
count(): number;
|
|
228
|
-
/**
|
|
229
|
-
* @return {boolean} True if the tree is empty.
|
|
230
|
-
*/
|
|
231
|
-
isEmpty(): boolean;
|
|
232
|
-
/**
|
|
233
|
-
* Traverses the tree in key order and calls the specified action function
|
|
234
|
-
* for each node.
|
|
235
|
-
*
|
|
236
|
-
* @param {function(!K, !V):*} action Callback function to be called for each
|
|
237
|
-
* node. If it returns true, traversal is aborted.
|
|
238
|
-
* @return {boolean} True if traversal was aborted.
|
|
239
|
-
*/
|
|
240
|
-
inorderTraversal(action: (k: K, v: V) => unknown): boolean;
|
|
241
|
-
/**
|
|
242
|
-
* Traverses the tree in reverse key order and calls the specified action function
|
|
243
|
-
* for each node.
|
|
244
|
-
*
|
|
245
|
-
* @param {function(!K, !V)} action Callback function to be called for each
|
|
246
|
-
* node. If it returns true, traversal is aborted.
|
|
247
|
-
* @return {boolean} True if traversal was aborted.
|
|
248
|
-
*/
|
|
249
|
-
reverseTraversal(action: (k: K, v: V) => void): boolean;
|
|
250
|
-
/**
|
|
251
|
-
* @return {null}
|
|
252
|
-
*/
|
|
253
|
-
minKey(): null;
|
|
254
|
-
/**
|
|
255
|
-
* @return {null}
|
|
256
|
-
*/
|
|
257
|
-
maxKey(): null;
|
|
258
|
-
/**
|
|
259
|
-
* @private
|
|
260
|
-
* @return {number} Not sure what this returns exactly. :-).
|
|
261
|
-
*/
|
|
262
|
-
check_(): number;
|
|
263
|
-
/**
|
|
264
|
-
* @private
|
|
265
|
-
* @return {boolean} Whether this node is red.
|
|
266
|
-
*/
|
|
267
|
-
isRed_(): boolean;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* An immutable sorted map implementation, based on a Left-leaning Red-Black
|
|
271
|
-
* tree.
|
|
272
|
-
*/
|
|
273
|
-
export declare class SortedMap<K, V> {
|
|
274
|
-
private comparator_;
|
|
275
|
-
private root_;
|
|
276
|
-
/**
|
|
277
|
-
* Always use the same empty node, to reduce memory.
|
|
278
|
-
* @const
|
|
279
|
-
*/
|
|
280
|
-
static EMPTY_NODE: LLRBEmptyNode<unknown, unknown>;
|
|
281
|
-
/**
|
|
282
|
-
* @template K, V
|
|
283
|
-
* @param {function(K, K):number} comparator_ Key comparator.
|
|
284
|
-
* @param {LLRBNode=} root_ (Optional) Root node for the map.
|
|
285
|
-
*/
|
|
286
|
-
constructor(comparator_: Comparator<K>, root_?: LLRBNode<K, V> | LLRBEmptyNode<K, V>);
|
|
287
|
-
/**
|
|
288
|
-
* Returns a copy of the map, with the specified key/value added or replaced.
|
|
289
|
-
* (TODO: We should perhaps rename this method to 'put')
|
|
290
|
-
*
|
|
291
|
-
* @param {!K} key Key to be added.
|
|
292
|
-
* @param {!V} value Value to be added.
|
|
293
|
-
* @return {!SortedMap.<K, V>} New map, with item added.
|
|
294
|
-
*/
|
|
295
|
-
insert(key: K, value: V): SortedMap<K, V>;
|
|
296
|
-
/**
|
|
297
|
-
* Returns a copy of the map, with the specified key removed.
|
|
298
|
-
*
|
|
299
|
-
* @param {!K} key The key to remove.
|
|
300
|
-
* @return {!SortedMap.<K, V>} New map, with item removed.
|
|
301
|
-
*/
|
|
302
|
-
remove(key: K): SortedMap<K, V>;
|
|
303
|
-
/**
|
|
304
|
-
* Returns the value of the node with the given key, or null.
|
|
305
|
-
*
|
|
306
|
-
* @param {!K} key The key to look up.
|
|
307
|
-
* @return {?V} The value of the node with the given key, or null if the
|
|
308
|
-
* key doesn't exist.
|
|
309
|
-
*/
|
|
310
|
-
get(key: K): V | null;
|
|
311
|
-
/**
|
|
312
|
-
* Returns the key of the item *before* the specified key, or null if key is the first item.
|
|
313
|
-
* @param {K} key The key to find the predecessor of
|
|
314
|
-
* @return {?K} The predecessor key.
|
|
315
|
-
*/
|
|
316
|
-
getPredecessorKey(key: K): K | null;
|
|
317
|
-
/**
|
|
318
|
-
* @return {boolean} True if the map is empty.
|
|
319
|
-
*/
|
|
320
|
-
isEmpty(): boolean;
|
|
321
|
-
/**
|
|
322
|
-
* @return {number} The total number of nodes in the map.
|
|
323
|
-
*/
|
|
324
|
-
count(): number;
|
|
325
|
-
/**
|
|
326
|
-
* @return {?K} The minimum key in the map.
|
|
327
|
-
*/
|
|
328
|
-
minKey(): K | null;
|
|
329
|
-
/**
|
|
330
|
-
* @return {?K} The maximum key in the map.
|
|
331
|
-
*/
|
|
332
|
-
maxKey(): K | null;
|
|
333
|
-
/**
|
|
334
|
-
* Traverses the map in key order and calls the specified action function
|
|
335
|
-
* for each key/value pair.
|
|
336
|
-
*
|
|
337
|
-
* @param {function(!K, !V):*} action Callback function to be called
|
|
338
|
-
* for each key/value pair. If action returns true, traversal is aborted.
|
|
339
|
-
* @return {*} The first truthy value returned by action, or the last falsey
|
|
340
|
-
* value returned by action
|
|
341
|
-
*/
|
|
342
|
-
inorderTraversal(action: (k: K, v: V) => unknown): boolean;
|
|
343
|
-
/**
|
|
344
|
-
* Traverses the map in reverse key order and calls the specified action function
|
|
345
|
-
* for each key/value pair.
|
|
346
|
-
*
|
|
347
|
-
* @param {function(!Object, !Object)} action Callback function to be called
|
|
348
|
-
* for each key/value pair. If action returns true, traversal is aborted.
|
|
349
|
-
* @return {*} True if the traversal was aborted.
|
|
350
|
-
*/
|
|
351
|
-
reverseTraversal(action: (k: K, v: V) => void): boolean;
|
|
352
|
-
/**
|
|
353
|
-
* Returns an iterator over the SortedMap.
|
|
354
|
-
* @template T
|
|
355
|
-
* @param {(function(K, V):T)=} resultGenerator
|
|
356
|
-
* @return {SortedMapIterator.<K, V, T>} The iterator.
|
|
357
|
-
*/
|
|
358
|
-
getIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
|
|
359
|
-
getIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
|
|
360
|
-
getReverseIteratorFrom<T>(key: K, resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
|
|
361
|
-
getReverseIterator<T>(resultGenerator?: (k: K, v: V) => T): SortedMapIterator<K, V, T>;
|
|
362
|
-
}
|