/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { type ISegmentInternal } from "./mergeTreeNodes.js";
import { TrackingGroupCollection } from "./mergeTreeTracking.js";
import { ReferenceType } from "./ops.js";
import { PropertySet } from "./properties.js";
import { ReferencePosition } from "./referencePositions.js";
/**
 * Dictates the preferential direction for a {@link ReferencePosition} to slide
 * in a merge-tree
 * @legacy
 * @alpha
 */
export declare const SlidingPreference: {
    /**
     * Prefer sliding towards the start of the tree
     */
    readonly BACKWARD: 0;
    /**
     * Prefer sliding towards the end of the tree
     */
    readonly FORWARD: 1;
};
/**
 * Dictates the preferential direction for a {@link ReferencePosition} to slide
 * in a merge-tree
 * @legacy
 * @alpha
 */
export type SlidingPreference = (typeof SlidingPreference)[keyof typeof SlidingPreference];
/**
 * @sealed
 * @legacy
 * @alpha
 */
export interface LocalReferencePosition extends ReferencePosition {
    callbacks?: Partial<Record<"beforeSlide" | "afterSlide", (ref: LocalReferencePosition) => void>>;
    readonly trackingCollection: TrackingGroupCollection;
    /**
     * Whether or not this reference position can slide onto one of the two
     * special segments representing the position before or after the tree
     */
    readonly canSlideToEndpoint?: boolean;
    /**
     * @param newProps - Properties to add to this reference.
     * @remarks Note that merge-tree does not broadcast changes to other clients. It is up to the consumer
     * to ensure broadcast happens if that is desired.
     */
    addProperties(newProps: PropertySet): void;
}
/**
 * Creates a new detached local reference.
 * @internal
 */
export declare function createDetachedLocalReferencePosition(slidingPreference: SlidingPreference | undefined, refType?: ReferenceType): LocalReferencePosition;
/**
 * Determines if the given function is true for any position within the collection.
 */
export declare function anyLocalReferencePosition(collection: LocalReferenceCollection, func: (pos: LocalReferencePosition) => boolean): boolean;
/**
 * Finds the local reference positions that satisfy the given predicate.
 */
export declare function filterLocalReferencePositions(collection: LocalReferenceCollection, predicate: (pos: LocalReferencePosition) => boolean): Generator<LocalReferencePosition>;
export declare function setValidateRefCount(cb?: (collection?: LocalReferenceCollection) => void): void;
/**
 * Represents a collection of {@link LocalReferencePosition}s associated with
 * one segment in a merge-tree.
 * Represents a collection of {@link LocalReferencePosition}s associated with one segment in a merge-tree.
 * @sealed
 *
 * @internal
 */
export declare class LocalReferenceCollection {
    /**
     * The segment this `LocalReferenceCollection` is associated with.
     */
    private readonly segment;
    static append(seg1: ISegmentInternal, seg2: ISegmentInternal): void;
    static setOrGet(segment: ISegmentInternal): LocalReferenceCollection;
    private readonly refsByOffset;
    private refCount;
    private constructor();
    /**
     * Returns an iterator over this LocalReferenceCollection.
     * @remarks This method should only be called by mergeTree.
     */
    [Symbol.iterator](): {
        next(): IteratorResult<LocalReferencePosition>;
        [Symbol.iterator](): IterableIterator<LocalReferencePosition>;
    };
    /**
     * Determines if the collection has no references in it.
     * @remarks This method should only be called by mergeTree.
     */
    get empty(): boolean;
    /**
     * Creates a new local reference.
     * @remarks This method should only be called by mergeTree.
     */
    createLocalRef(offset: number, refType: ReferenceType, properties: PropertySet | undefined, slidingPreference?: SlidingPreference, canSlideToEndpoint?: boolean): LocalReferencePosition;
    /**
     * Adds a local reference to the collection.
     * @remarks This method should only be called by mergeTree.
     */
    addLocalRef(lref: LocalReferencePosition, offset: number): void;
    /**
     * Removes a local reference from the collection.
     * @remarks This method should only be called by mergeTree.
     */
    removeLocalRef(lref: LocalReferencePosition): LocalReferencePosition | undefined;
    /**
     *
     * Called by 'append()' implementations to append local refs from the given 'other' segment to the
     * end of 'this' segment.
     *
     * Note: This method should be invoked after the caller has ensured that segments can be merged,
     * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs
     * will be incorrect.
     *
     * @remarks This method should only be called by mergeTree.
     */
    append(other: LocalReferenceCollection): void;
    /**
     * Returns true of the local reference is in the collection, otherwise false.
     *
     * @remarks This method should only be called by mergeTree.
     */
    has(lref: ReferencePosition): boolean;
    /**
     * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).
     * Local references in the former half of this split will remain associated with the segment used on construction.
     * Local references in the latter half of this split will be transferred to `splitSeg`,
     * and its `localRefs` field will be set.
     * @param offset - Offset into the original segment at which the collection should be split
     * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)
     * before splitting.
     *
     * @remarks This method should only be called by mergeTree.
     */
    split(offset: number, splitSeg: ISegmentInternal): void;
    /**
     * Insert a reference before tombstoned references.
     * @remarks This method should only be called by mergeTree.
     */
    addBeforeTombstones(...refs: Iterable<LocalReferencePosition>[]): void;
    /**
     * Insert a reference after tombstoned references.
     * @remarks This method should only be called by mergeTree.
     */
    addAfterTombstones(...refs: Iterable<LocalReferencePosition>[]): void;
    /**
     * Determines if a reference is after tombstoned references.
     * @remarks This method should only be called by mergeTree.
     */
    isAfterTombstone(lref: LocalReferencePosition): boolean;
    /**
     * Walks all of the references in a collection.
     * @remarks This method should only be called by mergeTree.
     */
    walkReferences(visitor: (lref: LocalReferencePosition) => boolean | void | undefined, start?: LocalReferencePosition, forward?: boolean): boolean;
}
//# sourceMappingURL=localReference.d.ts.map