/** * @license * Copyright 2021, JsData. All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * 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. * ========================================================================== */ /** * A variant of a binary max-heap with a size limit. * If more elements than the size limit are added, * only the smallest encountered elements are retained. * This data structure is used in k-nearest-neighbor * searches to retain the k nearest results during * tree traversal. */ export declare class CappedMaxHeap { _keys: Float32Array; _vals: Int32Array; /** * Index of the currently first entry. * The entries are added from right to * left until `_pos = 0`, at which point * adding further elements results in * replacement. */ _pos: number; /** * Creates a new heap using the given key * and value array as underlying data storage. * The heap will modify these arrays directly. * * @param keys Key array to be used by the heap. * @param vals Value array to be used by the heap. */ constructor(keys: Float32Array, vals: Int32Array); /** * Returns the currently larges key without removing it. */ get maxKey(): number; /** * Adds an entry to this heap. If, after adding, * the size limit is exceeded, the largest entry * is removed as well, even the entry that was * just added if it has the largest key. * * @param key Key of the added entry. * @param val Value of the added entry. */ add(key: number, val: number): void; /** * Sorts the entries of this heap by their keys in ascending * order. This method destroys the heap property and should * only be called after all elements have been added. */ sort(): void; }