//================================================================ /** * @packageDocumentation * @module std.internal */ //================================================================ import { VectorContainer } from "../linear/VectorContainer"; import { ArrayIteratorBase } from "../../iterator/ArrayIteratorBase"; import { ArrayReverseIteratorBase } from "../../iterator/ArrayReverseIteratorBase"; import { ITreeMap } from "../../../base/container/ITreeMap"; import { IPair } from "../../../utility/IPair"; import { Entry } from "../../../utility/Entry"; /** * Vector storing map elements. * * @template Key Key type * @template T Mapped type * @template Unique Whether duplicated key is blocked or not * @template Source Source type * * @author Jeongho Nam - https://github.com/samchon */ export class MapElementVector< Key, T, Unique extends boolean, Source extends ITreeMap< Key, T, Unique, Source, MapElementVector.Iterator, MapElementVector.ReverseIterator >, > extends VectorContainer< Entry, Source, MapElementVector, MapElementVector.Iterator, MapElementVector.ReverseIterator > { private associative_: Source; /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ public constructor(associative: Source) { super(); this.data_ = []; this.associative_ = associative; } public nth( index: number, ): MapElementVector.Iterator { return new MapElementVector.Iterator(this, index); } /** * @internal */ public static _Swap_associative< Key, T, Unique extends boolean, Source extends ITreeMap< Key, T, Unique, Source, MapElementVector.Iterator, MapElementVector.ReverseIterator >, >( x: MapElementVector, y: MapElementVector, ): void { [x.associative_, y.associative_] = [y.associative_, x.associative_]; } /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ public source(): Source { return this.associative_; } } /** * */ export namespace MapElementVector { /** * Iterator of map container storing elements in a vector. * * @template Key Key type * @template T Mapped type * @template Unique Whether duplicated key is blocked or not * @template Source Source container type * * @author Jeongho Nam - https://github.com/samchon */ export class Iterator< Key, T, Unique extends boolean, Source extends ITreeMap< Key, T, Unique, Source, Iterator, ReverseIterator >, > extends ArrayIteratorBase< Entry, Source, MapElementVector, Iterator, ReverseIterator, IPair > implements ITreeMap.Iterator< Key, T, Unique, Source, Iterator, ReverseIterator > { /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ /** * @inheritDoc */ public source(): Source { return this._Get_array().source(); } /** * @inheritDoc */ public reverse(): ReverseIterator { return new ReverseIterator(this); } /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ /** * @inheritDoc */ public get first(): Key { return this.value.first; } /** * @inheritDoc */ public get second(): T { return this.value.second; } /** * @inheritDoc */ public set second(val: T) { this.value.second = val; } } /** * Reverse iterator of map container storing elements in a vector. * * @template Key Key type * @template T Mapped type * @template Unique Whether duplicated key is blocked or not * @template Source Source container type * * @author Jeongho Nam - https://github.com/samchon */ export class ReverseIterator< Key, T, Unique extends boolean, Source extends ITreeMap< Key, T, Unique, Source, Iterator, ReverseIterator >, > extends ArrayReverseIteratorBase< Entry, Source, MapElementVector, Iterator, ReverseIterator, IPair > implements ITreeMap.ReverseIterator< Key, T, Unique, Source, Iterator, ReverseIterator > { /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ protected _Create_neighbor( base: Iterator, ): ReverseIterator { return new ReverseIterator(base); } /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ /** * @inheritDoc */ public get first(): Key { return this.value.first; } /** * @inheritDoc */ public get second(): T { return this.value.second; } /** * @inheritDoc */ public set second(val: T) { this.value.second = val; } } }