UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

81 lines (80 loc) 3.24 kB
/** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { SortedMapIterator } from './sorted_map'; /** * SortedSet is an immutable (copy-on-write) collection that holds elements * in order specified by the provided comparator. * * NOTE: if provided comparator returns 0 for two elements, we consider them to * be equal! */ export declare class SortedSet<T> { private comparator; private data; constructor(comparator: (left: T, right: T) => number); has(elem: T): boolean; first(): T | null; last(): T | null; get size(): number; indexOf(elem: T): number; /** Iterates elements in order defined by "comparator" */ forEach(cb: (elem: T) => void): void; /** Iterates over `elem`s such that: range[0] &lt;= elem &lt; range[1]. */ forEachInRange(range: [T, T], cb: (elem: T) => void): void; /** * Iterates over `elem`s such that: start &lt;= elem until false is returned. */ forEachWhile(cb: (elem: T) => boolean, start?: T): void; /** Finds the least element greater than or equal to `elem`. */ firstAfterOrEqual(elem: T): T | null; getIterator(): SortedSetIterator<T>; getIteratorFrom(key: T): SortedSetIterator<T>; /** Inserts or updates an element */ add(elem: T): SortedSet<T>; /** Deletes an element */ delete(elem: T): SortedSet<T>; isEmpty(): boolean; unionWith(other: SortedSet<T>): SortedSet<T>; isEqual(other: SortedSet<T>): boolean; toArray(): T[]; toString(): string; private copy; } export declare class SortedSetIterator<T> { private iter; constructor(iter: SortedMapIterator<T, boolean>); getNext(): T; hasNext(): boolean; } /** * Compares two sorted sets for equality using their natural ordering. The * method computes the intersection and invokes `onAdd` for every element that * is in `after` but not `before`. `onRemove` is invoked for every element in * `before` but missing from `after`. * * The method creates a copy of both `before` and `after` and runs in O(n log * n), where n is the size of the two lists. * * @param before - The elements that exist in the original set. * @param after - The elements to diff against the original set. * @param comparator - The comparator for the elements in before and after. * @param onAdd - A function to invoke for every element that is part of ` * after` but not `before`. * @param onRemove - A function to invoke for every element that is part of * `before` but not `after`. */ export declare function diffSortedSets<T>(before: SortedSet<T>, after: SortedSet<T>, comparator: (l: T, r: T) => number, onAdd: (entry: T) => void, onRemove: (entry: T) => void): void;